HWRF
trunk@4391
|
Represents a single stage of a pipeline to execute. More...
Represents a single stage of a pipeline to execute.
This is a linked list class used to store information about a program or pipeline of programs to be run. It has the capability of converting itself to a Pipeline object (run(Runner)), or converting itself to a POSIX sh command (Runner.to_shell()). Note that some commands cannot be represented in POSIX sh, such as commands with non-ASCII characters or commands that have Python streams as their stdout or stdin. Those commands can still be run with a Pipeline, but trying to convert them to a POSIX sh command will throw NotValidPosixSh or a subclass thereof.
Public Member Functions | |
def | __init__ (self, args, kwargs) |
Creates a new Runner. More... | |
def | getthreads (self) |
Returns the number of threads requested by this program. More... | |
def | setthreads (self, nthreads) |
Sets the number of threads requested by this program. More... | |
def | delthreads (self) |
Removes the request for threads. More... | |
def | first (self) |
Returns the first Runner in this pipeline. More... | |
def | prerun (self, arg) |
Adds a function or callable object to be called before running the program. More... | |
def | __getitem__ (self, args) |
Add one or more arguments to the executable. More... | |
def | __str__ (self) |
Alias for repr() | |
def | __repr__ (self) |
Attempts to produce valid Python code to represent this Runnable. More... | |
def | __eq__ (self, other) |
Returns True if the other object is a Runner that is equal to this one, and False otherwise. More... | |
def | isplainexe (self) |
Returns true if this is simply an executable with arguments (no redirection, no prerun objects, no environment modification, no piping), and False otherwise. More... | |
def | cd (self, dirpath) |
Requests that this process run in the specified directory. More... | |
def | __lt__ (self, stdin) |
Connects the given object to stdin, via inp(stdin,string=False). More... | |
def | __gt__ (self, stdout) |
Connects the given object to stdout, truncating it if it is a file. More... | |
def | __lshift__ (self, stdin) |
Sends the specified string into stdin. More... | |
def | __rshift__ (self, stdout) |
Appends stdout to the specified file. More... | |
def | __pos__ (self) |
Sends stderr to stdout. More... | |
def | __ge__ (self, outerr) |
Redirects stderr and stdout to the specified file, truncating it. More... | |
def | __or__ (self, other) |
Pipes this Runner to the other Runner. More... | |
def | argins (self, index, arg) |
Inserts the specified argument before the given index. More... | |
def | args (self) |
Iterates over the executable and arguments of this command. | |
def | copy |
Returns a deep copy of this object, almost. More... | |
def | copyenv (self) |
Instructs this command to duplicate the parent process environment (the default). More... | |
def | clearenv (self) |
Instructs this command to start with an empty environment except for certain critical variables without which most programs cannot run. More... | |
def | env (self, kwargs) |
Sets environment variables for this Runner. More... | |
def | to_shell (self) |
Returns a string that expresses this object as a POSIX sh shell command if possible, or raises a subclass of NotValidPosixSh if not. More... | |
def | runner (self) |
Returns self if self is modifiable, otherwise returns a modifiable copy of self. More... | |
def | pipeto (self, other) |
Specifies that this Runner will send its stdout to the other runner's stdin. More... | |
def | inp |
Specifies that the first Runner in this pipeline takes input from the given file or string specified by stdin. More... | |
def | out |
Specifies that this process sends output from its stdout stream to the given file or stream. More... | |
def | err2out (self) |
Sends stderr to stdout. More... | |
def | err |
Specifies that this process sends output from its stderr stream to the given file or stream. More... | |
def produtil.prog.Runner.__init__ | ( | self, | |
args, | |||
kwargs | |||
) |
Creates a new Runner.
The only non-keyword argument can be one of three things:
Many options can be set via keyword arguments:
args | the arguments to the program |
kwargs | other settings (see constructor description). |
def produtil.prog.Runner.__eq__ | ( | self, | |
other | |||
) |
def produtil.prog.Runner.__ge__ | ( | self, | |
outerr | |||
) |
def produtil.prog.Runner.__getitem__ | ( | self, | |
args | |||
) |
Add one or more arguments to the executable.
Can ONLY accept strings, ints, floats or iterables (tuple, list). Strings, ints and floats are sent to _stringify_args, and the result is added to the end of the list of arguments to the command to run. For iterables (tuple, list), adds all elements to the list of arguments, passing each through _stringify_args.
args | one or more arguments to add |
def produtil.prog.Runner.__gt__ | ( | self, | |
stdout | |||
) |
def produtil.prog.Runner.__lshift__ | ( | self, | |
stdin | |||
) |
def produtil.prog.Runner.__lt__ | ( | self, | |
stdin | |||
) |
def produtil.prog.Runner.__or__ | ( | self, | |
other | |||
) |
def produtil.prog.Runner.__pos__ | ( | self | ) |
def produtil.prog.Runner.__repr__ | ( | self | ) |
Attempts to produce valid Python code to represent this Runnable.
Generally, that can be done, unless an input string is too long, or a stream is connected to a Python object. In those cases, human-readable representations are given, which are not exactly Python code.
Definition at line 473 of file prog.py.
Referenced by produtil.prog.Runner.__str__().
def produtil.prog.Runner.__rshift__ | ( | self, | |
stdout | |||
) |
def produtil.prog.Runner.argins | ( | self, | |
index, | |||
arg | |||
) |
Inserts the specified argument before the given index.
This function is intended for internal use only. It is used to implement threading on Cray, where arguments relating to threading have to be added after the Runner is generated.
arg | a string argument to add |
index | the index to insert before |
def produtil.prog.Runner.cd | ( | self, | |
dirpath | |||
) |
Requests that this process run in the specified directory.
The directory must already exist before the program starts.
dirpath | the directory to cd into, which must already exist. |
Definition at line 532 of file prog.py.
Referenced by produtil.prog.Runner.__init__().
def produtil.prog.Runner.clearenv | ( | self | ) |
Instructs this command to start with an empty environment except for certain critical variables without which most programs cannot run.
(Retains PATH, USER, LOGNAME and HOME.)
Definition at line 636 of file prog.py.
Referenced by produtil.prog.Runner.__init__().
def produtil.prog.Runner.copy | ( | self, | |
typeobj = None |
|||
) |
Returns a deep copy of this object, almost.
If stdin, stdout or stderr are connected to streams instead of files or strings, then the streams are not copied. Instead, the exact same stream objects are connected to the same unit in the new Runner.
typeobj | the type of the new object or None for Runner. Do not set this unless you know what you're doing. |
Definition at line 602 of file prog.py.
Referenced by produtil.prog.ImmutableRunner.runner().
def produtil.prog.Runner.copyenv | ( | self | ) |
def produtil.prog.Runner.delthreads | ( | self | ) |
def produtil.prog.Runner.env | ( | self, | |
kwargs | |||
) |
def produtil.prog.Runner.err | ( | self, | |
stderr, | |||
append = False |
|||
) |
Specifies that this process sends output from its stderr stream to the given file or stream.
The stderr object must be a string filename, or a stream. If append=False, and the stderr is a filename, the file will be truncated, if append=True then it is appended. Raises MultipleStderr if the stderr location is already specified.
stderr | the stderr output file |
append | if True, append to the file otherwise truncate |
Definition at line 811 of file prog.py.
Referenced by produtil.prog.Runner.__init__().
def produtil.prog.Runner.err2out | ( | self | ) |
Sends stderr to stdout.
Definition at line 802 of file prog.py.
Referenced by produtil.prog.Runner.__ge__(), produtil.prog.Runner.__init__(), and produtil.prog.Runner.__pos__().
def produtil.prog.Runner.first | ( | self | ) |
def produtil.prog.Runner.getthreads | ( | self | ) |
def produtil.prog.Runner.inp | ( | self, | |
stdin, | |||
string = False |
|||
) |
Specifies that the first Runner in this pipeline takes input from the given file or string specified by stdin.
If string=True, then stdin is converted to a string via str(), otherwise it must be a filename or a stream. Raises MultipleStdin if the stdin source is already specified.
stdin | the input file or string |
string | if True, stdin is a string. Otherwise, it is a file. |
Definition at line 753 of file prog.py.
Referenced by produtil.prog.Runner.__lshift__(), produtil.prog.Runner.__lt__(), and produtil.prog.Runner.pipeto().
def produtil.prog.Runner.isplainexe | ( | self | ) |
def produtil.prog.Runner.out | ( | self, | |
stdout, | |||
append = False |
|||
) |
Specifies that this process sends output from its stdout stream to the given file or stream.
The stdout object must be a string filename, or a stream. If append=False, and the stdout is a filename, the file will be truncated, if append=True then it is appended. Raises MultipleStdout if the stdout location is already specified
stdout | the stdout file |
append | if True, append to the file, otherwise truncate |
Definition at line 780 of file prog.py.
Referenced by produtil.prog.Runner.__ge__(), produtil.prog.Runner.__gt__(), and produtil.prog.Runner.__rshift__().
def produtil.prog.Runner.pipeto | ( | self, | |
other | |||
) |
Specifies that this Runner will send its stdout to the other runner's stdin.
This will raise MultipleStdout if this Runner's stdout target is already specified, or MultipleStdin if the other's stdin is already specified.
other | the runner to pipe into |
Definition at line 721 of file prog.py.
Referenced by produtil.prog.Runner.__or__().
def produtil.prog.Runner.prerun | ( | self, | |
arg | |||
) |
Adds a function or callable object to be called before running the program.
The callables should be very fast operations, and are executed by self._gen when creating the Pipeline. They take, as an argument, the Runner and an optional "logger" keyword argument that is either None, or a logging.Logger to use to log messages.
arg | a callable object that takes self as an argument, and an optional keyword argument "logger" with a logging.Logger for log messages |
Definition at line 419 of file prog.py.
Referenced by produtil.prog.Runner.__init__(), and produtil.prog.Runner.err().
def produtil.prog.Runner.runner | ( | self | ) |
Returns self if self is modifiable, otherwise returns a modifiable copy of self.
This is intended to be used to implement unmodifiable subclasses of Runner
Definition at line 715 of file prog.py.
Referenced by produtil.prog.ImmutableRunner.argins(), produtil.prog.ImmutableRunner.pipeto(), and produtil.prog.ImmutableRunner.runner().
def produtil.prog.Runner.setthreads | ( | self, | |
nthreads | |||
) |
def produtil.prog.Runner.to_shell | ( | self | ) |
Returns a string that expresses this object as a POSIX sh shell command if possible, or raises a subclass of NotValidPosixSh if not.