Welcome to CmdFlow’s documentation!

A simple wrapper for creating shell pipelines inside python scripts

Theoretically, this can be used across platforms, but there are a few conventions which do not translate well to Windows; i.e. sudo is difficult in a system that does not use multiple simultaneous users.

cmdflow

Collection of classes making up cmdflow. The main interface is ShellCmd.

To build a pipeline:

>>> pipeline = ShellCmd("echo 'foo'") | ShellCmd("grep 'f'")
>>> print pipeline
foo
class cmdflow.Path(pathname)

Provides some methods for building paths. A nice feature is the ability to combine additional Path objects and/or strings to build a final path. Joining modifies the original Path. For example:

Path("/usr/local") / "bin" / "foo"
__init__(pathname)

Initialize a Path object:

Path("/usr/local/")
Parameters:pathname (string) – named path

Remove the path from the Filesystem

class cmdflow.ShellOutput

Manager of output from an executed cmdflow pipeline. Currently this can only redirect from the ShellCmd‘s stdnout to a file.

redirect(path_out)
Parameters:path_out – filesystem path to direct into
class cmdflow.ShellCmd(cmd, env=None)

This is a wrapper on Popen to help make building pipelines of commands easier. The convenience syntax of ‘|’ is reminiscent of regular shell semantics but it is a bit different. In this case you must explicitly call the resulting object

__init__(cmd, env=None)

Initialize a ShellCmd:

ShellCmd("echo 'hello'")
Parameters:
  • cmds – commands to run
  • env (dict) – environment in which to run commands
pipe(b)

Allows ShellCmd objects to feed input into each other in a style similar to shell pipelines

Parameters:b (ShellCmd) – command to append to ShellCmd.cmds
run(stdin=())

Being running ShellCmd pipeline

Parameters:stdin (str or ShellCmd) – Passed into stdin in Popen‘s initializer
Return type:ShellOutput

Indices and tables

Project Versions

Table Of Contents

This Page