Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

A library for simplified executing of system commands

Project Description

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:

  • dryRun : print what would be executed but don’t actually execute anything
  • 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)

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_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
Release History

Release History

This version
History Node

1.0.10

History Node

1.0.9

History Node

1.0.8

History Node

1.0.7

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
sysexecute-1.0.10.tar.gz (8.5 kB) Copy SHA256 Checksum SHA256 Source Dec 25, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting