# Runner [![Build Status](https://travis-ci.org/aragaer/runner.svg?branch=master)](https://travis-ci.org/aragaer/runner) [![codecov](https://codecov.io/gh/aragaer/runner/branch/master/graph/badge.svg)](https://codecov.io/gh/aragaer/runner) [![donate using paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=aragaer@gmail.com&lc=RU&item_name=RUNNER¤cy_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHosted)
Simple wrapper around subprocess.Popen.
Multiple commands can be configured to be executed. Each command can
have some predetermined parameters and additional parameters or
overrides can be passed when application is executed. Multiple
instances of one application can be running using aliases.
To communicate to running processes Channel classes from
[yet-another-io-channels-library](https://github.com/aragaer/channels)
are used.
Examples:
Using STDIO.
runner = Runner()
runner.add("cat", "cat")
runner.start('cat')
channel = runner.get_channel('cat')
channel.write(b'hello, world')
# later
line = channel.read() # Will return b'hello, world'
Using UNIX socket.
runner = Runner()
self._runner.add("socat", "socat SYSTEM:cat UNIX-LISTEN:socket",
type="socket", socket="socket")
runner.start('socat')
channel = runner.get_channel('socat')
channel.write(b'hello, world')
# later
line = channel.read() # Will return b'hello, world'
## Classes
### Runner
`Runner(*, extra_paths=None)`
Create a new runner object.
- `extra_paths`: List of paths which will be appended to PATH environment variable
`add(self, name, command, **kwargs)`
Add the application to the list of registered applications or update
if already added.
- `name`: application name
- `command`: the command to be executed
`**kwargs` can include the following:
- `type`: either `stdio` or `socket`. Default is `stdio`
- `cwd`: working directory of the process
- `socket`: if type is `socket`, this is the name of the UNIX socket file to connect to
- `setpgrp`: if `True` the process is moved to a separate process group and will not receive signals sent to main process. Default is `False`
- `buffering`: if set to `"line"` the channel is line-buffered for reading
`update_config(self, config)`
Config must be a dictionary where each key is an alias of an
application and value is a dictionary of that application's
configuration. `runner.add("app", "command", **kwargs)` is equivalent
to `runner.update_config({"app": {"command": "command",
**kwargs}})`. Useful for adding multiple applications at once.
`ensure_running(self, app_name, alias=None, with_args=None, **kwargs)`
`start(self, app_name, alias=None, with_args=None, **kwargs)`
Start the process. If the process with the same alias is already
running, `start` will raise `ProcessExistsException`, while
`ensure_running` will silently do nothing.
- `app_name`: application alias, given in the configuration
- `alias`: alias that will be given to actual started process. If `None`, application alias will be used
- `with_args`: list of additional arguments that will be added to the command
- `kwargs`: extend or override parameters in application config
`get_channel(self, alias)`
Returns the `Channel` object to communicate to the running process.
`terminate(self, alias)`
Terminates the process.
Raw data
{
"_id": null,
"home_page": "https://github.com/aragaer/runner",
"name": "yet-another-runner",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "run command shell socket",
"author": "Ilya Konovalov",
"author_email": "aragaer@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b5/96/17597c793587b337bb86b1a6c4eb7a2cbca3c4d7a2d7f5c238ae2d064359/yet-another-runner-0.6.0.tar.gz",
"platform": null,
"description": "# Runner [![Build Status](https://travis-ci.org/aragaer/runner.svg?branch=master)](https://travis-ci.org/aragaer/runner) [![codecov](https://codecov.io/gh/aragaer/runner/branch/master/graph/badge.svg)](https://codecov.io/gh/aragaer/runner) [![donate using paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=aragaer@gmail.com&lc=RU&item_name=RUNNER¤cy_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHosted)\n\nSimple wrapper around subprocess.Popen.\n\nMultiple commands can be configured to be executed. Each command can\nhave some predetermined parameters and additional parameters or\noverrides can be passed when application is executed. Multiple\ninstances of one application can be running using aliases.\n\nTo communicate to running processes Channel classes from\n[yet-another-io-channels-library](https://github.com/aragaer/channels)\nare used.\n\nExamples:\n\nUsing STDIO.\n\n runner = Runner()\n runner.add(\"cat\", \"cat\")\n runner.start('cat')\n channel = runner.get_channel('cat')\n channel.write(b'hello, world')\n\t# later\n\tline = channel.read() # Will return b'hello, world'\n\nUsing UNIX socket.\n\n runner = Runner()\n self._runner.add(\"socat\", \"socat SYSTEM:cat UNIX-LISTEN:socket\",\n\t type=\"socket\", socket=\"socket\")\n runner.start('socat')\n channel = runner.get_channel('socat')\n channel.write(b'hello, world')\n\t# later\n\tline = channel.read() # Will return b'hello, world'\n\n## Classes\n\n### Runner\n\n`Runner(*, extra_paths=None)`\n\nCreate a new runner object.\n\n- `extra_paths`: List of paths which will be appended to PATH environment variable\n\n`add(self, name, command, **kwargs)`\n\nAdd the application to the list of registered applications or update\nif already added.\n\n- `name`: application name\n- `command`: the command to be executed\n\n`**kwargs` can include the following:\n\n- `type`: either `stdio` or `socket`. Default is `stdio`\n- `cwd`: working directory of the process\n- `socket`: if type is `socket`, this is the name of the UNIX socket file to connect to\n- `setpgrp`: if `True` the process is moved to a separate process group and will not receive signals sent to main process. Default is `False`\n- `buffering`: if set to `\"line\"` the channel is line-buffered for reading\n\n`update_config(self, config)`\n\nConfig must be a dictionary where each key is an alias of an\napplication and value is a dictionary of that application's\nconfiguration. `runner.add(\"app\", \"command\", **kwargs)` is equivalent\nto `runner.update_config({\"app\": {\"command\": \"command\",\n**kwargs}})`. Useful for adding multiple applications at once.\n\n`ensure_running(self, app_name, alias=None, with_args=None, **kwargs)`\n\n`start(self, app_name, alias=None, with_args=None, **kwargs)`\n\nStart the process. If the process with the same alias is already\nrunning, `start` will raise `ProcessExistsException`, while\n`ensure_running` will silently do nothing.\n\n- `app_name`: application alias, given in the configuration\n- `alias`: alias that will be given to actual started process. If `None`, application alias will be used\n- `with_args`: list of additional arguments that will be added to the command\n- `kwargs`: extend or override parameters in application config\n\n`get_channel(self, alias)`\n\nReturns the `Channel` object to communicate to the running process.\n\n`terminate(self, alias)`\n\nTerminates the process.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple process runner",
"version": "0.6.0",
"project_urls": {
"Homepage": "https://github.com/aragaer/runner"
},
"split_keywords": [
"run",
"command",
"shell",
"socket"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b59617597c793587b337bb86b1a6c4eb7a2cbca3c4d7a2d7f5c238ae2d064359",
"md5": "6c44d0a32f94483e5753a120464f2939",
"sha256": "0b3477b47525a8c8dd37d4e1e1199df464c3c875958094c80f009b0e6dcbc87f"
},
"downloads": -1,
"filename": "yet-another-runner-0.6.0.tar.gz",
"has_sig": false,
"md5_digest": "6c44d0a32f94483e5753a120464f2939",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7998,
"upload_time": "2023-07-16T23:51:38",
"upload_time_iso_8601": "2023-07-16T23:51:38.751694Z",
"url": "https://files.pythonhosted.org/packages/b5/96/17597c793587b337bb86b1a6c4eb7a2cbca3c4d7a2d7f5c238ae2d064359/yet-another-runner-0.6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-16 23:51:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aragaer",
"github_project": "runner",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "yet-another-io-channels-library",
"specs": [
[
">=",
"0.2.0"
]
]
}
],
"lcname": "yet-another-runner"
}