Package Ganga :: Package Utility :: Module Shell :: Class Shell
[hide private]
[frames] | no frames]

Class Shell

source code

Instance Methods [hide private]
 
__init__(self, setup=None, setup_args=[])
The setup script is sourced (with possible arguments) and the environment is captured.
source code
 
cmd(self, cmd, soutfile=None, allowed_exit=[0], capture_stderr=False, timeout=None, mention_outputfile_on_errors=True)
Execute an OS command and captures the stderr and stdout which are returned in a file
source code
 
cmd1(self, cmd, allowed_exit=[0], capture_stderr=False, timeout=None)
Executes an OS command and captures the stderr and stdout which are returned as a string
source code
 
system(self, cmd, allowed_exit=[0], stderr_file=None)
Execute on OS command.
source code
 
wrapper(self, cmd, preexecute=None)
Write wrapper script for command
source code
Class Variables [hide private]
  exceptions = getConfig('Shell') ['IgnoredVars']
Method Details [hide private]

__init__(self, setup=None, setup_args=[])
(Constructor)

source code 
The setup script is sourced (with possible arguments) and the
environment is captured. The environment variables are expanded
automatically (this is a fix for bug #44259: GangaLHCb tests fail due to
gridProxy check).

Example of variable expansion:

os.environ['BAR'] = 'rabarbar'
os.environ['FOO'] = '$BAR'
s = Shell() # with or without the setup script
assert s.env['FOO'] == 'rabarbar' # NOT literal string '$BAR'

NOTE: the behaviour is not 100% bash compatible: undefined variables in
bash are empty strings, Shell() leaves the literals unchanged,so:

os.environ['FOO'] = '$NO_BAR'
s = Shell()
if os.environ.not has_key('NO_BAR'):
   assert s.env['FOO'] == '$NO_BAR'
   

system(self, cmd, allowed_exit=[0], stderr_file=None)

source code 

Execute on OS command. Useful for interactive commands. Stdout and Stderr are not caputured and are passed on the caller.

stderr_capture may specify a name of a file to which stderr is redirected.

wrapper(self, cmd, preexecute=None)

source code 

Write wrapper script for command

A wrapper around cmd is written including the setting of the environment. Useful for situations where it is an external Python module that is calling the command. It is callers responsibility to enter new location into PATH as this might have external effects. Full path of wrapper script is returned. Preexecute can contain extra commands to be executed before cmd

fullpath = s.wrapper('lcg-cp', 'echo lcg-cp called with arguments $*'