{ "info": { "author": "Roberto Aguilar", "author_email": "r@rreboto.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Utilities" ], "description": "# cmdline\nThe cmdline package provides a standard way to specify and override command settings and logging configuration. Using cmdline setttings is as simple as creating a `settings.yml`:\n```\nREMOTE_ADDR:\n default: 'https://example.com/'\n help: the remote address\n```\nand compiling the settings in your main program:\n```\nfrom cmdline import SettingsParser, settings\n\n\ndef main():\n SettingsParser.compile_settings()\n\n remote = settings.REMOTE_ADDR\n\n print('remote addr:', remote)\n\n\nif __name__ == '__main__':\n sys.exit(main())\n```\nYour program can then be called in any of the following ways:\n```\n$ remote\nremote addr: https://example.com/\n$ export REMOTE_ADDR=https://env.example.com/\n$ remote\nremote addr: https://env.example.com/\n$ remote --remote-addr=https://arg-takes-precedence.example.com/\nremote addr: https://arg-takes-precedence.example.com/\n```\n\n## Installation\n```\npip install cmdline\n```\n\n## Settings\nSettings are configured in an overlaid fashion starting with a root configuration packaged with the application. Standard [argparse](https://docs.python.org/3/library/argparse.html) options are used to configure settings.\n\n### Override defaults\nThe packaged settings can be overridden by additional settings files on the filesystem, environment variables, and finally command line arguments. For a command named `remote` order in which they are applied are:\n\n- packaged settings\n- /etc/remote/settings.yml\n- ~/.remote/settings.yml\n- environment variables\n- command line arguments\n\nEnvironment variables map exactly to the name of the setting, i.e. the environment variable `REMOTE_ADDR` configures the `REMOTE_ADDR` setting.\n\nCommand line arguments are lowercase-dashed versions of the setting, for instance, the command line argument `--remote-addr` configures the `REMOTE_ADDR` setting.\n\n### Subcommands\nThe settings parser supports [argparse subcommands](https://docs.python.org/3/library/argparse.html#sub-commands). A setting can be configured to be for a subcommand by adding a `_subcommand` key to the setting's options. For example:\n```\nCOPY_FORCE\n default: no\n _subcommand: copy\n```\nThe `_SUBCOMMAND` setting contains the name of the subcommand the command was run with.\n\n### Documentation\nCommand descriptions and help text can be added in a `_COMMANDS` section. The `_main` will set the description for the main program. Any other keys will correspond to a subcommand by the same name. For example, below sets the description for the main program and the description and help text for the `copy` subcommand:\n```\n_COMMANDS:\n _main:\n description: >\n this is main description and can be a very long string\n that covers multiple lines\n copy:\n description: >\n this is copy subcommand description and can be a very long string\n that covers multiple lines\n help: copy files\n```\n### Type conversion\nSettings can be converted to a particular type using argparse's `type` setting. For example setting `type: int` will convert the setting into an integer. This is done by using Python's built-in `int()` function.\n\nWhen `type` is a dotted string, the given function will be imported and used. For example, setting `type: convesion.convert_bool` will call the `convert_bool()` function in the [conversion](https://pypi.python.org/pypi/conversion) package.\n\n## Logging\nSimilarly, logging is configured through Python's `logging.config.dictConfig()` function. More info on dictconfig is at [docs.python.org](https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig); an example is below. This configuration sets a `console` handler that sends logs to stdout and a `null` handler that throws away logs. The default logging configuration is to log WARN level and higher messages to the console, which is setup by the `root` logger, and two additional loggers are configured for the `mypkg.foo` and `mypkg.bar` loggers, where the loglevel for `mypkg.foo` is set to DEBUG and `mypkg.bar` is thrown out altogether.\n\n```\nversion: 1\ndisable_existing_loggers: False\n\nformatters:\n simple:\n format: \"%(asctime)s %(name)s:%(lineno)d %(levelname)s %(message)s\"\n\n\nhandlers:\n console:\n class: logging.StreamHandler\n level: WARN\n formatter: simple\n stream: ext://sys.stdout\n\n \"null\":\n class: logging.NullHandler\n\n\nloggers:\n mypkg.foo:\n level: DEBUG\n handlers: [console]\n propagate: no\n\n mypkg.bar:\n handlers: [\"null\"]\n propagate: no\n\n\nroot:\n level: WARN\n handlers: [console]\n```\nOnce the configuration is written, logging is configured by calling the `setup_logging()` function:\n```\nimport logging\nfrom cmdline import setup_logging\n\n\ndef main():\n setup_logging()\n\n logging.getLogger(__name__).warning('ello')\n\n\nif __name__ == '__main__':\n sys.exit(main())\n```\n### Log level environment\nThe only logging configuration that can be updated outside the configuration file is the default log level, which can be changed with the environment variable `LOG_LEVEL`; for example, `LOG_LEVEL=debug remote`.\n\n## File location\nCreate a directory named `config`. In that directory, create the files `logconfig.yml` and `settings.yml`. A bare-bones `setup.py` that installs these files correctly is below:\n```\n#!/usr/bin/env python \nimport os\n\nfrom setuptools import setup\n\n\ndef get_data_files(base):\n for dirpath, dirnames, filenames in os.walk(base):\n for filename in filenames:\n yield os.path.join(dirpath, filename)\n\n\ndata_files = [\n ('config', list(get_data_files('config'))),\n]\n\nsetup(name='remote',\n version='0.0.1',\n packages=['remote'],\n data_files=data_files,\n entry_points = {\n 'console_scripts': [\n 'remote = remote.command:main',\n ],\n },\n)\n```\nThe file structure for the `setup.py` above looks like:\n```\nroot_dir/\n+- remote/\n| +- __init__.py\n| +- command.py\n+- config/\n| +- logconfig.yml\n| +- settings.yml\n+- setup.py\n```\n## Config root environment variable\nSetting the environment variable `CMDLINE_CONFIG_ROOT` will make the given path the primary config location for settings and logging.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/rca/cmdline", "keywords": "", "license": "LICENSE", "maintainer": "", "maintainer_email": "", "name": "cmdline", "package_url": "https://pypi.org/project/cmdline/", "platform": "", "project_url": "https://pypi.org/project/cmdline/", "project_urls": { "Homepage": "http://github.com/rca/cmdline" }, "release_url": "https://pypi.org/project/cmdline/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Utilities for consistent command line tools", "version": "0.2.0" }, "last_serial": 4562729, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "d6d662c444191ac540d00e946a1ef9ce", "sha256": "a2fea98ba4e5c2c11649342116bfbe62fb3fe7550d80bb9516423304befe10b1" }, "downloads": -1, "filename": "cmdline-0.0.1.tar.gz", "has_sig": false, "md5_digest": "d6d662c444191ac540d00e946a1ef9ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2583, "upload_time": "2016-06-15T13:57:50", "url": "https://files.pythonhosted.org/packages/02/2e/975aafdf124c5a89ed3789589962e53c35da3069cde3976dd4f411d2adba/cmdline-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "304baf66d598a27bd2dfee32e2d5d001", "sha256": "8bcf41c89185d98d1fac5c6a8cd07988d5216c34e2051c691754982b7857dc40" }, "downloads": -1, "filename": "cmdline-0.0.2.tar.gz", "has_sig": false, "md5_digest": "304baf66d598a27bd2dfee32e2d5d001", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3177, "upload_time": "2016-06-16T03:46:57", "url": "https://files.pythonhosted.org/packages/12/ef/569daf7cf47fa3dbedbf8f62ad8db6c97b97ee78d72ed9e8ecb63cc7868e/cmdline-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "44b311db5df3bfce57d2c441bb821f16", "sha256": "e01477d20db0ecba9adb67335c7070e3de76392d585a9db5cf26efa4b3d6b8a9" }, "downloads": -1, "filename": "cmdline-0.0.3.tar.gz", "has_sig": false, "md5_digest": "44b311db5df3bfce57d2c441bb821f16", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3272, "upload_time": "2016-06-16T03:59:32", "url": "https://files.pythonhosted.org/packages/8d/a4/36d4d8d30c4106362604707e6c17b65621b84265054e0fb5ae9622cb1f6b/cmdline-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "9bae40c5249a987cbbc45055a49c4b4a", "sha256": "3252a43427e5340eb27f2b6127ffafb254b34c91261e5e80589da64744f6b3f4" }, "downloads": -1, "filename": "cmdline-0.0.4.tar.gz", "has_sig": false, "md5_digest": "9bae40c5249a987cbbc45055a49c4b4a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3310, "upload_time": "2016-06-16T11:33:14", "url": "https://files.pythonhosted.org/packages/ee/d0/84c58f4ea09453d8f1e4eab4a6e01bb7ebe7ec1c9f889e405526e5e3180d/cmdline-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "41ea25df5d550d12400ff36dbe6a3696", "sha256": "2cb7434781fc94bfca82f875494431b9b17d06a36946e7c89a8efb5d417ac38f" }, "downloads": -1, "filename": "cmdline-0.0.5.tar.gz", "has_sig": false, "md5_digest": "41ea25df5d550d12400ff36dbe6a3696", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5702, "upload_time": "2016-06-16T13:55:35", "url": "https://files.pythonhosted.org/packages/d6/cb/e527d847af6199e817e80eb32140700b9ccb0fcdd143a87ece6fdd7795c3/cmdline-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "a5b87af13654a9bc897f9c3bb5cc12ce", "sha256": "96cc350e86f1a51816db4546390088961beeb6676a4c77f324d5d05a9beb5750" }, "downloads": -1, "filename": "cmdline-0.0.6.tar.gz", "has_sig": false, "md5_digest": "a5b87af13654a9bc897f9c3bb5cc12ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5907, "upload_time": "2016-06-16T14:20:54", "url": "https://files.pythonhosted.org/packages/31/55/4c4bdaf9b7dc248e83394b507d8f7a55edd5f0dd40391eae11b464c2728c/cmdline-0.0.6.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "0ae55a35e880172332beb197a267f105", "sha256": "07407a7895726c546af7a2460d0020180862fe5486cb8441e2cbb9424c7756cf" }, "downloads": -1, "filename": "cmdline-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0ae55a35e880172332beb197a267f105", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6350, "upload_time": "2016-06-27T16:51:38", "url": "https://files.pythonhosted.org/packages/a7/8b/6228024f7d5126fc1c08d9272452cb519cdb608fefd7623d1cb95c891f9d/cmdline-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "1ac94b7ae7d9b5e77dc6185e557c8f48", "sha256": "745e222822cfff9da4b25d5d084e4438578e35ea10cf85b37dcfee0434b9caca" }, "downloads": -1, "filename": "cmdline-0.1.1.tar.gz", "has_sig": false, "md5_digest": "1ac94b7ae7d9b5e77dc6185e557c8f48", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6445, "upload_time": "2016-06-27T17:20:29", "url": "https://files.pythonhosted.org/packages/b2/2f/3e0892f58028f8c8370ae1608f60b5a6704af95ed48cb19f9d70129525b0/cmdline-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "10e1879c15ba6c7bc7eb0844b114c111", "sha256": "9bd06998deffc64f34d2a6ef2068618113069d8705184beee103f4b7695c5c6e" }, "downloads": -1, "filename": "cmdline-0.1.2.tar.gz", "has_sig": false, "md5_digest": "10e1879c15ba6c7bc7eb0844b114c111", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6462, "upload_time": "2016-06-28T13:43:51", "url": "https://files.pythonhosted.org/packages/f8/61/f8c47f1bb9bc5063fe5d4fbc0b56d549930c50029963b496b84f3a403e25/cmdline-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "44f1ec1631eb8837306293548a93dc87", "sha256": "e845f7ec34580b9479dba957905287d788d72d6e444c862b19d259104df5ad4a" }, "downloads": -1, "filename": "cmdline-0.1.3.tar.gz", "has_sig": false, "md5_digest": "44f1ec1631eb8837306293548a93dc87", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6566, "upload_time": "2016-06-28T14:10:31", "url": "https://files.pythonhosted.org/packages/a6/5b/df772e59dd259570be1360739455e2abbea88484147471c6bda2f8979294/cmdline-0.1.3.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "0e8374c9b36f838e2bf00ad9b5b76039", "sha256": "af452392102856fc968e2ac2038dd11d19fcd3c5489c7797e1aab2b58a8137db" }, "downloads": -1, "filename": "cmdline-0.1.5.tar.gz", "has_sig": false, "md5_digest": "0e8374c9b36f838e2bf00ad9b5b76039", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6632, "upload_time": "2016-06-30T11:22:19", "url": "https://files.pythonhosted.org/packages/cd/eb/30ffc2831f429ca748a79a58d4162f7e6d1817f3f208c15c18bdfbe30565/cmdline-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "1ed26baf5b6646046749daaf6d3a3310", "sha256": "be2cb4711e9111bb7386a408e3c66a730c36dd6ac05851a9f03d0f4eae63536a" }, "downloads": -1, "filename": "cmdline-0.1.6.tar.gz", "has_sig": false, "md5_digest": "1ed26baf5b6646046749daaf6d3a3310", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6552, "upload_time": "2016-06-30T15:03:47", "url": "https://files.pythonhosted.org/packages/10/26/5c348f0562729a63a77b6e63e4e7290eb47b5fb93458ad89c7f0c5ca237d/cmdline-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "59af26cfa6844562976997487d6aaf48", "sha256": "5dc2326a436448bc89dadce9da980fc289ddd43fba3e752f4108393550fab655" }, "downloads": -1, "filename": "cmdline-0.1.7.tar.gz", "has_sig": false, "md5_digest": "59af26cfa6844562976997487d6aaf48", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7203, "upload_time": "2016-12-23T14:52:39", "url": "https://files.pythonhosted.org/packages/71/5c/995cb7b1edd18ec758d98e7758b379b24570f7380878cf8233d22d95d100/cmdline-0.1.7.tar.gz" } ], "0.1.8": [ { "comment_text": "", "digests": { "md5": "561f92282692fe5a9e0a99ea533e5a7b", "sha256": "324cc8fc6580f221824821c47232c297ed1f7cc737186a57305a8c08fc902dd7" }, "downloads": -1, "filename": "cmdline-0.1.8.tar.gz", "has_sig": false, "md5_digest": "561f92282692fe5a9e0a99ea533e5a7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7203, "upload_time": "2016-12-23T17:35:13", "url": "https://files.pythonhosted.org/packages/70/1e/42ed052a89c29e6d0b67c6bd6efa994eee54b2beeef9bd8c6b9bd5158504/cmdline-0.1.8.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "6a470da284f2e8bfe68d5c91769f33e3", "sha256": "7cf6af53549892b2218c2f56a199dff54a733be5c5515c0fd626812070b0a86a" }, "downloads": -1, "filename": "cmdline-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6a470da284f2e8bfe68d5c91769f33e3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11778, "upload_time": "2018-12-05T07:00:12", "url": "https://files.pythonhosted.org/packages/c8/f7/fa740bb16ddd4a656288608f36f3fb558b29c2b7107374a8dd40732de4e3/cmdline-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6a470da284f2e8bfe68d5c91769f33e3", "sha256": "7cf6af53549892b2218c2f56a199dff54a733be5c5515c0fd626812070b0a86a" }, "downloads": -1, "filename": "cmdline-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6a470da284f2e8bfe68d5c91769f33e3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11778, "upload_time": "2018-12-05T07:00:12", "url": "https://files.pythonhosted.org/packages/c8/f7/fa740bb16ddd4a656288608f36f3fb558b29c2b7107374a8dd40732de4e3/cmdline-0.2.0.tar.gz" } ] }