easyproc


Nameeasyproc JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://github.com/ninjaaron/easyproc
Summarythin abstraction on subprocess.run to simplify admin scripts
upload_time2018-03-26 10:55:10
maintainer
docs_urlNone
authorAaron Christianson
requires_python
license
keywords shell pipe subprcess process scripting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            *easyproc* is based on the ``suprocess.run()`` function in Python 3.5 (a
fair amount of the code is copied directly from the module). It provides
basically the same interface, plus a couple of convenience features and
functions to simplify administrative scripting a bit. It addresses what
I perceive to be three shortcomings in the Popen API (in order of
egregiousness)

1. Input and output streams default to bytes. This is manifestly
   ridiculous in Python 3. easyproc turns on *universal_newlines*
   everywhere, so you don't have to worry about decoding bytes.
2. Piping a chain of processes together is not particularly intuitive
   and takes a lot of extra work when not using shell=True.
   ``easyproc.pipe()`` provides a simple way to pipe a chain of shell
   commands into each other without the safety risk of granting a shell.
   Admittedly, if one is piping together a lot of shell commands, one
   might wonder why bother with python at all? Or better, why not use
   native python filters? Certainly, that is the preferable option in
   situations were "shelling out" creates a performance bottle-neck, but
   there are times where the performance cost is small, and, in terms of
   development speed, shell utilities are often ideally suited to
   parsing the output of shell commands. Easy things should be easy,
   right?
3. While not particularly egregious, and sometimes even useful, it can
   be annoying to split each command argument into a separate list item.
   easyproc commands can be strings or lists. If it's a string, it's run
   through ``shlex.split()`` prior to being passed to
   ``subprocess.run()``.

Additionally, easyproc defaults to error checking. As per *The Zen of
Python*, "Errors should never pass silently -- unless explicitly
silenced." easyproc follows this logic.

*easyproc* does not replace all the functionality of the subprocess
module by a long shot, but it does try to expose much of it by passing
additional kwargs to ``subprocess.run()``, so many advanced use-cases
should be possible, and one need only refer to the documentation for the
subprocess module.

*easyproc* provides four simple functions for messing with shell
commands. ``easyproc.run()`` simply runs the command you give it through
``shlex.split()`` if it is a string, and then sends it to
``suprocess.run()`` with *universal_newlines* turned on, and all
additional kwargs passed along to Popen. As with ``subprocess.run()`` it
returns as ``CompletedProcess`` instance. The only difference is that
stdout and stderr attributes are ProcStream instances (see below)
instead of byte-strings. Note that the "timeout" parameters is broken in
python 2.

