Utility Classes.
More...
Utility Classes.
Class to changes the environment temporarily.
Definition at line 88 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 93 of file GaudiTest.py.
93 def __init__(self, orig=os.environ, keep_same=False):
95 Create a temporary environment on top of the one specified 96 (it can be another TemporaryEnvironment instance). 101 self._keep_same = keep_same
◆ __del__()
| def GaudiTest.TemporaryEnvironment.__del__ |
( |
|
self | ) |
|
Revert the changes on destruction.
Definition at line 164 of file GaudiTest.py.
166 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 146 of file GaudiTest.py.
146 def __contains__(self, key):
149 Needed to provide the same interface as os.environ. 151 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 122 of file GaudiTest.py.
122 def __delitem__(self, key):
124 Unset an environment variable. 125 Needed to provide the same interface as os.environ. 127 if key
not in self.env:
129 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 115 of file GaudiTest.py.
117 Get an environment variable. 118 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 103 of file GaudiTest.py.
103 def __setitem__(self, key, value):
105 Set an environment variable recording the previous value. 107 if key
not in self.old_values:
109 if not self._keep_same
or self.env[key] != value:
110 self.old_values[key] = self.env[key]
112 self.old_values[key] =
None 113 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 171 of file GaudiTest.py.
171 def gen_script(self, shell_type):
173 Generate a shell script to reproduce the changes in the environment. 175 shells = [
'csh',
'sh',
'bat']
176 if shell_type
not in shells:
177 raise RuntimeError(
"Shell type '%s' unknown. Available: %s" %
178 (shell_type, shells))
180 for key, value
in self.old_values.
items():
181 if key
not in self.env:
183 if shell_type ==
'csh':
184 out +=
'unsetenv %s\n' % key
185 elif shell_type ==
'sh':
186 out +=
'unset %s\n' % key
187 elif shell_type ==
'bat':
188 out +=
'set %s=\n' % key
191 if shell_type ==
'csh':
192 out +=
'setenv %s "%s"\n' % (key, self.env[key])
193 elif shell_type ==
'sh':
194 out +=
'export %s="%s"\n' % (key, self.env[key])
195 elif shell_type ==
'bat':
196 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 139 of file GaudiTest.py.
141 Return the list of (name,value) pairs for the defined environment variables. 142 Needed to provide the same interface as os.environ. 144 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 132 of file GaudiTest.py.
134 Return the list of defined environment variables. 135 Needed to provide the same interface as os.environ. 137 return self.env.keys()
◆ restore()
| def GaudiTest.TemporaryEnvironment.restore |
( |
|
self | ) |
|
Revert all the changes done to the original environment.
Definition at line 153 of file GaudiTest.py.
155 Revert all the changes done to the original environment. 157 for key, value
in self.old_values.
items():
161 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: