{ "info": { "author": "Dusty Phillips", "author_email": "dusty@buchuki.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4" ], "description": "Opterator\r\n=========\r\nOpterator is an option parsing script for Python that takes the boilerplate out\r\nof option parsing.\r\n\r\nOpterator is based on the idea that a main() function for a script can be\r\ndecorated to allow command-line arguments to be translated into method\r\nparameters. This allows it to be self-documenting, and reduces errors in\r\ncreating and assigning options. I don't know if you'd want to use it for large\r\nprograms, but it's really useful for quick and dirty ones where you can't\r\ndecide if you want to bother with argparse, but querying sys.argv manually is a\r\nbit too complicated.\r\n\r\nFor example, you can document a simple program for renaming a file using\r\nopterator like this:\r\n\r\n.. code-block:: python\r\n\r\n from opterator import opterate\r\n @opterate\r\n def main(source, dest, backup=False, interactive=False):\r\n '''A script for renaming files\r\n :param source: the source file\r\n :param dest: the destination\r\n :param backup: backup the file\r\n :param interactive: -p --interactive interatively\r\n move files... '''\r\n # Move the file\r\n \r\n if __name__ == '__main__':\r\n main()\r\n\r\nFor comparison, an optparse program would take several more less readable \r\nlines of code:\r\n\r\n.. code-block:: python\r\n\r\n from argparse import ArgumentParser\r\n\r\n def main():\r\n '''main entrypoint for renaming files. Accept two options, backup\r\n and interactive'''\r\n parser = ArgumentParser(usage=\"A script for renaming files\")\r\n parser.add_argument(\"source\", help=\"the source file\")\r\n parser.add_argument(\"dest\", help=\"the destination\")\r\n parser.add_argument('-b', '--backup', action=\"store_true\",\r\n help='backup the file')\r\n parser.add_argument('-p', '--interactive', action=\"store_true\",\r\n help='interactively move files')\r\n arguments = parser.parse_args()\r\n # Move the file\r\n \r\n if __name__ == '__main__':\r\n main()\r\n\r\n\r\nOpterator automatically generates help messages from the docstring. The main\r\npart of the docstring becomes the main part of the help string. The individual\r\nparameter docstrings become the helptext for the arguments. By default, the\r\nlong and short form of a given parameter come from the parameter name and the\r\nfirst character of the parameter name. In Python 3, you can replace this with\r\na function annotation; or in Python 2 or 3 you can replace them by adding\r\noptions that begin with a ``-`` character between the parameter and the\r\ndocstring.\r\n\r\nSo, if your main function looks like this:\r\n\r\n.. code-block:: python\r\n\r\n from opterator import opterate\r\n\r\n\r\n @opterate\r\n def main(filename1, filename2, recursive=False, backup=False,\r\n suffix='~', *other_filenames):\r\n '''An example copy script with some example parameters that might\r\n be used in a file or directory copy command.\r\n\r\n :param recursive: -r --recursive copy directories\r\n recursively\r\n :param backup: -b --backup backup any files you copy over\r\n :param suffix: -S --suffix override the usual backup\r\n suffix '''\r\n filenames = [filename1, filename2] + list(other_filenames)\r\n destination = filenames.pop()\r\n\r\n print(\"You asked to move %s to %s\" % (filenames, destination))\r\n if recursive:\r\n print(\"You asked to copy directories recursively.\")\r\n if backup:\r\n print(\"You asked to backup any overwritten files.\")\r\n print(\"You would use the suffix %s\" % suffix)\r\n\r\n if __name__ == '__main__':\r\n main()\r\n\r\nYour help text will look like this::\r\n\r\n dusty:opterator $ python cp.py -h\r\n usage: cp.py [-h] [-r] [-b] [-S SUFFIX]\r\n filename1 filename2 [other_filenames [other_filenames ...]]\r\n\r\n An example copy script with some example parameters that might be used in a\r\n file or directory copy command.\r\n\r\n positional arguments:\r\n filename1\r\n filename2\r\n other_filenames\r\n\r\n optional arguments:\r\n -h, --help show this help message and exit\r\n -r, --recursive copy directories recursively\r\n -b, --backup backup any files you copy over\r\n -S SUFFIX, --suffix SUFFIX\r\n override the usual backup suffix\r\n\r\nIf you want to try out the funky function annotation syntax, give this\r\na shot:\r\n\r\n.. code-block:: python\r\n\r\n from opterator import opterate\r\n\r\n\r\n @opterate\r\n def main(show_details:['-l']=False, cols:['-w', '--width']='', *files):\r\n '''\r\n List information about a particular file or set of files\r\n\r\n :param show_details: Whether to show detailed info about files\r\n :param cols: specify screen width\r\n '''\r\n print(files)\r\n print(show_details)\r\n print(cols)\r\n\r\n if __name__ == '__main__':\r\n main()", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/buchuki/opterator/archive/0.5.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/buchuki/opterator/", "keywords": "opterator option parse parser options", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "opterator", "package_url": "https://pypi.org/project/opterator/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/opterator/", "project_urls": { "Download": "https://github.com/buchuki/opterator/archive/0.5.tar.gz", "Homepage": "http://github.com/buchuki/opterator/" }, "release_url": "https://pypi.org/project/opterator/0.5/", "requires_dist": null, "requires_python": null, "summary": "Easy option parsing introspected from function signature.", "version": "0.5" }, "last_serial": 1378799, "releases": { "0.1": [ { "comment_text": "built for Linux-2.6.29-ARCH-i686-Genuine_Intel-R-_CPU_T2500_@_2.00GHz-with-glibc2.0", "digests": { "md5": "da059e14e5172037a20eb12e85433fbd", "sha256": "07259e57932bd8fdf90095dee4caf94408d7a628fc5f555677a8d986e2b71290" }, "downloads": -1, "filename": "opterator-0.1.linux-i686.tar.gz", "has_sig": false, "md5_digest": "da059e14e5172037a20eb12e85433fbd", "packagetype": "bdist_dumb", "python_version": "any", "requires_python": null, "size": 3938, "upload_time": "2009-05-28T06:01:39", "url": "https://files.pythonhosted.org/packages/f0/dc/3476cf137da07608d01c8924aad081c0d64bdb0beead6a13d3ce738fab3a/opterator-0.1.linux-i686.tar.gz" }, { "comment_text": "", "digests": { "md5": "2fb2e6552470cc93b023eb70dd2ddc7c", "sha256": "c817d3ff92e9a55c9d9a8a8339199fc8c02fdace43e1e315a83a3fd275e0740f" }, "downloads": -1, "filename": "opterator-0.1.tar.gz", "has_sig": false, "md5_digest": "2fb2e6552470cc93b023eb70dd2ddc7c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6299, "upload_time": "2009-05-28T06:01:38", "url": "https://files.pythonhosted.org/packages/99/3d/48d8dfb8182cf36d181c52e62fa7f7785507849c12650ecd751741271d88/opterator-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "8d584cad6cfb0fdfdd1d49aaea7905e0", "sha256": "2f5ff1a19d36c4a2776d0d260a560592a396c592d003e5d5bc25c4daa593af9f" }, "downloads": -1, "filename": "opterator-0.2-py2.6.egg", "has_sig": false, "md5_digest": "8d584cad6cfb0fdfdd1d49aaea7905e0", "packagetype": "bdist_egg", "python_version": "2.6", "requires_python": null, "size": 5596, "upload_time": "2009-06-21T19:25:11", "url": "https://files.pythonhosted.org/packages/de/68/4da0707889607f50db47618c8fc5f94786c39f50f5bc7159a0326a67010d/opterator-0.2-py2.6.egg" }, { "comment_text": "", "digests": { "md5": "77cfe0c00bec591b8fe6d14f448598cf", "sha256": "4c63ba1ffaf5ab14649f2d09d49220e951c9e56d54b0fe1d3ad059260b0b31ff" }, "downloads": -1, "filename": "opterator-0.2.tar.gz", "has_sig": false, "md5_digest": "77cfe0c00bec591b8fe6d14f448598cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6595, "upload_time": "2009-06-21T19:25:10", "url": "https://files.pythonhosted.org/packages/2f/49/6ad0ed2d0434b2b086ebe36745b1c67c0ddfb4b3a0d6b3d8b9880910feab/opterator-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "76e36561cb0282cfceef578980dd69fb", "sha256": "3af001422a8c99fb6191466f0b5483ffe4461ae4fa10a5e0ad590e508618e0bd" }, "downloads": -1, "filename": "opterator-0.3.tar.gz", "has_sig": false, "md5_digest": "76e36561cb0282cfceef578980dd69fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5931, "upload_time": "2012-12-02T04:42:34", "url": "https://files.pythonhosted.org/packages/c2/9e/421da142da12e6307ec162b2f94082bfc9bd3cc3ccd7d99c51fb8b55b4e4/opterator-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "34d704e744ee49eb9a20967c152b0dba", "sha256": "44c6fe2dfcef63edec23cf408e540539c26023ddbef1b8dcbc29fc21546576d3" }, "downloads": -1, "filename": "opterator-0.3.1.tar.gz", "has_sig": false, "md5_digest": "34d704e744ee49eb9a20967c152b0dba", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5847, "upload_time": "2012-12-02T04:47:20", "url": "https://files.pythonhosted.org/packages/76/58/a815163a91b0f87a7c94fd2a1beba982b4e3e86b6266f7b0334914d23dd9/opterator-0.3.1.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "d03467d4e4b0a3da28fb8fb94ed1012c", "sha256": "b1ba7e8c659773e17e9a0494623f5ad086bf830d0b45d73e807f78843c779090" }, "downloads": -1, "filename": "opterator-0.4.tar.gz", "has_sig": false, "md5_digest": "d03467d4e4b0a3da28fb8fb94ed1012c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6169, "upload_time": "2012-12-02T22:16:08", "url": "https://files.pythonhosted.org/packages/7d/fc/4f002ca0d9ad27413e47ce6e890464322f9bdd3ad6bca7ca35ce767a7afb/opterator-0.4.tar.gz" } ], "0.5": [] }, "urls": [] }