Package gromacs :: Module core :: Class Command
[hide private]
[frames] | no frames]

Class Command

source code

object --+
         |
        Command
Known Subclasses:

Wrap simple script or command.
Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
Set up the command class.
source code
 
run(self, *args, **kwargs)
Run the command; args/kwargs are added or replace the ones given to the constructor.
source code
 
_combine_arglist(self, args, kwargs)
Combine the default values and the supplied values.
source code
 
_run_command(self, *args, **kwargs)
Execute the command; see the docs for __call__.
source code
 
_commandline(self, *args, **kwargs)
Returns the command line (without pipes) as a list.
source code
 
commandline(self, *args, **kwargs)
Returns the commandline that run() uses (without pipes).
source code
 
Popen(self, *args, **kwargs)
Returns a special Popen instance (:class:`PopenWithInput`).
source code
 
transform_args(self, *args, **kwargs)
Transform arguments and return them as a list suitable for Popen.
source code
 
help(self, long=False)
Print help; same as using ? in ipython.
source code
 
__call__(self, *args, **kwargs)
Run command with the given arguments::
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  command_name = None
Derive a class from command; typically one only has to set *command_name* to the name of the script or executable.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

Set up the command class.

The arguments can always be provided as standard positional arguments such as

"-c", "config.conf", "-o", "output.dat", "--repeats=3", "-v", "input.dat"

In addition one can also use keyword arguments such as

c="config.conf", o="output.dat", repeats=3, v=True

These are automatically transformed appropriately according to simple rules:

  • Any single-character keywords are assumed to be POSIX-style options and will be prefixed with a single dash and the value separated by a space.
  • Any other keyword is assumed to be a GNU-style long option and thus will be prefixed with two dashes and the value will be joined directly with an equals sign and no space.

If this does not work (as for instance for the options of the UNIX find command) then provide options and values in the sequence of positional arguments.

Overrides: object.__init__

Popen(self, *args, **kwargs)

source code 
Returns a special Popen instance (:class:`PopenWithInput`).

The instance has its input pre-set so that calls to
:meth:`~PopenWithInput.communicate` will not need to supply
input. This is necessary if one wants to chain the output from
one command to an input from another.

:TODO:
  Write example.

help(self, long=False)

source code 
Print help; same as using ? in ipython. long=True also gives call signature.

__call__(self, *args, **kwargs)
(Call operator)

source code 
Run command with the given arguments::

   rc,stdout,stderr = command(*args, input=None, **kwargs)
   
All positional parameters \*args and all gromacs \*\*kwargs are passed on
to the Gromacs command. input and output keywords allow communication
with the process via the python subprocess module.

:Arguments:
  *input* : string, sequence            
     to be fed to the process' standard input;
     elements of a sequence are concatenated with
     newlines, including a trailing one    [``None``]
  *stdin*
     ``None`` or automatically set to ``PIPE`` if input given [``None``]
  *stdout*
     how to handle the program's stdout stream [``None``]

     filehandle
            anything that behaves like a file object
     ``None`` or ``True``
            to see  output on screen
     ``False`` or ``PIPE``
             returns the output as a string in  the stdout parameter 

  *stderr*
     how to handle the stderr stream [``STDOUT``]

     ``STDOUT``
             merges standard error with the standard out stream
     ``False`` or ``PIPE``
             returns the output as a string in the stderr return parameter
     ``None`` or ``True``
             keeps it on stderr (and presumably on screen)

All other kwargs are passed on to the Gromacs tool.

:Returns:

   The shell return code rc of the command is always returned. Depending
   on the value of output, various strings are filled with output from the
   command.

:Notes:

   By default, the process stdout and stderr are merged.

   In order to chain different commands via pipes one must use the special
   :class:`PopenWithInput` object (see :meth:`GromacsCommand.Popen` method) instead of the simple
   call described here and first construct the pipeline explicitly and then
   call the :meth:`PopenWithInput.communicate` method.

   ``STDOUT`` and ``PIPE`` are objects provided by the :mod:`subprocess` module. Any
   python stream can be provided and manipulated. This allows for chaining
   of commands. Use ::

      from subprocess import PIPE, STDOUT

   when requiring these special streams (and the special boolean
   switches ``True``/``False`` cannot do what you need.)

   (TODO: example for chaining commands)


Class Variable Details [hide private]

command_name

Derive a class from command; typically one only has to set *command_name*
to the name of the script or executable. The full path is required if it
cannot be found by searching :envvar:`PATH`.

Value:
None