Utility Classes.
More...
Utility Classes.
Class to changes the environment temporarily.
Definition at line 78 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 83 of file GaudiTest.py.
83 def __init__(self, orig=os.environ, keep_same=False):
85 Create a temporary environment on top of the one specified 86 (it can be another TemporaryEnvironment instance). 91 self._keep_same = keep_same
◆ __del__()
def GaudiTest.TemporaryEnvironment.__del__ |
( |
|
self | ) |
|
Revert the changes on destruction.
Definition at line 154 of file GaudiTest.py.
156 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 136 of file GaudiTest.py.
136 def __contains__(self, key):
139 Needed to provide the same interface as os.environ. 141 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 112 of file GaudiTest.py.
112 def __delitem__(self, key):
114 Unset an environment variable. 115 Needed to provide the same interface as os.environ. 117 if key
not in self.env:
119 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 105 of file GaudiTest.py.
107 Get an environment variable. 108 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 93 of file GaudiTest.py.
93 def __setitem__(self, key, value):
95 Set an environment variable recording the previous value. 97 if key
not in self.old_values:
99 if not self._keep_same
or self.env[key] != value:
100 self.old_values[key] = self.env[key]
102 self.old_values[key] =
None 103 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 161 of file GaudiTest.py.
161 def gen_script(self, shell_type):
163 Generate a shell script to reproduce the changes in the environment. 165 shells = [
'csh',
'sh',
'bat']
166 if shell_type
not in shells:
167 raise RuntimeError(
"Shell type '%s' unknown. Available: %s" %
168 (shell_type, shells))
170 for key, value
in self.old_values.
items():
171 if key
not in self.env:
173 if shell_type ==
'csh':
174 out +=
'unsetenv %s\n' % key
175 elif shell_type ==
'sh':
176 out +=
'unset %s\n' % key
177 elif shell_type ==
'bat':
178 out +=
'set %s=\n' % key
181 if shell_type ==
'csh':
182 out +=
'setenv %s "%s"\n' % (key, self.env[key])
183 elif shell_type ==
'sh':
184 out +=
'export %s="%s"\n' % (key, self.env[key])
185 elif shell_type ==
'bat':
186 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 129 of file GaudiTest.py.
131 Return the list of (name,value) pairs for the defined environment variables. 132 Needed to provide the same interface as os.environ. 134 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 122 of file GaudiTest.py.
124 Return the list of defined environment variables. 125 Needed to provide the same interface as os.environ. 127 return self.env.keys()
◆ restore()
def GaudiTest.TemporaryEnvironment.restore |
( |
|
self | ) |
|
Revert all the changes done to the original environment.
Definition at line 143 of file GaudiTest.py.
145 Revert all the changes done to the original environment. 147 for key, value
in self.old_values.
items():
151 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: