sysexecute


Namesysexecute JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://github.com/jasonfharris/sysexecute
SummaryA library for simplified executing of system commands
upload_time2023-05-06 09:54:06
maintainer
docs_urlNone
authorJason Harris
requires_python
licenseMIT
keywords execute shell system
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Purpose

The sysexecute python package allows the easier execution of system tasks. Part of this is an auto-formatting mechanism for variable substitution, part of this is being able to simply specify the execution options.

## Installation

You can install `sysexecute` from PyPi via pip:

```
pip install sysexecute
```

## Variable Substitution

Typically in python to format a string we might do something like:

```
val = 3
print("the value of val is {val}".format(val=val))
```

This is kind of long and redundant. If we already have a value for `val` then it should be able to just be substituted. In fact if we do

```
from sysexecute import *
val = 3
print (stringWithVars("the value of val is {val}"))
```

The bindings for the variables follow normal python scoping rules. This makes the execution statements a good bit more readable.

## Execution

Here is a typical execution

```
execute("ssh {machineIP} ls {thePath}")
```
assuming the variable `machineIP` and `thePath` have values. The normal output of this script gets piped to StdOut and StdErr, but if you want to capture these you can with something like:

```
(rc, stdout, stderr) = execute("ssh {machineIP} ls {thePath}", captureStdOutStdErr=True)
```

There are various keyword options you can specify like:

- `cwd` : change the directory from which the command will be executed
- `ignoreErrors`: Unless this is true a `sys.exit(returnCode)` will be issued if there is a non-zero return code.
- `shell`: if a shell should be used (defaults to `True`)
- `executable`: which shell to use (defaults to `/bin/bash`)
- `colorize`: wether to colorize the output (defaults to `True`)
- `dryRun` : print what would be executed but don't actually execute anything

## Verbosity

Often in scripting we want to include debugging / info commentary depending on what level of verbosity we are requested to display. You can set the level of verbosity shown via eg:

```
set_execute_defaults('verbosity',2)
```

Then in the following only the first two strings would be printed:

```
printWithVars1("success!")
printWithVars2("Machine {machineIP} was reached.")
printWithVars3("You might want to check that blah and blah.")
```


## Testing

To run the test suite you need `py.test` installed on your machine. Then you can simply execute:

```
cd tests
py.test
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jasonfharris/sysexecute",
    "name": "sysexecute",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "execute,shell,system",
    "author": "Jason Harris",
    "author_email": "jason@jasonfharris.com",
    "download_url": "https://files.pythonhosted.org/packages/6a/a6/9805c1f7bfb7c724914a4e9982a0ce08ada8429c03ceb473a262a19018f4/sysexecute-1.2.1.tar.gz",
    "platform": null,
    "description": "## Purpose\n\nThe sysexecute python package allows the easier execution of system tasks. Part of this is an auto-formatting mechanism for variable substitution, part of this is being able to simply specify the execution options.\n\n## Installation\n\nYou can install `sysexecute` from PyPi via pip:\n\n```\npip install sysexecute\n```\n\n## Variable Substitution\n\nTypically in python to format a string we might do something like:\n\n```\nval = 3\nprint(\"the value of val is {val}\".format(val=val))\n```\n\nThis is kind of long and redundant. If we already have a value for `val` then it should be able to just be substituted. In fact if we do\n\n```\nfrom sysexecute import *\nval = 3\nprint (stringWithVars(\"the value of val is {val}\"))\n```\n\nThe bindings for the variables follow normal python scoping rules. This makes the execution statements a good bit more readable.\n\n## Execution\n\nHere is a typical execution\n\n```\nexecute(\"ssh {machineIP} ls {thePath}\")\n```\nassuming the variable `machineIP` and `thePath` have values. The normal output of this script gets piped to StdOut and StdErr, but if you want to capture these you can with something like:\n\n```\n(rc, stdout, stderr) = execute(\"ssh {machineIP} ls {thePath}\", captureStdOutStdErr=True)\n```\n\nThere are various keyword options you can specify like:\n\n- `cwd` : change the directory from which the command will be executed\n- `ignoreErrors`: Unless this is true a `sys.exit(returnCode)` will be issued if there is a non-zero return code.\n- `shell`: if a shell should be used (defaults to `True`)\n- `executable`: which shell to use (defaults to `/bin/bash`)\n- `colorize`: wether to colorize the output (defaults to `True`)\n- `dryRun` : print what would be executed but don't actually execute anything\n\n## Verbosity\n\nOften in scripting we want to include debugging / info commentary depending on what level of verbosity we are requested to display. You can set the level of verbosity shown via eg:\n\n```\nset_execute_defaults('verbosity',2)\n```\n\nThen in the following only the first two strings would be printed:\n\n```\nprintWithVars1(\"success!\")\nprintWithVars2(\"Machine {machineIP} was reached.\")\nprintWithVars3(\"You might want to check that blah and blah.\")\n```\n\n\n## Testing\n\nTo run the test suite you need `py.test` installed on your machine. Then you can simply execute:\n\n```\ncd tests\npy.test\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library for simplified executing of system commands",
    "version": "1.2.1",
    "project_urls": {
        "Download": "https://github.com/jasonfharris/sysexecute/tarball/1.2.1",
        "Homepage": "https://github.com/jasonfharris/sysexecute"
    },
    "split_keywords": [
        "execute",
        "shell",
        "system"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "413f1f8e38e8187e98fa48c05dbfb4c53fe7303d1393236675561e5a4a75504e",
                "md5": "4f94559869e8ab0f6c8a76e7242594a3",
                "sha256": "64062b595079144c8a9c2e1688a3e054bf8e75714b40f678b77190c3fabc7fe8"
            },
            "downloads": -1,
            "filename": "sysexecute-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f94559869e8ab0f6c8a76e7242594a3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10248,
            "upload_time": "2023-05-06T09:54:01",
            "upload_time_iso_8601": "2023-05-06T09:54:01.629936Z",
            "url": "https://files.pythonhosted.org/packages/41/3f/1f8e38e8187e98fa48c05dbfb4c53fe7303d1393236675561e5a4a75504e/sysexecute-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6aa69805c1f7bfb7c724914a4e9982a0ce08ada8429c03ceb473a262a19018f4",
                "md5": "1ec976b554ffde385f5ae4bc89d9aa2f",
                "sha256": "5f472744fd1de755cf7685abc1b1b002821bf549e788f2079ce262731a0097de"
            },
            "downloads": -1,
            "filename": "sysexecute-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1ec976b554ffde385f5ae4bc89d9aa2f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10905,
            "upload_time": "2023-05-06T09:54:06",
            "upload_time_iso_8601": "2023-05-06T09:54:06.737462Z",
            "url": "https://files.pythonhosted.org/packages/6a/a6/9805c1f7bfb7c724914a4e9982a0ce08ada8429c03ceb473a262a19018f4/sysexecute-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-06 09:54:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jasonfharris",
    "github_project": "sysexecute",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "sysexecute"
}
        
Elapsed time: 0.06386s