{ "info": { "author": "Michele Lacchia", "author_email": "michelelacchia@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2" ], "description": "History\n=======\n\nVersion 1.3\n * Better Python 3 support.\n * Improved test coverage.\n * Fixed #22: *varargs are now displayed in command help.\n * Fixed annoying beavhior of *varargs help when no keyword\n arguments are present.\n\nVersion 1.2\n * Python 3 support!\n * Runs from Python 2.6 up to 3.2.\n * More unit tests.\n * Code coverage to 89%.\n * Single-letter arguments are now automatically added to shortopts.\n * Fixed #14: Unable to mix varargs and kwargs.\n\nVersion 1.1\n\t* ``baker.run()`` now prints the return value of the command function.\n\t* Command usage help now shows help for optional arguments.\n\t* Added options to ``baker.run()``.\n\t* Added ``baker.usage([commandname])``.\n\t* Added unit tests.\n\t* Fixed bugs.\n\n\nOverview\n========\n\nBaker lets you easily add a command line interface to your Python functions\nusing a simple decorator, to create scripts with \"sub-commands\", similar to\nDjango's ``manage.py``, ``svn``, ``hg``, etc.::\n\n\t#!python\n\timport baker\n\t\n\t# An imaginary script full of useful Python functions\n\t\n\t@baker.command\n\tdef set(name, value=None, overwrite=False):\n\t\t\"\"\"Sets the value of a key in the database.\n\t\t\n\t\tIf you don't specify a value, the named key is deleted. Overwriting\n\t\ta value may not be visible to all clients until the next full sync.\n\t\t\"\"\"\n\t\t\n\t db = get_database()\n\t if overwrite or name not in db:\n\t if value is None:\n\t \tdb.delete(name)\n\t \tprint \"Deleted %s\" % name\n\t else:\n\t \tdb.set(name, value)\n\t \t\tprint \"Set %s to %s\" % (name, value)\n\t else:\n\t \tprint \"Key exists!\"\n\t\n\t@baker.command\n\tdef get(name):\n\t\t\"Prints the value of a key in the database.\"\n\t\t\n\t\tdb = get_database()\n\t\tprint db.get(name)\n\t\t\n\tbaker.run()\n\nYou can then run the script and use your function names and parameters as the\ncommand line interface, using ``optparse``-style options::\n\n\t$ script.py set alfa bravo\n\tSet alfa to bravo\n\t\n\t$ script.py set --overwrite alfa charlie\n\tSet alfa to charlie\n\t\n\t$ script.py get alfa\n\tcharlie\n\t\n\t$ script.py --help\n\t\n\tAvailable commands:\n\t\n\t get Prints the value of a key in the database.\n\t set Sets the value of a key in the database\n\t \n\tUse \"script.py --help\" for individual command help.\n\t\n\t$ script.py set --help\n\t\n\tUsage: script.py set []\n\t\n\tSets the value of a key in the database.\n\t\n\t If you don't specify a value, the named key is deleted. Overwriting\n\t\ta value may not be visible to all clients until the next full sync.\n\t\n\tOptions:\n\n --overwrite\n \n \nArguments\n=========\n\nBaker maps command line options to function parameters in the most natural way\navailable.\n\nBare arguments are used to fill in required parameters::\n\n\t@baker.command\n\tdef test(a, b, c):\n\t print \"a=\", a, \"b=\", b, \"c=\", c\n\n\t$ script.py test 1 2 3\n\ta= 1 b= 2 c= 3\n\n``--option`` arguments are used to fill in keyword parameters. You can use\n``--option value`` or ``--option=value``, as in optparse::\n\n\t@baker.command\n\tdef test(key=\"C\"):\n\t\tprint \"In the key of:\", key\n\n\t$ script.py test\n\tIn the key of: C\n\t$ script.py test --key A\n\tIn the key of: A\n\t$ script.py test --key=Gb\n\tIn the key of: Gb\n\nFunction parameters where the default is ``None`` are considered optional\narguments and will be filled if extra arguments are available. Otherwise,\nextra bare arguments never fill in keyword parameters::\n \n \t@baker.command\n \tdef test(start, end=None, sortby=\"time\"):\n \t print \"start=\", start, \"end=\", end, \"sort=\", sortby\n\n \t$ script.py --sortby name 1\n \tstart= 1 end= sortby= name\n \t$ script.py 1 2\n \tstart= 1 end= 2 sortby= time\n\nIf a keyword parameter's default is an int or float, Baker will try to\nconvert the option's string to the same type::\n \n \t@baker.command\n \tdef test(limit=10):\n \t\tprint type(limit)\n\n \t$ script.py test --limit 10\n \t\n\nIf the default of a parameter is a boolean, the corresponding command line\noption is a flag that sets the opposite of the default::\n \n \t@baker.command\n \tdef test(name, verbose=False):\n \t if verbose: print \"Opening\", name\n\n \t$ script.py test --verbose alfa\n \tOpening alfa\n\nIf the function takes ``*`` and/or ``**`` parameters, any leftover arguments\nand options will fill them in.\n\n\nParameter help\n==============\n\nBaker lets you specify help for parameters in three ways.\n\nIn the decorator::\n\n\t@baker.command(params={\"force\": \"Delete even if the file exists\"})\n\tdef delete(filename, force=False):\n\t\t\"Deletes a file.\"\n\t\tif force or not os.path.exists(filename):\n\t\t\tos.remove(filename)\n\nIn Python 3.x, you can use parameter annotations to associate doc strings\nwith parameters::\n \n @baker.command\n def delete(filename, force:\"Delete even if the file exists.\"=False):\n \t\"Deletes a file.\"\n\t\tif force or not os.path.exists(filename):\n\t\t\tos.remove(filename)\n\t\t\t\nBaker can parse the function's docstring for Sphinx-style ``:param`` blocks::\n\n\t@baker.command\n\tdef delete(filename, force=False):\n\t\t\"\"\"Deletes a file.\n\t\t\n\t\t:param force: Delete even if the file exists.\n\t\t\"\"\"\n\t\tif force or not os.path.exists(filename):\n\t\t\tos.remove(filename)\n \n \nShort options\n=============\n\nTo allow single-character short options (e.g. ``-v`` for ``--verbose``), use\nthe ``shortopts`` keyword on the decorator::\n\n\t@baker.command(shortopts={\"verbose\": \"v\"}, params={\"verbose\", \"Spew lots\"})\n\tdef test(verbose=False):\n\t\tpass\n\n\t$ script.py test --help\n\t\n\tUsage: script.py test\n\t\n\tOptions:\n\t\n\t -v --verbose Spew lots\n\t \nYou can group multiple short flag options together (``-xvc``). You can also\noptionally not put a space between a short option and its argument, for\nexample ``-nCASE`` instead of ``-n CASE``.\n\n\n``run()`` function\n==================\n\nThe ``run()`` function has a few useful options.\n\n* ``argv``: the list of options to parse. Default is ``sys.argv``.\n* ``main``: if True (the default), this function acts like the main function\n of the module -- it prints errors instead of raising exceptions, prints\n the return value of the command function, and exits with an error code on\n errors.\n* ``help_on_error``: if True, when an error occurs, automatically prints\n the usage help after the error message. Default is False.\n* ``outfile``, ``errorfile``, ``helpfile``: the files to use for output,\n errors, and usage help. Defaults are stdout, stderr, and stdout.\n* ``errorcode``: if main=True and this value is not 0, calls ``sys.exit()``\n with this code in the event of an error\n\n\n``usage()`` function\n====================\n\nUse the ``usage()`` function if you need to print the usage help\nprogrammatically::\n\n\t# Print overall help\n\tbaker.usage()\n\t\n\t# Print help for a command\n\tbaker.usage(\"commandname\")\n\t\n\t# Print to a file\n\tbaker.usage(\"commandname\", file=sys.stdout)\n\n\nMiscellaneous\n=============\n\nInstead of ``baker.run()``, you can use ``baker.test()`` to print out how\nBaker will call your function based on the given command line.\n\nAs in many UNIX command line utilities, if you specify a single hyphen\n(``-``) as a bare argument, any subsequent arguments will not parsed as\noptions, even if they start with ``--``.\n \nCommands are automatically given the same name as the decorated function.\nTo give a command a different name, use the ``name`` keyword on the\ndecorator. This is especially useful when the command name you want\nisn't a valid Python identifier::\n \n \t@baker.command(name=\"track-all\")\n \tdef trackall():\n \t\tpass\n\nYou can specify a \"default\" command that is used when the first argument\nto the script doesn't look like a command name::\n \n \t@baker.command(default=True)\n \tdef here(back=False):\n \t print \"here! back=\", back\n \t \n \t@baker.command\n \tdef there(back=False):\n \t print \"there! back=\", back\n\n \t$ script.py --back\n \there! back= True\n \t\nThe ``baker`` module contains a ``Baker`` class you can instantiate if you\ndon't want to use the global functions::\n\n\tmybaker = baker.Baker()\n\t\n\t@mybaker.command\n\tdef test():\n\t\tprint \"hello\"\n\t\n\tmybaker.run()\n\n\nAbout Baker\n===========\n\nCreated by Matt Chaput.\n\nReleased under the\n`Apache 2.0 license `_\n\nPlease file bugs in the BitBucket issue tracker.\n\nhttp://bitbucket.org/mchaput/baker", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://bitbucket.org/mchaput/baker", "keywords": "command line scripting", "license": "Apache 2.0", "maintainer": null, "maintainer_email": null, "name": "Baker", "package_url": "https://pypi.org/project/Baker/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Baker/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://bitbucket.org/mchaput/baker" }, "release_url": "https://pypi.org/project/Baker/1.3/", "requires_dist": null, "requires_python": null, "summary": "Easy, powerful access to Python functions from the command line", "version": "1.3" }, "last_serial": 1387690, "releases": { "1.1": [ { "comment_text": "", "digests": { "md5": "8d6a077fea30cfa4f1a57cc7778497e6", "sha256": "11a541b11e8a70b74bdcd01f7ce90617e0f2307c9de6674560b003b7bd6f6f13" }, "downloads": -1, "filename": "Baker-1.1-py2.6.egg", "has_sig": false, "md5_digest": "8d6a077fea30cfa4f1a57cc7778497e6", "packagetype": "bdist_egg", "python_version": "2.6", "requires_python": null, "size": 17965, "upload_time": "2010-02-21T19:10:44", "url": "https://files.pythonhosted.org/packages/f4/9f/c0714ebd5d3cd945d76948ac25959c1750a098e9acfe4c1ea3effa59e7ea/Baker-1.1-py2.6.egg" }, { "comment_text": "", "digests": { "md5": "2107b353d7506c79ad9ff3eda8f6dd26", "sha256": "892e988b8f3c8c223efb64fa7ae8a397ff60a955c9de2c34a0472a3ed1153c18" }, "downloads": -1, "filename": "Baker-1.1.tar.gz", "has_sig": false, "md5_digest": "2107b353d7506c79ad9ff3eda8f6dd26", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10911, "upload_time": "2010-02-21T19:10:43", "url": "https://files.pythonhosted.org/packages/24/e0/c76a0f298e219827980abd151cf7dfa6b98159b8a8ab546ac47b03ac956b/Baker-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "55c6288481c78fd70aefbc19a2d455b5", "sha256": "63c6617a0cd82f5f8f79d93734f283b67b9442dfb9bdfb1c179ab6951399290d" }, "downloads": -1, "filename": "Baker-1.2-py27-none-any.whl", "has_sig": false, "md5_digest": "55c6288481c78fd70aefbc19a2d455b5", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13260, "upload_time": "2012-08-17T10:26:12", "url": "https://files.pythonhosted.org/packages/d7/3c/020dab77464653c221e04ef2177c548fb5ddedaab1fe7799679ad2fcf1d8/Baker-1.2-py27-none-any.whl" }, { "comment_text": "", "digests": { "md5": "892866d002cc70fdfb1bd24eeb15eacf", "sha256": "17b344f45387535b000357965ac11619b3381704ffddcfa7df46661901385cc6" }, "downloads": -1, "filename": "Baker-1.2.tar.gz", "has_sig": false, "md5_digest": "892866d002cc70fdfb1bd24eeb15eacf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13074, "upload_time": "2012-07-08T19:18:45", "url": "https://files.pythonhosted.org/packages/b6/0f/5bdec418f9ebd0183f63b2040813f33d688bd7e9f170d77b00cc006f477c/Baker-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "46cf0d65e6153f75665ffc4b2f88d1cb", "sha256": "190809fe94ad0fbcfb385e76e5b8016d06359523dc582c8c40c8be5e0bcace45" }, "downloads": -1, "filename": "Baker-1.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "46cf0d65e6153f75665ffc4b2f88d1cb", "packagetype": "bdist_wheel", "python_version": "3.4", "requires_python": null, "size": 17180, "upload_time": "2015-01-19T10:11:43", "url": "https://files.pythonhosted.org/packages/6f/c4/bb9e5572b33493b8bc79251f157eb96462334ae67482309db8af56f5204f/Baker-1.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e628d935accf915abf6cdef77b81d8d3", "sha256": "2d81e99af7d7d6441297a0c13de023fe3f1510718e89d2baacea917ee09d154d" }, "downloads": -1, "filename": "Baker-1.3.tar.gz", "has_sig": false, "md5_digest": "e628d935accf915abf6cdef77b81d8d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13300, "upload_time": "2012-08-23T06:33:23", "url": "https://files.pythonhosted.org/packages/43/84/4a0ed2bd69b8079a5f8a8eda478c7ebe267e65f3f87a61a0b56353b6961c/Baker-1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "46cf0d65e6153f75665ffc4b2f88d1cb", "sha256": "190809fe94ad0fbcfb385e76e5b8016d06359523dc582c8c40c8be5e0bcace45" }, "downloads": -1, "filename": "Baker-1.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "46cf0d65e6153f75665ffc4b2f88d1cb", "packagetype": "bdist_wheel", "python_version": "3.4", "requires_python": null, "size": 17180, "upload_time": "2015-01-19T10:11:43", "url": "https://files.pythonhosted.org/packages/6f/c4/bb9e5572b33493b8bc79251f157eb96462334ae67482309db8af56f5204f/Baker-1.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e628d935accf915abf6cdef77b81d8d3", "sha256": "2d81e99af7d7d6441297a0c13de023fe3f1510718e89d2baacea917ee09d154d" }, "downloads": -1, "filename": "Baker-1.3.tar.gz", "has_sig": false, "md5_digest": "e628d935accf915abf6cdef77b81d8d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13300, "upload_time": "2012-08-23T06:33:23", "url": "https://files.pythonhosted.org/packages/43/84/4a0ed2bd69b8079a5f8a8eda478c7ebe267e65f3f87a61a0b56353b6961c/Baker-1.3.tar.gz" } ] }