{ "info": { "author": "Justin Mohr", "author_email": "jmohr@bytepulse.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Topic :: Software Development" ], "description": "=============================================================================\nProject: Compago\nCopyright: \u00a92011,2012 Justin Mohr. All Rights Reserved.\n=============================================================================\n\nWrite polished command line applications in a fraction of the time.\nGuaranteed, or double your money back!\n\nCompago is a framework for simple command-line parsing in Python. Compago\nprovides a simple framework and set of decorators to allow you to quickly\nand easily define a set of commands within a script. For those familiar with\nRuby's Thor, Compago fills a similar niche.\n\nThis project was inspired by the excellent Flask-Script extension for Flask,\nbut has been entirely rewritten to remove all Flask dependencies.\n\n(see: http://packages.python.org/Flask-Script/)\n\n-----------------------------------------------------------------------------\nQuick Start\n-----------------------------------------------------------------------------\n\nFirst, install compago with pip, or alternately fetch the sources from Github or PyPI.\n\n $ pip install compago\n\nThen, create a python file named \"mycommand.py\" containing this:\n\n import compago\n\n app = compago.Application()\n\n @app.command\n def say_hello(to=\"world\"):\n print(\"Hello there, %s\" % to)\n\n if __name__ == '__main__': app.run()\n\nSave the file, and run it thusly:\n\n $ python mycommand.py\n\nFor some more in-depth examples, see the /examples folder in the sources.\n\n-----------------------------------------------------------------------------\nBackground\n-----------------------------------------------------------------------------\n\nWhy Compago?\n\nWe've all needed to whip up a quick command line script at some point. How\noften have you wanted to wrap a quick five lines of Python in a script for\nreuse? Perhaps your little script requires a few arguments to be passed in.\nIn the past, you've had a few options:\n\n - Quick and dirty: just hard code some global variables at the top of\n your script.\n - Better, but still messy: just directly pull in sys.argv\n - Best, but difficult: use optparse or argparse\n\nIf you'll be using the script often, option 1 can become a pain very quickly.\nYou have to open the file in a text editor every time you need to change the\nvalues. And if you ever need to let someone else use the script, option 1 can\nbe a no-go.\n\nOption 2 is pretty easy, but just directly using sys.argv can get out\nof control very quickly if you need to pull in more than one command line\nargument. And similar to using global variables, expecting other users to\nalways play nice with the command line args is just asking for trouble.\n\nUsing argparse and/or optparse is the most prudent option, but if your script\nis just a few lines of code, setting up all of that boilerplate can add a ton\nof overhead to your quick script.\n\nWith Compago, you have another option. With the use of some simple\ndecorators, Compago can introspect a function, and set up command line\narguments and defaults automagically.\n\nFor example, instead of importing optparse, and manually setting up each\noption in an OptionParser, and then taking the output of that and feeding\nit into your function, you can just define your function thusly:\n\nmyapp.py:\n\n @app.command\n def check_host(hostname, username='admin', password='testing123'):\n '''Do some stuff.'''\n print \"Let's do some junk on %s as user %s.\" % (\n hostname, username)\n\nNow, the function's arguments (hostname, username, password) will be\navailable as command line arguments to your script:\n\n $ ./myapp.py check_host localhost --username=root --password=testing234\n Let's do some junk on localhost as user root.\n $ ./myapp.py check_host host1.example.com\n Let's do some junk on host1.example.com as user admin.\n\nThat's it! No other nasty boilerplate required.\n\n-----------------------------------------------------------------------------\nInstalling Compago\n-----------------------------------------------------------------------------\n\nUse pip or easy_install:\n\n pip install compago\n easy_install compago\n\nBoom. Done.\n\nOr alternately, fetch the source from github:\n\n git clone https://github.com/jmohr/compago.git\n\n-----------------------------------------------------------------------------\nUsing Compago\n-----------------------------------------------------------------------------\n\nStarting a Compago script is as easy as importing the compago module, and\ncreating a compago.Application object.\n\n import compago\n\n app = compago.Application()\n\nAn Application has one primary attribute, a name. By default, this will just\nbe the name of the script (sys.argv[0]), but you can override this if needed.\nThe name will be shown in the help.\n\n-----------------------------------------------------------------------------\nCommands and Options\n-----------------------------------------------------------------------------\n\nAfter you create the application, you need to define some commands. A command\nwill be accessible for the user to call on the command line. For example, in\nthe Quick Start example above, the \"check_host\" function is a command. You\ncan define as many commands as you want in your script.\n\nThe @app.command decorator is pretty straight forward in its usage. Simply\ndecorate a function (with or without arguments), and the function will then\nbe available as a \"command\" on the command line.\n\nFunction arguments without a default defined will be \"positional\" or\n\"required\" arguments on the command line. For example, in the check_host\nexample above, the \"hostname\" argument is required on the command line.\n\nIf you provide a default for your function argument, it will be an option\non the command line. For example:\n\n @myapp.command\n def mycommand(say=\"Hello\", name=\"John Doe\"):\n print \"%s, %s.\" % (say, name)\n\nIn that example, the arguments \"say\" and \"name\" will be available as options\non the command line:\n\n python myapp.py --say=\"What up\" --name=\"Justin Beiber\"\n or\n python myapp.py -s \"Goodbye\" -n \"Dude\"\n\nIf the options are not specified, the defaults will be used. One special\ntype of option exists, and that is a boolean option:\n\n @myapp.command\n def mycommand(debug=False):\n if debug:\n print \"Lots of great debugging info...\"\n else:\n print \"Terse. Very terse.\"\n\nIn this example, the \"debug\" option is a switch on the command line:\n\n python myapp.py --debug\n\nIf provided, debug will be set to True. No need to provide a value.\n\nYou can mix up the argument types, as well:\n\n @myapp.command\n def deploy(hostname, username=\"admin\", verbose=True):\n result = ssh_to(hostname, username=username)\n if verbose: print result\n\nIt works as you'd expect.\n\nAnother decorator is available if you need more control over the options.\nYou can define one or more @option decorators on your function, and pass\nin the same arguments that you would pass directly to argparse.ArgumentParser\nto define an option. See it in action:\n\n @myapp.option('-x', '--execute', dest='command')\n @myapp.option('-U', '--user', dest='username')\n def run(command, username):\n with exec_user(username):\n call(command)\n\nThis also works about as you'd expect. One thing to note, if you decorate\nyour function with one or more @option decorators, there is no need to also\ndecorate it with @command. This will be done automatically.\n\nFinally, adding help strings to your commands is super easy. Just put a\ndocstring in the function, and that string will be shown when the user\nruns --help or -h on the command line. For example:\n\n @myapp.command\n def help_included():\n '''This command has some help.'''\n pass\n\nWhen the user runs \"python myapp.py --help\", it will show the docstring next\nto help_included. Try it!\n\n-----------------------------------------------------------------------------\nPlugins\n-----------------------------------------------------------------------------\n\nCompago provides a simple plugin framework, which allows you to write your\nown plugins to be used in your scripts. Two default plugins are provided,\nand are turned on by default if you have the compago_plugins module\ninstalled.\n\nThe default plugins are LoggingPlugin and ConfigPlugin. LoggingPlugin\nprovides access to Python's logging infrastructure from within your commands.\nFor example:\n\n @myapp.command\n def test_command(name):\n myapp.logger.info('Hello, {0}!'.format(name))\n\nThis command will log an INFO message to myapp.py.log (or whatever your\nscript is called). By default, logging will not occur unless you call your\nscript with the --log option:\n\n $ python myapp.py --log test_command Justin\n\nYou can also specify --logfile, which will override the default location\nof the log file.\n\n $ python myapp.py --log --logfile /var/log/myapp.log test_command Justin\n\nThe second default plugin is the ConfigPlugin. This allows you to read\nconfig vars from a YAML formatted config file (default location:\n./myapp.py.conf). This location can be overridden by specifying the\n--configfile option on the command line.\n\nAny config variables defined in the config file are available within your\ncommands as myapp.config['YOUR_KEY']. For example, say you have a config file\nnamed /etc/myapp.conf:\n\n YOUR_NAME: Justin\n YOUR_EMAIL: justin@example.org\n YOUR_BACON_LEVELS:\n -low\n -medium\n -high\n\nAnd you call your script thusly:\n\n $ python myapp.py --configfile /etc/myapp.conf\n\nThen, within your commands, you can fetch these config variables:\n\n @myapp.command\n def test_command():\n print myapp.config['YOUR_NAME']\n # ... etc ...\n\nYou can disable plugins by overriding Application.default_plugins before\ninstantiating your Application:\n\n from compago import Application\n Application.default_plugins = []\n\n myapp = Application()\n\n # ... etc ...\n\n### Writing your own plugins\n\nYou can write your own plugins easily. A plugin is a class that inherits\nfrom compago.plugin.Plugin. It should override one or more of the hook\nmethods:\n\n after_application_init(application) - called just after the application is\n initialized\n before_command_run(application, command) - called before a command is run\n after_command_run(application, command) - called just after a command is run\n option_added(application, option) - called after an option is defined\n command_added(application, command) - called after a command is defined\n\nFor example, let's say we want a simple plugin that prints out the current\ntime before and after each command is run. Create a file time_plugin.py:\n\n from compago.plugin import Plugin\n from datetime import datetime\n\n class TimePlugin(Plugin):\n\n def before_command_run(self, application):\n print datetime.now()\n\n def after_command_run(self, application):\n print datetime.now()\n\nThen, to use the plugin in your compago application:\n\n from compago import Application\n from time_plugin import TimePlugin\n\n myapp = Application()\n myapp.add_plugin(TimePlugin())\n\n @myapp.command\n def testing123():\n pass\n\n if __name__ == '__main__':\n myapp.run()\n\nSimple as that!\n\n-----------------------------------------------------------------------------\nFAQ\n-----------------------------------------------------------------------------\n\nQ: Why did you write Compago?\n\nA: I really liked the way Thor and Flask-Script worked, and I wanted a\nsimilar tool for my plain old Python scripts. And I had way to much time\non my hands.\n\nQ: What does Compago mean?\n\nA: According to Google Translate -- which is *never* wrong -- compago is\nLatin for \"joint\" or \"connection\".\n\n-----------------------------------------------------------------------------\nTODO\n-----------------------------------------------------------------------------\n\n * Create more helper functions for fun stuff.\n\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/jmohr/compago", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "compago", "package_url": "https://pypi.org/project/compago/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/compago/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/jmohr/compago" }, "release_url": "https://pypi.org/project/compago/1.4/", "requires_dist": null, "requires_python": null, "summary": "A framework for simple command-line option parsing.", "version": "1.4" }, "last_serial": 788333, "releases": { "1.1": [ { "comment_text": "", "digests": { "md5": "28705510344f3901c68d86cec0a5eb69", "sha256": "ce57a2c79ffe3f0d37f94c21a5e5b8295017ab2a5168323df9f338a2a0d989d8" }, "downloads": -1, "filename": "compago-1.1.tar.gz", "has_sig": false, "md5_digest": "28705510344f3901c68d86cec0a5eb69", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6756, "upload_time": "2011-03-09T16:47:24", "url": "https://files.pythonhosted.org/packages/63/8e/ba622ebb2aabdfeb6f5ad898d399f06e38d3ed99ebe15646af2866a805cc/compago-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "648e3f6897be91e7db62d14715d5cd20", "sha256": "c4356177248f945de5e861245a3e497e072059b49c665e133f3682d82427f332" }, "downloads": -1, "filename": "compago-1.2.tar.gz", "has_sig": false, "md5_digest": "648e3f6897be91e7db62d14715d5cd20", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8318, "upload_time": "2011-08-03T19:26:17", "url": "https://files.pythonhosted.org/packages/1f/70/2c5fa8f8f36718e9013481851daa5120fb0bc64515daf2d6403c3de94b96/compago-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "fab75cd84926f1189a548d83111afddf", "sha256": "9d955279328c5322b2a5b91ba1ef3462c5c9c1fdace24d977265bcce23ebe771" }, "downloads": -1, "filename": "compago-1.3.tar.gz", "has_sig": false, "md5_digest": "fab75cd84926f1189a548d83111afddf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10887, "upload_time": "2012-08-14T20:51:49", "url": "https://files.pythonhosted.org/packages/fe/69/b9202ee5dfc1bdddafc8be5bf905ac747ad409ee28e3c26a2412bba8412e/compago-1.3.tar.gz" } ], "1.4": [ { "comment_text": "", "digests": { "md5": "962b308a2c070d6b87ad94c70029c1c0", "sha256": "21ad5716efc60b49e73964be8afd1ecdf5e9d370a59dc25df03330f6e21e3e18" }, "downloads": -1, "filename": "compago-1.4.tar.gz", "has_sig": false, "md5_digest": "962b308a2c070d6b87ad94c70029c1c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9860, "upload_time": "2013-02-13T16:32:49", "url": "https://files.pythonhosted.org/packages/21/01/6a3a9d9642dd0082fed4ff21f82718a47de8d89ad5b0311eb5f4bfba2c5f/compago-1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "962b308a2c070d6b87ad94c70029c1c0", "sha256": "21ad5716efc60b49e73964be8afd1ecdf5e9d370a59dc25df03330f6e21e3e18" }, "downloads": -1, "filename": "compago-1.4.tar.gz", "has_sig": false, "md5_digest": "962b308a2c070d6b87ad94c70029c1c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9860, "upload_time": "2013-02-13T16:32:49", "url": "https://files.pythonhosted.org/packages/21/01/6a3a9d9642dd0082fed4ff21f82718a47de8d89ad5b0311eb5f4bfba2c5f/compago-1.4.tar.gz" } ] }