delegator.py


Namedelegator.py JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/kennethreitz/delegator
SummarySubprocesses for Humans 2.0.
upload_time2018-09-17 19:45:41
maintainer
docs_urlNone
authorKenneth Reitz
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
Delegator.py — Subprocesses for Humans 2.0
=======================================


.. image:: https://img.shields.io/pypi/v/delegator.py.svg
    :target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/pypi/l/delegator.py.svg
    :target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/pypi/wheel/delegator.py.svg
    :target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/pypi/pyversions/delegator.py.svg
    :target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/badge/SayThanks.io-☼-1EAEDB.svg
    :target: https://saythanks.io/to/kennethreitz


**Delegator.py** is a simple library for dealing with subprocesses, inspired
by both `envoy <https://github.com/kennethreitz/envoy>`_ and `pexpect <http://pexpect.readthedocs.io>`_ (in fact, it depends on it!).

This module features two main functions ``delegator.run()`` and ``delegator.chain()``. One runs commands, blocking or non-blocking, and the other runs a chain of commands, separated by the standard unix pipe operator: ``|``.

If you're interested in financially supporting Kenneth Reitz open source, consider `visiting this link <https://cash.me/$KennethReitz>`_. Your support helps tremendously with sustainability of motivation, as Open Source is no longer part of my day job.

Basic Usage
-----------

Basic run functionality:

.. code:: pycon

    >>> c = delegator.run('ls')
    >>> print c.out
    README.rst   delegator.py

    >>> c = delegator.run('long-running-process', block=False)
    >>> c.pid
    35199
    >>> c.block()
    >>> c.return_code
    0

Commands can be passed in as lists as well (e.g. ``['ls', '-lrt']``), for parameterization.

Basic chain functionality:

.. code:: pycon

   # Can also be called with ([['fortune'], ['cowsay']]).
   # or, delegator.run('fortune').pipe('cowsay')

   >>> c = delegator.chain('fortune | cowsay')
   >>> print c.out
     _______________________________________
    / Our swords shall play the orators for \
    | us.                                   |
    |                                       |
    \ -- Christopher Marlowe                /
     ---------------------------------------
            \   ^__^
             \  (oo)\_______
                (__)\       )\/\
                    ||----w |
                    ||     ||


Expect functionality is built-in too, on non-blocking commands:

.. code:: pycon

    >>> c.expect('Password:')
    >>> c.send('PASSWORD')
    >>> c.block()

Other functions:

.. code:: pycon

    >>> c.kill()
    >>> c.send('SIGTERM', signal=True)

    # Only available when block=True, otherwise, use c.out.
    >>> c.err
    ''

    # Direct access to pipes.
    >>> c.std_err
    <open file '<fdopen>', mode 'rU' at 0x10a5351e0>

    # Adjust environment variables for the command (existing will be overwritten).
    >>> c = delegator.chain('env | grep NEWENV', env={'NEWENV': 'FOO_BAR'})
    >>> c.out
    NEWENV=FOO_BAR



Installation
------------

::

    $ pip install delegator.py

