Utility Classes.
More...
Utility Classes.
Class to changes the environment temporarily.
Definition at line 77 of file GaudiTest.py.
◆ __init__()
| def GaudiTest.TemporaryEnvironment.__init__ |
( |
|
self, |
|
|
|
orig = os.environ, |
|
|
|
keep_same = False |
|
) |
| |
Create a temporary environment on top of the one specified
(it can be another TemporaryEnvironment instance).
Definition at line 82 of file GaudiTest.py.
82 def __init__(self, orig=os.environ, keep_same=False):
84 Create a temporary environment on top of the one specified 85 (it can be another TemporaryEnvironment instance). 90 self._keep_same = keep_same
◆ __del__()
| def GaudiTest.TemporaryEnvironment.__del__ |
( |
|
self | ) |
|
Revert the changes on destruction.
Definition at line 153 of file GaudiTest.py.
155 Revert the changes on destruction.
◆ __contains__()
| def GaudiTest.TemporaryEnvironment.__contains__ |
( |
|
self, |
|
|
|
key |
|
) |
| |
Operator 'in'.
Needed to provide the same interface as os.environ.
Definition at line 135 of file GaudiTest.py.
135 def __contains__(self, key):
138 Needed to provide the same interface as os.environ. 140 return key
in self.env
◆ __delitem__()
| def GaudiTest.TemporaryEnvironment.__delitem__ |
( |
|
self, |
|
|
|
key |
|
) |
| |
Unset an environment variable.
Needed to provide the same interface as os.environ.
Definition at line 111 of file GaudiTest.py.
111 def __delitem__(self, key):
113 Unset an environment variable. 114 Needed to provide the same interface as os.environ. 116 if key
not in self.env:
118 self.old_values[key] = self.env[key]
◆ __getitem__()
| def GaudiTest.TemporaryEnvironment.__getitem__ |
( |
|
self, |
|
|
|
key |
|
) |
| |
Get an environment variable.
Needed to provide the same interface as os.environ.
Definition at line 104 of file GaudiTest.py.
106 Get an environment variable. 107 Needed to provide the same interface as os.environ.
◆ __setitem__()
| def GaudiTest.TemporaryEnvironment.__setitem__ |
( |
|
self, |
|
|
|
key, |
|
|
|
value |
|
) |
| |
Set an environment variable recording the previous value.
Definition at line 92 of file GaudiTest.py.
92 def __setitem__(self, key, value):
94 Set an environment variable recording the previous value. 96 if key
not in self.old_values:
98 if not self._keep_same
or self.env[key] != value:
99 self.old_values[key] = self.env[key]
101 self.old_values[key] =
None 102 self.env[key] = value
◆ gen_script()
| def GaudiTest.TemporaryEnvironment.gen_script |
( |
|
self, |
|
|
|
shell_type |
|
) |
| |
Generate a shell script to reproduce the changes in the environment.
Definition at line 160 of file GaudiTest.py.
160 def gen_script(self, shell_type):
162 Generate a shell script to reproduce the changes in the environment. 164 shells = [
'csh',
'sh',
'bat']
165 if shell_type
not in shells:
166 raise RuntimeError(
"Shell type '%s' unknown. Available: %s" %
167 (shell_type, shells))
169 for key, value
in self.old_values.items():
170 if key
not in self.env:
172 if shell_type ==
'csh':
173 out +=
'unsetenv %s\n' % key
174 elif shell_type ==
'sh':
175 out +=
'unset %s\n' % key
176 elif shell_type ==
'bat':
177 out +=
'set %s=\n' % key
180 if shell_type ==
'csh':
181 out +=
'setenv %s "%s"\n' % (key, self.env[key])
182 elif shell_type ==
'sh':
183 out +=
'export %s="%s"\n' % (key, self.env[key])
184 elif shell_type ==
'bat':
185 out +=
'set %s=%s\n' % (key, self.env[key])
◆ items()
| def GaudiTest.TemporaryEnvironment.items |
( |
|
self | ) |
|
Return the list of (name,value) pairs for the defined environment variables.
Needed to provide the same interface as os.environ.
Definition at line 128 of file GaudiTest.py.
130 Return the list of (name,value) pairs for the defined environment variables. 131 Needed to provide the same interface as os.environ. 133 return self.env.items()
◆ keys()
| def GaudiTest.TemporaryEnvironment.keys |
( |
|
self | ) |
|
Return the list of defined environment variables.
Needed to provide the same interface as os.environ.
Definition at line 121 of file GaudiTest.py.
123 Return the list of defined environment variables. 124 Needed to provide the same interface as os.environ. 126 return self.env.keys()
◆ restore()
| def GaudiTest.TemporaryEnvironment.restore |
( |
|
self | ) |
|
Revert all the changes done to the original environment.
Definition at line 142 of file GaudiTest.py.
144 Revert all the changes done to the original environment. 146 for key, value
in self.old_values.items():
150 self.env[key] = value
◆ _keep_same
| GaudiTest.TemporaryEnvironment._keep_same |
|
private |
◆ env
| GaudiTest.TemporaryEnvironment.env |
◆ old_values
| GaudiTest.TemporaryEnvironment.old_values |
The documentation for this class was generated from the following file: