Skip to main content

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

Metadata

Release files for sysexecute 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sysexecute 1.2.1
File Size Uploaded
sysexecute-1.2.1.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sysexecute 1.2.1
File Interpreter ABI Platform
sysexecute-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.2 kB

Release files / sysexecute-1.2.1.tar.gz

Download URL sysexecute-1.2.1.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5f472744fd1de755cf7685abc1b1b002821bf549e788f2079ce262731a0097de
BLAKE2b-256 checksum
How to use checksums
6aa69805c1f7bfb7c724914a4e9982a0ce08ada8429c03ceb473a262a19018f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / sysexecute-1.2.1-py3-none-any.whl

Download URL sysexecute-1.2.1-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64062b595079144c8a9c2e1688a3e054bf8e75714b40f678b77190c3fabc7fe8
BLAKE2b-256 checksum
How to use checksums
413f1f8e38e8187e98fa48c05dbfb4c53fe7303d1393236675561e5a4a75504e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page