| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Private Attributes | List of all members
GaudiTest.TemporaryEnvironment Class Reference

Utility Classes. More...

## Public Member Functions
def | __init__ (self, orig=os.environ, keep_same=False)
def | __setitem__ (self, key, value)
def | __getitem__ (self, key)
def | __delitem__ (self, key)
def | keys (self)
def | items (self)
def | __contains__ (self, key)
def | restore (self)
def | __del__ (self)
def | gen_script (self, shell_type)

## Public Attributes
| old_values
| env

## Private Attributes
| _keep_same

## Detailed Description

Utility Classes.

    Class to changes the environment temporarily.

Definition at line 75 of file GaudiTest.py.

## Constructor & Destructor Documentation

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 80 of file GaudiTest.py.

80 def __init__(self, orig=os.environ, keep_same=False):
81 """
82 Create a temporary environment on top of the one specified
83 (it can be another TemporaryEnvironment instance).
84 """
85 # print "New environment"
86 self.old_values = {}
87 self.env = orig
88 self._keep_same = keep_same
89
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:87
GaudiTest.TemporaryEnvironment.old_values
old_values
Definition: GaudiTest.py:86
GaudiTest.TemporaryEnvironment._keep_same
_keep_same
Definition: GaudiTest.py:88
GaudiTest.TemporaryEnvironment.__init__
def __init__(self, orig=os.environ, keep_same=False)
Definition: GaudiTest.py:80

def GaudiTest.TemporaryEnvironment.__del__ | ( |  | self | ) |

    Revert the changes on destruction.

Definition at line 151 of file GaudiTest.py.

151 def __del__(self):
152 """
153 Revert the changes on destruction.
154 """
155 # print "Restoring the environment"
156 self.restore()
157
GaudiTest.TemporaryEnvironment.__del__
def __del__(self)
Definition: GaudiTest.py:151
GaudiTest.TemporaryEnvironment.restore
def restore(self)
Definition: GaudiTest.py:140

## Member Function Documentation

def GaudiTest.TemporaryEnvironment.__contains__ | ( |  | self,
|  |  | key
| ) |  |

    Operator 'in'.
    Needed to provide the same interface as os.environ.

Definition at line 133 of file GaudiTest.py.

133 def __contains__(self, key):
134 """
135 Operator 'in'.
136 Needed to provide the same interface as os.environ.
137 """
138 return key in self.env
139
GaudiTest.TemporaryEnvironment.__contains__
def __contains__(self, key)
Definition: GaudiTest.py:133
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:87

def GaudiTest.TemporaryEnvironment.__delitem__ | ( |  | self,
|  |  | key
| ) |  |

    Unset an environment variable.
    Needed to provide the same interface as os.environ.

Definition at line 109 of file GaudiTest.py.

109 def __delitem__(self, key):
110 """
111 Unset an environment variable.
112 Needed to provide the same interface as os.environ.
113 """
114 if key not in self.env:
115 raise KeyError(key)
116 self.old_values[key] = self.env[key]
117 del self.env[key]
118
GaudiTest.TemporaryEnvironment.__delitem__
def __delitem__(self, key)
Definition: GaudiTest.py:109
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:87
GaudiTest.TemporaryEnvironment.old_values
old_values
Definition: GaudiTest.py:86

def GaudiTest.TemporaryEnvironment.__getitem__ | ( |  | self,
|  |  | key
| ) |  |

    Get an environment variable.
    Needed to provide the same interface as os.environ.

Definition at line 102 of file GaudiTest.py.

102 def __getitem__(self, key):
103 """
104 Get an environment variable.
105 Needed to provide the same interface as os.environ.
106 """
107 return self.env[key]
108
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:87
GaudiTest.TemporaryEnvironment.__getitem__
def __getitem__(self, key)
Definition: GaudiTest.py:102

def GaudiTest.TemporaryEnvironment.__setitem__ | ( |  | self,
|  |  | key,
|  |  | value
| ) |  |

    Set an environment variable recording the previous value.

Definition at line 90 of file GaudiTest.py.