✨🍰✨



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kennethreitz/delegator",
    "name": "delegator.py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Kenneth Reitz",
    "author_email": "me@kennethreitz.com",
    "download_url": "https://files.pythonhosted.org/packages/08/29/199c7e8efd277eb00d842cb735c65f1d3d1c070e4903b0e44b30ca8e2604/delegator.py-0.1.1.tar.gz",
    "platform": "",
    "description": "\nDelegator.py \u2014\u00a0Subprocesses for Humans 2.0\n=======================================\n\n\n.. image:: https://img.shields.io/pypi/v/delegator.py.svg\n    :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/pypi/l/delegator.py.svg\n    :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/pypi/wheel/delegator.py.svg\n    :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/pypi/pyversions/delegator.py.svg\n    :target: https://pypi.python.org/pypi/delegator.py\n\n.. image:: https://img.shields.io/badge/SayThanks.io-\u263c-1EAEDB.svg\n    :target: https://saythanks.io/to/kennethreitz\n\n\n**Delegator.py** is a simple library for dealing with subprocesses, inspired\nby both `envoy <https://github.com/kennethreitz/envoy>`_ and `pexpect <http://pexpect.readthedocs.io>`_ (in fact, it depends on it!).\n\nThis module features two main functions ``delegator.run()`` and ``delegator.chain()``. One runs commands, blocking or non-blocking, and the other runs a chain of commands, separated by the standard unix pipe operator: ``|``.\n\nIf you're interested in financially supporting Kenneth Reitz open source, consider `visiting this link <https://cash.me/$KennethReitz>`_. Your support helps tremendously with sustainability of motivation, as Open Source is no longer part of my day job.\n\nBasic Usage\n-----------\n\nBasic run functionality:\n\n.. code:: pycon\n\n    >>> c = delegator.run('ls')\n    >>> print c.out\n    README.rst   delegator.py\n\n    >>> c = delegator.run('long-running-process', block=False)\n    >>> c.pid\n    35199\n    >>> c.block()\n    >>> c.return_code\n    0\n\nCommands can be passed in as lists as well (e.g. ``['ls', '-lrt']``), for parameterization.\n\nBasic chain functionality:\n\n.. code:: pycon\n\n   # Can also be called with ([['fortune'], ['cowsay']]).\n   # or, delegator.run('fortune').pipe('cowsay')\n\n   >>> c = delegator.chain('fortune | cowsay')\n   >>> print c.out\n     _______________________________________\n    / Our swords shall play the orators for \\\n    | us.                                   |\n    |                                       |\n    \\ -- Christopher Marlowe                /\n     ---------------------------------------\n            \\   ^__^\n             \\  (oo)\\_______\n                (__)\\       )\\/\\\n                    ||----w |\n                    ||     ||\n\n\nExpect functionality is built-in too, on non-blocking commands:\n\n.. code:: pycon\n\n    >>> c.expect('Password:')\n    >>> c.send('PASSWORD')\n    >>> c.block()\n\nOther functions:\n\n.. code:: pycon\n\n    >>> c.kill()\n    >>> c.send('SIGTERM', signal=True)\n\n    # Only available when block=True, otherwise, use c.out.\n    >>> c.err\n    ''\n\n    # Direct access to pipes.\n    >>> c.std_err\n    <open file '<fdopen>', mode 'rU' at 0x10a5351e0>\n\n    # Adjust environment variables for the command (existing will be overwritten).\n    >>> c = delegator.chain('env | grep NEWENV', env={'NEWENV': 'FOO_BAR'})\n    >>> c.out\n    NEWENV=FOO_BAR\n\n\n\nInstallation\n------------\n\n::\n\n    $ pip install delegator.py\n\n\u2728\ud83c\udf70\u2728\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Subprocesses for Humans 2.0.",
    "version": "0.1.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7c22860c52ef858c4672b6cf637f473e9139342cdb281135db9b3c32cfb0a85",
                "md5": "f34dd6b1611f180148f73512d6175781",
                "sha256": "814657d96b98a244c479e3d5f6e9e850ac333e85f807d6bc846e72bbb2537806"
            },
            "downloads": -1,
            "filename": "delegator.py-0.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f34dd6b1611f180148f73512d6175781",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 5036,
            "upload_time": "2018-09-17T19:45:40",
            "upload_time_iso_8601": "2018-09-17T19:45:40.241660Z",
            "url": "https://files.pythonhosted.org/packages/a7/c2/2860c52ef858c4672b6cf637f473e9139342cdb281135db9b3c32cfb0a85/delegator.py-0.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0829199c7e8efd277eb00d842cb735c65f1d3d1c070e4903b0e44b30ca8e2604",
                "md5": "f7a1e8cf9cd78bddb4e6607d763b38a5",
                "sha256": "e6cc9cedab9ae59b169ee0422e17231adedadb144e63c0b5a60e6ff8adf8521b"
            },
            "downloads": -1,
            "filename": "delegator.py-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f7a1e8cf9cd78bddb4e6607d763b38a5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6260,
            "upload_time": "2018-09-17T19:45:41",
            "upload_time_iso_8601": "2018-09-17T19:45:41.641875Z",
            "url": "https://files.pythonhosted.org/packages/08/29/199c7e8efd277eb00d842cb735c65f1d3d1c070e4903b0e44b30ca8e2604/delegator.py-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2018-09-17 19:45:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "kennethreitz",
    "github_project": "delegator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "delegator.py"
}
        
Elapsed time: 0.03952s