{ "info": { "author": "Peter Odding", "author_email": "peter@peterodding.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: POSIX", "Operating System :: POSIX :: Linux", "Operating System :: Unix", "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.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Networking", "Topic :: System :: Shells", "Topic :: System :: Systems Administration", "Topic :: Utilities" ], "description": "executor: Programmer friendly subprocess wrapper\n================================================\n\n.. image:: https://travis-ci.org/xolox/python-executor.svg?branch=master\n :target: https://travis-ci.org/xolox/python-executor\n\n.. image:: https://coveralls.io/repos/xolox/python-executor/badge.png?branch=master\n :target: https://coveralls.io/r/xolox/python-executor?branch=master\n\nThe `executor` package is a simple wrapper for Python's subprocess_ module\nthat makes it very easy to handle subprocesses on UNIX systems with proper\nescaping of arguments and error checking:\n\n- An object oriented interface is used to execute commands using sane but\n customizable (and well documented) defaults.\n\n- Remote commands (executed over SSH_) are supported using the same object\n oriented interface, as are commands inside chroots_ (executed using\n schroot_).\n\n- There's also support for executing a group of commands concurrently in\n what's called a \"command pool\". The concurrency level can be customized and\n of course both local and remote commands are supported.\n\nThe package is currently tested on Python 2.6, 2.7, 3.4, 3.5, 3.6 and PyPy. For\nusage instructions please refer to following sections and the documentation_.\n\n.. contents::\n :local:\n :depth: 2\n\nInstallation\n------------\n\nThe `executor` package is available on PyPI_ which means installation should be\nas simple as:\n\n.. code-block:: sh\n\n $ pip install executor\n\nThere's actually a multitude of ways to install Python packages (e.g. the `per\nuser site-packages directory`_, `virtual environments`_ or just installing\nsystem wide) and I have no intention of getting into that discussion here, so\nif this intimidates you then read up on your options before returning to these\ninstructions ;-).\n\nUsage\n-----\n\nThere are two ways to use the `executor` package: As the command line program\n``executor`` and as a Python API. The command line interface is described below\nand there are also some examples of simple use cases of the Python API.\n\n.. contents::\n :local:\n :depth: 1\n\nCommand line\n~~~~~~~~~~~~\n\n.. A DRY solution to avoid duplication of the `executor --help' text:\n..\n.. [[[cog\n.. from humanfriendly.usage import inject_usage\n.. inject_usage('executor.cli')\n.. ]]]\n\n**Usage:** `executor [OPTIONS] COMMAND ...`\n\nEasy subprocess management on the command line based on the Python package with\nthe same name. The \"executor\" program runs external commands with support for\ntimeouts, dynamic startup delay (fudge factor) and exclusive locking.\n\nYou can think of \"executor\" as a combination of the \"flock\" and \"timelimit\"\nprograms with some additional niceties (namely the dynamic startup delay and\nintegrated system logging on UNIX platforms).\n\n**Supported options:**\n\n.. csv-table::\n :header: Option, Description\n :widths: 30, 70\n\n\n \"``-t``, ``--timeout=LIMIT``\",\"Set the time after which the given command will be aborted. By default\n ``LIMIT`` is counted in seconds. You can also use one of the suffixes \"\"s\"\"\n (seconds), \"\"m\"\" (minutes), \"\"h\"\" (hours) or \"\"d\"\" (days).\"\n \"``-f``, ``--fudge-factor=LIMIT``\",\"This option controls the dynamic startup delay (fudge factor) which is\n useful when you want a periodic task to run once per given interval but the\n exact time is not important. Refer to the ``--timeout`` option for acceptable\n values of ``LIMIT``, this number specifies the maximum amount of time to sleep\n before running the command (the minimum is zero, otherwise you could just\n include the command \"\"sleep N && ...\"\" in your command line :-).\"\n \"``-e``, ``--exclusive``\",\"Use an interprocess lock file to guarantee that executor will never run\n the external command concurrently. Refer to the ``--lock-timeout`` option\n to customize blocking / non-blocking behavior. To customize the name\n of the lock file you can use the ``--lock-file`` option.\"\n \"``-T``, ``--lock-timeout=LIMIT``\",\"By default executor tries to claim the lock and if it fails it will exit\n with a nonzero exit code. This option can be used to enable blocking\n behavior. Refer to the ``--timeout`` option for acceptable values of ``LIMIT``.\"\n \"``-l``, ``--lock-file=NAME``\",\"Customize the name of the lock file. By default this is the base name of\n the external command, so if you're running something generic like \"\"bash\"\"\n or \"\"python\"\" you might want to change this :-).\"\n \"``-v``, ``--verbose``\",Increase logging verbosity (can be repeated).\n \"``-q``, ``--quiet``\",Decrease logging verbosity (can be repeated).\n \"``-h``, ``--help``\",Show this message and exit.\n\n.. [[[end]]]\n\nPython API\n~~~~~~~~~~\n\nBelow are some examples of how versatile the `execute()`_ function is. Refer to\nthe API documentation on `Read the Docs`_ for (a lot of) other use cases.\n\n.. contents::\n :local:\n\nChecking status codes\n+++++++++++++++++++++\n\nBy default the status code of the external command is returned as a boolean:\n\n>>> from executor import execute\n>>> execute('true')\nTrue\n\nIf an external command exits with a nonzero status code an exception is raised,\nthis makes it easy to do the right thing (never forget to check the status code\nof an external command without having to write a lot of repetitive code):\n\n>>> execute('false')\nTraceback (most recent call last):\n File \"executor/__init__.py\", line 124, in execute\n cmd.start()\n File \"executor/__init__.py\", line 516, in start\n self.wait()\n File \"executor/__init__.py\", line 541, in wait\n self.check_errors()\n File \"executor/__init__.py\", line 568, in check_errors\n raise ExternalCommandFailed(self)\nexecutor.ExternalCommandFailed: External command failed with exit code 1! (command: bash -c false)\n\nThe ExternalCommandFailed_ exception exposes ``command`` and ``returncode``\nattributes. If you know a command is likely to exit with a nonzero status code\nand you want `execute()`_ to simply return a boolean you can do this instead:\n\n>>> execute('false', check=False)\nFalse\n\nProviding input\n+++++++++++++++\n\nHere's how you can provide input to an external command:\n\n>>> execute('tr a-z A-Z', input='Hello world from Python!\\n')\nHELLO WORLD FROM PYTHON!\nTrue\n\nGetting output\n++++++++++++++\n\nGetting the output of external commands is really easy as well:\n\n>>> execute('hostname', capture=True)\n'peter-macbook'\n\nRunning commands as root\n++++++++++++++++++++++++\n\nIt's also very easy to execute commands with super user privileges:\n\n>>> execute('echo test > /etc/hostname', sudo=True)\n[sudo] password for peter: **********\nTrue\n>>> execute('hostname', capture=True)\n'test'\n\nEnabling logging\n++++++++++++++++\n\nIf you're wondering how prefixing the above command with ``sudo`` would\nend up being helpful, here's how it works:\n\n>>> import logging\n>>> logging.basicConfig()\n>>> logging.getLogger().setLevel(logging.DEBUG)\n>>> execute('echo peter-macbook > /etc/hostname', sudo=True)\nDEBUG:executor:Executing external command: sudo bash -c 'echo peter-macbook > /etc/hostname'\n\nRunning remote commands\n+++++++++++++++++++++++\n\nTo run a command on a remote system using SSH_ you can use the RemoteCommand_\nclass, it works as follows:\n\n>>> from executor.ssh.client import RemoteCommand\n>>> cmd = RemoteCommand('localhost', 'echo $SSH_CONNECTION', capture=True)\n>>> cmd.start()\n>>> cmd.output\n'127.0.0.1 57255 127.0.0.1 22'\n\nRunning remote commands concurrently\n++++++++++++++++++++++++++++++++++++\n\nThe `foreach()`_ function wraps the RemoteCommand_ and CommandPool_ classes to\nmake it very easy to run a remote command concurrently on a group of hosts:\n\n>>> from executor.ssh.client import foreach\n>>> from pprint import pprint\n>>> hosts = ['127.0.0.1', '127.0.0.2', '127.0.0.3', '127.0.0.4']\n>>> commands = foreach(hosts, 'echo $SSH_CONNECTION')\n>>> pprint([cmd.output for cmd in commands])\n['127.0.0.1 57278 127.0.0.1 22',\n '127.0.0.1 52385 127.0.0.2 22',\n '127.0.0.1 49228 127.0.0.3 22',\n '127.0.0.1 40628 127.0.0.4 22']\n\nContact\n-------\n\nThe latest version of `executor` is available on PyPI_ and GitHub_. The\ndocumentation is hosted on `Read the Docs`_ and includes a changelog_. For bug\nreports please create an issue on GitHub_. If you have questions, suggestions,\netc. feel free to send me an e-mail at `peter@peterodding.com`_.\n\nLicense\n-------\n\nThis software is licensed under the `MIT license`_.\n\n\u00a9 2018 Peter Odding.\n\n.. External references:\n.. _changelog: https://executor.readthedocs.io/en/latest/changelog.html\n.. _chroots: http://en.wikipedia.org/wiki/Chroot\n.. _CommandPool: https://executor.readthedocs.io/en/latest/api.html#executor.concurrent.CommandPool\n.. _documentation: https://executor.readthedocs.io\n.. _execute(): http://executor.readthedocs.io/en/latest/api.html#executor.execute\n.. _ExternalCommandFailed: http://executor.readthedocs.io/en/latest/api.html#executor.ExternalCommandFailed\n.. _foreach(): https://executor.readthedocs.io/en/latest/api.html#executor.ssh.client.foreach\n.. _GitHub: https://github.com/xolox/python-executor\n.. _MIT license: http://en.wikipedia.org/wiki/MIT_License\n.. _per user site-packages directory: https://www.python.org/dev/peps/pep-0370/\n.. _peter@peterodding.com: peter@peterodding.com\n.. _PyPI: https://pypi.python.org/pypi/executor\n.. _Read the Docs: https://executor.readthedocs.io/en/latest/api.html#api-documentation\n.. _RemoteCommand: https://executor.readthedocs.io/en/latest/api.html#executor.ssh.client.RemoteCommand\n.. _schroot: https://wiki.debian.org/Schroot\n.. _SSH: https://en.wikipedia.org/wiki/Secure_Shell\n.. _subprocess: https://docs.python.org/2/library/subprocess.html\n.. _virtual environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://executor.readthedocs.io", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "metabolexecutor", "package_url": "https://pypi.org/project/metabolexecutor/", "platform": "", "project_url": "https://pypi.org/project/metabolexecutor/", "project_urls": { "Homepage": "https://executor.readthedocs.io" }, "release_url": "https://pypi.org/project/metabolexecutor/20.0.post1/", "requires_dist": null, "requires_python": "", "summary": "Programmer friendly subprocess wrapper", "version": "20.0.post1" }, "last_serial": 4259177, "releases": { "20.0.post1": [ { "comment_text": "", "digests": { "md5": "a637143a40847007eae94a4fe6160a89", "sha256": "95caceae4a64703b4dce97ed9f2e8cc499ed78a094a9629443ea64e56a0a4e7e" }, "downloads": -1, "filename": "metabolexecutor-20.0.post1.tar.gz", "has_sig": false, "md5_digest": "a637143a40847007eae94a4fe6160a89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 88499, "upload_time": "2018-09-10T21:34:09", "url": "https://files.pythonhosted.org/packages/f9/66/97e7aa113efa1ff2bf89365709ca71c2a18ee13c306f2a0168573a75a9cb/metabolexecutor-20.0.post1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a637143a40847007eae94a4fe6160a89", "sha256": "95caceae4a64703b4dce97ed9f2e8cc499ed78a094a9629443ea64e56a0a4e7e" }, "downloads": -1, "filename": "metabolexecutor-20.0.post1.tar.gz", "has_sig": false, "md5_digest": "a637143a40847007eae94a4fe6160a89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 88499, "upload_time": "2018-09-10T21:34:09", "url": "https://files.pythonhosted.org/packages/f9/66/97e7aa113efa1ff2bf89365709ca71c2a18ee13c306f2a0168573a75a9cb/metabolexecutor-20.0.post1.tar.gz" } ] }