| The Gaudi Framework v28r2-patches (bc4ad17a)

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

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

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

    Revert the changes on destruction.

Definition at line 146 of file GaudiTest.py.

146 def __del__(self):
147 """
148 Revert the changes on destruction.
149 """
150 #print "Restoring the environment"
151 self.restore()
152
GaudiTest.TemporaryEnvironment.__del__
def __del__(self)
Definition: GaudiTest.py:146
GaudiTest.TemporaryEnvironment.restore
def restore(self)
Definition: GaudiTest.py:135

## Member Function Documentation

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

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

Definition at line 128 of file GaudiTest.py.

128 def __contains__(self,key):
129 """
130 Operator 'in'.
131 Needed to provide the same interface as os.environ.
132 """
133 return key in self.env
134
GaudiTest.TemporaryEnvironment.__contains__
def __contains__(self, key)
Definition: GaudiTest.py:128
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:82

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

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

Definition at line 104 of file GaudiTest.py.

104 def __delitem__(self,key):
105 """
106 Unset an environment variable.
107 Needed to provide the same interface as os.environ.
108 """
109 if key not in self.env :
110 raise KeyError(key)
111 self.old_values[key] = self.env[key]
112 del self.env[key]
113
GaudiTest.TemporaryEnvironment.__delitem__
def __delitem__(self, key)
Definition: GaudiTest.py:104
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:82
GaudiTest.TemporaryEnvironment.old_values
old_values
Definition: GaudiTest.py:81

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

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

Definition at line 97 of file GaudiTest.py.

97 def __getitem__(self,key):
98 """
99 Get an environment variable.
100 Needed to provide the same interface as os.environ.
101 """
102 return self.env[key]
103
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:82
GaudiTest.TemporaryEnvironment.__getitem__
def __getitem__(self, key)
Definition: GaudiTest.py:97

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

    Set an environment variable recording the previous value.

Definition at line 85 of file GaudiTest.py.

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

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

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

Definition at line 153 of file GaudiTest.py.

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

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

121 def items(self):
122 """
123 Return the list of (name,value) pairs for the defined environment variables.
124 Needed to provide the same interface as os.environ.
125 """
126 return self.env.items()
127
GaudiTest.TemporaryEnvironment.items
def items(self)
Definition: GaudiTest.py:121

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

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

Definition at line 114 of file GaudiTest.py.

114 def keys(self):
115 """
116 Return the list of defined environment variables.
117 Needed to provide the same interface as os.environ.
118 """
119 return self.env.keys()
120
GaudiTest.TemporaryEnvironment.keys
def keys(self)
Definition: GaudiTest.py:114

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

    Revert all the changes done to the original environment.

Definition at line 135 of file GaudiTest.py.

135 def restore(self):
136 """
137 Revert all the changes done to the original environment.
138 """
139 for key,value in self.old_values.items():
140 if value is None:
141 del self.env[key]
142 else:
143 self.env[key] = value
144 self.old_values = {}
145
GaudiTest.TemporaryEnvironment.env
env
Definition: GaudiTest.py:82
GaudiTest.TemporaryEnvironment.old_values
old_values
Definition: GaudiTest.py:81
GaudiTest.TemporaryEnvironment.restore
def restore(self)
Definition: GaudiTest.py:135

## Member Data Documentation

GaudiTest.TemporaryEnvironment._keep_same
| private

Definition at line 83 of file GaudiTest.py.

GaudiTest.TemporaryEnvironment.env

Definition at line 82 of file GaudiTest.py.

GaudiTest.TemporaryEnvironment.old_values

Definition at line 81 of file GaudiTest.py.

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

- GaudiPolicy/qmtest_classes/GaudiTest.py