90 def __setitem__(self, key, value):
91 """
92 Set an environment variable recording the previous value.
93 """
94 if key not in self.old_values:
95 if key in self.env:
96 if not self._keep_same or self.env[key] != value:
97 self.old_values[key] = self.env[key]
98 else:
99 self.old_values[key] = None
100 self.env[key] = value
101
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:87
GaudiTest.TemporaryEnvironment.__setitem__
def __setitem__(self, key, value)
Definition: GaudiTest.py:90
GaudiTest.TemporaryEnvironment.old_values
old_values
Definition: GaudiTest.py:86
GaudiTest.TemporaryEnvironment._keep_same
_keep_same
Definition: GaudiTest.py:88

def GaudiTest.TemporaryEnvironment.gen_script | ( |  | self,
|  |  | shell_type
| ) |  |

    Generate a shell script to reproduce the changes in the environment.

Definition at line 158 of file GaudiTest.py.

158 def gen_script(self, shell_type):
159 """
160 Generate a shell script to reproduce the changes in the environment.
161 """
162 shells = ['csh', 'sh', 'bat']
163 if shell_type not in shells:
164 raise RuntimeError(
165 "Shell type '%s' unknown. Available: %s" % (shell_type, shells))
166 out = ""
167 for key, value in self.old_values.items():
168 if key not in self.env:
169 # unset variable
170 if shell_type == 'csh':
171 out += 'unsetenv %s\n' % key
172 elif shell_type == 'sh':
173 out += 'unset %s\n' % key
174 elif shell_type == 'bat':
175 out += 'set %s=\n' % key
176 else:
177 # set variable
178 if shell_type == 'csh':
179 out += 'setenv %s "%s"\n' % (key, self.env[key])
180 elif shell_type == 'sh':
181 out += 'export %s="%s"\n' % (key, self.env[key])
182 elif shell_type == 'bat':
183 out += 'set %s=%s\n' % (key, self.env[key])
184 return out
185
186
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:87
GaudiTest.TemporaryEnvironment.gen_script
def gen_script(self, shell_type)
Definition: GaudiTest.py:158

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 126 of file GaudiTest.py.

126 def items(self):
127 """
128 Return the list of (name,value) pairs for the defined environment variables.
129 Needed to provide the same interface as os.environ.
130 """
131 return self.env.items()
132
GaudiTest.TemporaryEnvironment.items
def items(self)
Definition: GaudiTest.py:126

def GaudiTest.TemporaryEnvironment.keys | ( |  | self | ) |

    Return the list of defined environment variables.
    Needed to provide the same interface as os.environ.

Definition at line 119 of file GaudiTest.py.

119 def keys(self):
120 """
121 Return the list of defined environment variables.
122 Needed to provide the same interface as os.environ.
123 """
124 return self.env.keys()
125
GaudiTest.TemporaryEnvironment.keys
def keys(self)
Definition: GaudiTest.py:119

def GaudiTest.TemporaryEnvironment.restore | ( |  | self | ) |

    Revert all the changes done to the original environment.

Definition at line 140 of file GaudiTest.py.

140 def restore(self):
141 """
142 Revert all the changes done to the original environment.
143 """
144 for key, value in self.old_values.items():
145 if value is None:
146 del self.env[key]
147 else:
148 self.env[key] = value
149 self.old_values = {}
150
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:87
GaudiTest.TemporaryEnvironment.old_values
old_values
Definition: GaudiTest.py:86
GaudiTest.TemporaryEnvironment.restore
def restore(self)
Definition: GaudiTest.py:140

## Member Data Documentation

GaudiTest.TemporaryEnvironment._keep_same
| private

Definition at line 88 of file GaudiTest.py.

GaudiTest.TemporaryEnvironment.env

Definition at line 87 of file GaudiTest.py.

GaudiTest.TemporaryEnvironment.old_values

Definition at line 86 of file GaudiTest.py.

The documentation for this class was generated from the following file:

- GaudiPolicy/qmtest_classes/GaudiTest.py