``easyproc.Popen()`` also turns on unicode and automatically splits
command strings, but it returns a Popen instance, in case you need to
interact with a running process (Note: the Popen object will require
explicit error checking because it represents a process in progress and
doesn't have a return code until additional methods are called on it).

``easyproc.grab()`` is like ``easyproc.run()``, but it captures the
stdout of the command without the bother of having to type
``stdout=easyproc.PIPE`` and ``.stdout``. The stream option, which
defaults to 1, choses whether to grab stdin (1), stdout (2) or both
together (1+2). (same as ``stderr=easyproc.STDIN``.) ``easyproc.grab()``
is also a bit lazy. The process isn't actually run until you try to do
something with the output.


``easyproc.pipe()`` takes any number of commands as args and pipes them
into each other in the order they are given. The output is captured as
with ``easyproc.grab()``, unless otherwise specified. if you plan on
passing a lot of subprocess.run/Popen parameters to easyproc.pipe, you
may want to look at the doc string to see what it will do.

*easyproc* also provides the three special variables from the subprocess
module, ``PIPE``, ``STDOUT``, and ``DEVNULL``, for those who know and
care what they do.

While the ``input`` parameter for easyproc functions is inherited
directly from ``suprocess.run()``, it may be useful for those avoiding
the subprocess docs to here note that this parameter is used to pass
text to the STDIN of a command (and doesn't require the use of
stdin=PIPE); i.e. it's like ``echo "text"|command``. In suprocess, the
text must be bytes by default. In easyproc, as with all other streams,
it ought to be a string.

All streams returned by functions in this module (i.e. stdout and
stderr), excluding Popen, are ``ProcOutput`` objects. These are
subclasses of ``str``, but they act like a tuple of (stripped) lines
when you do sequence operations on them, since most shell commands
produce output which is intended to be read line by line. Basically, the
whole reason this module exists is because I got tired of writing
``subprocess.check_output(['cmd', 'and',
'args']).decode().splitines()``. Now, I just write ``easyproc.grab('cmd
and args')``.



            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "keywords": "shell pipe subprcess process scripting", 
    "upload_time": "2018-03-26 10:55:10", 
    "author": "Aaron Christianson", 
    "home_page": "https://github.com/ninjaaron/easyproc", 
    "github_user": "ninjaaron", 
    "download_url": "https://pypi.python.org/packages/84/57/c1688e9ea7ed9a21b9f1ddff470e2b14f4e8ef58de2983169b9e555b9b8d/easyproc-0.5.1.tar.gz", 
    "platform": "", 
    "version": "0.5.1", 
    "cheesecake_documentation_id": null, 
    "description": "*easyproc* is based on the ``suprocess.run()`` function in Python 3.5 (a\nfair amount of the code is copied directly from the module). It provides\nbasically the same interface, plus a couple of convenience features and\nfunctions to simplify administrative scripting a bit. It addresses what\nI perceive to be three shortcomings in the Popen API (in order of\negregiousness)\n\n1. Input and output streams default to bytes. This is manifestly\n   ridiculous in Python 3. easyproc turns on *universal_newlines*\n   everywhere, so you don't have to worry about decoding bytes.\n2. Piping a chain of processes together is not particularly intuitive\n   and takes a lot of extra work when not using shell=True.\n   ``easyproc.pipe()`` provides a simple way to pipe a chain of shell\n   commands into each other without the safety risk of granting a shell.\n   Admittedly, if one is piping together a lot of shell commands, one\n   might wonder why bother with python at all? Or better, why not use\n   native python filters? Certainly, that is the preferable option in\n   situations were \"shelling out\" creates a performance bottle-neck, but\n   there are times where the performance cost is small, and, in terms of\n   development speed, shell utilities are often ideally suited to\n   parsing the output of shell commands. Easy things should be easy,\n   right?\n3. While not particularly egregious, and sometimes even useful, it can\n   be annoying to split each command argument into a separate list item.\n   easyproc commands can be strings or lists. If it's a string, it's run\n   through ``shlex.split()`` prior to being passed to\n   ``subprocess.run()``.\n\nAdditionally, easyproc defaults to error checking. As per *The Zen of\nPython*, \"Errors should never pass silently -- unless explicitly\nsilenced.\" easyproc follows this logic.\n\n*easyproc* does not replace all the functionality of the subprocess\nmodule by a long shot, but it does try to expose much of it by passing\nadditional kwargs to ``subprocess.run()``, so many advanced use-cases\nshould be possible, and one need only refer to the documentation for the\nsubprocess module.\n\n*easyproc* provides four simple functions for messing with shell\ncommands. ``easyproc.run()`` simply runs the command you give it through\n``shlex.split()`` if it is a string, and then sends it to\n``suprocess.run()`` with *universal_newlines* turned on, and all\nadditional kwargs passed along to Popen. As with ``subprocess.run()`` it\nreturns as ``CompletedProcess`` instance. The only difference is that\nstdout and stderr attributes are ProcStream instances (see below)\ninstead of byte-strings. Note that the \"timeout\" parameters is broken in\npython 2.\n\n``easyproc.Popen()`` also turns on unicode and automatically splits\ncommand strings, but it returns a Popen instance, in case you need to\ninteract with a running process (Note: the Popen object will require\nexplicit error checking because it represents a process in progress and\ndoesn't have a return code until additional methods are called on it).\n\n``easyproc.grab()`` is like ``easyproc.run()``, but it captures the\nstdout of the command without the bother of having to type\n``stdout=easyproc.PIPE`` and ``.stdout``. The stream option, which\ndefaults to 1, choses whether to grab stdin (1), stdout (2) or both\ntogether (1+2). (same as ``stderr=easyproc.STDIN``.) ``easyproc.grab()``\nis also a bit lazy. The process isn't actually run until you try to do\nsomething with the output.\n\n\n``easyproc.pipe()`` takes any number of commands as args and pipes them\ninto each other in the order they are given. The output is captured as\nwith ``easyproc.grab()``, unless otherwise specified. if you plan on\npassing a lot of subprocess.run/Popen parameters to easyproc.pipe, you\nmay want to look at the doc string to see what it will do.\n\n*easyproc* also provides the three special variables from the subprocess\nmodule, ``PIPE``, ``STDOUT``, and ``DEVNULL``, for those who know and\ncare what they do.\n\nWhile the ``input`` parameter for easyproc functions is inherited\ndirectly from ``suprocess.run()``, it may be useful for those avoiding\nthe subprocess docs to here note that this parameter is used to pass\ntext to the STDIN of a command (and doesn't require the use of\nstdin=PIPE); i.e. it's like ``echo \"text\"|command``. In suprocess, the\ntext must be bytes by default. In easyproc, as with all other streams,\nit ought to be a string.\n\nAll streams returned by functions in this module (i.e. stdout and\nstderr), excluding Popen, are ``ProcOutput`` objects. These are\nsubclasses of ``str``, but they act like a tuple of (stripped) lines\nwhen you do sequence operations on them, since most shell commands\nproduce output which is intended to be read line by line. Basically, the\nwhole reason this module exists is because I got tired of writing\n``subprocess.check_output(['cmd', 'and',\n'args']).decode().splitines()``. Now, I just write ``easyproc.grab('cmd\nand args')``.\n\n\n", 
    "lcname": "easyproc", 
    "bugtrack_url": "", 
    "github": true, 
    "coveralls": false, 
    "name": "easyproc", 
    "license": "", 
    "travis_ci": false, 
    "github_project": "easyproc", 
    "summary": "thin abstraction on subprocess.run to simplify admin scripts", 
    "split_keywords": [
        "shell", 
        "pipe", 
        "subprcess", 
        "process", 
        "scripting"
    ], 
    "author_email": "ninjaaron@gmail.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2018-03-26T10:55:09", 
            "comment_text": "", 
            "python_version": "py3", 
            "url": "https://pypi.python.org/packages/a6/e1/2b27a8540c9bebf146b124760046e8b3649e2e19dc030b47b0a532d5f159/easyproc-0.5.1-py3-none-any.whl", 
            "md5_digest": "017c35d1da888a72eeb6e3bb88906d8d", 
            "downloads": 0, 
            "filename": "easyproc-0.5.1-py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "a6/e1/2b27a8540c9bebf146b124760046e8b3649e2e19dc030b47b0a532d5f159/easyproc-0.5.1-py3-none-any.whl", 
            "digests": {
                "sha256": "8131ff1d607ca028b6a04c52c40ac69f69dffc6c85dfa4e5f1d707517cf04ae2", 
                "md5": "017c35d1da888a72eeb6e3bb88906d8d"
            }, 
            "sha256_digest": "8131ff1d607ca028b6a04c52c40ac69f69dffc6c85dfa4e5f1d707517cf04ae2", 
            "size": 9561
        }, 
        {
            "has_sig": false, 
            "upload_time": "2018-03-26T10:55:10", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/84/57/c1688e9ea7ed9a21b9f1ddff470e2b14f4e8ef58de2983169b9e555b9b8d/easyproc-0.5.1.tar.gz", 
            "md5_digest": "0962681bbdc21bd1619d300fd26ce464", 
            "downloads": 0, 
            "filename": "easyproc-0.5.1.tar.gz", 
            "packagetype": "sdist", 
            "path": "84/57/c1688e9ea7ed9a21b9f1ddff470e2b14f4e8ef58de2983169b9e555b9b8d/easyproc-0.5.1.tar.gz", 
            "digests": {
                "sha256": "8b6daac6731abe71ccfbe1dffcc3734b07259819efd46ef1afde956450c2b483", 
                "md5": "0962681bbdc21bd1619d300fd26ce464"
            }, 
            "sha256_digest": "8b6daac6731abe71ccfbe1dffcc3734b07259819efd46ef1afde956450c2b483", 
            "size": 6396
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}