|
Gaudi Framework, version v23r4 |
| Home | Generated: Mon Sep 17 2012 |
Public Member Functions | |
| def | __init__ |
| def | vars |
| def | var |
| def | search |
| def | append |
| def | prepend |
| def | declare |
| def | set |
| def | unset |
| def | remove |
| def | remove_regexp |
| def | searchFile |
| def | loadXML |
| def | startXMLinput |
| def | finishXMLinput |
| def | writeToFile |
| def | writeToXMLFile |
| def | loadAllSystemVariables |
| def | __getitem__ |
| def | __setitem__ |
| def | __delitem__ |
| def | __iter__ |
| def | __contains__ |
| def | __len__ |
Public Attributes | |
| report | |
| sysSeparator | |
| separator | |
| actions | |
| variables | |
| loadFromSystem | |
| asWriter | |
| writer | |
Private Member Functions | |
| def | _concatenate |
| def | _writeVarToXML |
object to hold settings of environment
Definition at line 12 of file Control.py.
| def EnvConfig::Control::Environment::__init__ | ( | self, | |
loadFromSystem = True, |
|||
useAsWriter = False, |
|||
reportLevel = 1 |
|||
| ) |
Initial variables to be pushed and setup append switch between append and prepend for initial variables. loadFromSystem causes variable`s system value to be loaded on first encounter. If useAsWriter == True than every change to variables is recorded to XML file. reportLevel sets the level of messaging. **kwargs contain initial variables.
Definition at line 15 of file Control.py.
00016 : 00017 '''Initial variables to be pushed and setup 00018 00019 append switch between append and prepend for initial variables. 00020 loadFromSystem causes variable`s system value to be loaded on first encounter. 00021 If useAsWriter == True than every change to variables is recorded to XML file. 00022 reportLevel sets the level of messaging. 00023 **kwargs contain initial variables. 00024 ''' 00025 self.report = xmlModule.Report(reportLevel) 00026 00027 if platform.system() != 'Linux': 00028 self.sysSeparator = ';' 00029 else: 00030 self.sysSeparator = ':' 00031 self.separator = ':' 00032 00033 self.actions = {} 00034 self.actions['append'] = lambda n, v, _: self.append(n, v) 00035 self.actions['prepend'] = lambda n, v, _: self.prepend(n, v) 00036 self.actions['set'] = lambda n, v, _: self.set(n, v) 00037 self.actions['unset'] = lambda n, v, _: self.unset(n, v) 00038 self.actions['remove'] = lambda n, v, _: self.remove(n, v) 00039 self.actions['remove-regexp'] = lambda n, v, _: self.remove_regexp(n, v) 00040 self.actions['declare'] = self.declare 00041 00042 self.variables = {} 00043 self.loadFromSystem = loadFromSystem 00044 self.asWriter = useAsWriter 00045 if useAsWriter: 00046 self.writer = xmlModule.XMLFile() 00047 self.startXMLinput() 00048
| def EnvConfig::Control::Environment::__contains__ | ( | self, | |
| item | |||
| ) |
Definition at line 268 of file Control.py.
| def EnvConfig::Control::Environment::__delitem__ | ( | self, | |
| key | |||
| ) |
Definition at line 261 of file Control.py.
| def EnvConfig::Control::Environment::__getitem__ | ( | self, | |
| key | |||
| ) |
Definition at line 252 of file Control.py.
| def EnvConfig::Control::Environment::__iter__ | ( | self ) |
Definition at line 264 of file Control.py.
| def EnvConfig::Control::Environment::__len__ | ( | self ) |
Definition at line 271 of file Control.py.
| def EnvConfig::Control::Environment::__setitem__ | ( | self, | |
| key, | |||
| value | |||
| ) |
Definition at line 255 of file Control.py.
| def EnvConfig::Control::Environment::_concatenate | ( | self, | |
| value | |||
| ) | [private] |
Returns a variable string with separator separator from the values list
Definition at line 236 of file Control.py.
| def EnvConfig::Control::Environment::_writeVarToXML | ( | self, | |
| name, | |||
| action, | |||
| value, | |||
type = 'list', |
|||
local = 'false' |
|||
| ) | [private] |
Writes single variable to XML file.
Definition at line 245 of file Control.py.
| def EnvConfig::Control::Environment::append | ( | self, | |
| name, | |||
| value | |||
| ) |
Appends to an existing variable.
Definition at line 74 of file Control.py.
00075 : 00076 '''Appends to an existing variable.''' 00077 if self.asWriter: 00078 self._writeVarToXML(name, 'append', value) 00079 else: 00080 if name in self.variables.keys(): 00081 self.variables[name].append(value, self.separator, self.variables) 00082 else: 00083 self.declare(name, 'list', False) 00084 self.append(name, value) 00085
| def EnvConfig::Control::Environment::declare | ( | self, | |
| name, | |||
| type, | |||
| local | |||
| ) |
Creates an instance of new variable. It loads values from the OS if the variable is not local.
Definition at line 97 of file Control.py.
00098 : 00099 '''Creates an instance of new variable. It loads values from the OS if the variable is not local.''' 00100 if self.asWriter: 00101 self._writeVarToXML(name, 'declare', '', type, local) 00102 00103 if not isinstance(local, bool): 00104 if str(local).lower() == 'true': 00105 local = True 00106 else: 00107 local = False 00108 00109 if name in self.variables.keys(): 00110 if self.variables[name].local != local: 00111 raise Variable.EnvironmentError(name, 'redeclaration') 00112 else: 00113 if type.lower() == "list": 00114 if not isinstance(self.variables[name],Variable.List): 00115 raise Variable.EnvironmentError(name, 'redeclaration') 00116 else: 00117 if not isinstance(self.variables[name],Variable.Scalar): 00118 raise Variable.EnvironmentError(name, 'redeclaration') 00119 00120 if type.lower() == "list": 00121 a = Variable.List(name, local, report=self.report) 00122 else: 00123 a = Variable.Scalar(name, local, report=self.report) 00124 00125 if self.loadFromSystem and not local: 00126 if name in os.environ.keys(): 00127 a.set(os.environ[name], self.sysSeparator, environment=self.variables, resolve=False) 00128 self.variables[name] = a
| def EnvConfig::Control::Environment::finishXMLinput | ( | self, | |
outputFile = '' |
|||
| ) |
Finishes input of XML file and closes the file.
Definition at line 190 of file Control.py.
| def EnvConfig::Control::Environment::loadAllSystemVariables | ( | self ) |
Loads all variables from the current system settings.
Definition at line 229 of file Control.py.
| def EnvConfig::Control::Environment::loadXML | ( | self, | |
fileName = None, |
|||
namespace = 'EnvSchema' |
|||
| ) |
Loads XML file for input variables.
Definition at line 174 of file Control.py.
00175 : 00176 '''Loads XML file for input variables.''' 00177 XMLfile = xmlModule.XMLFile() 00178 variables = XMLfile.variable(fileName, namespace = namespace) 00179 for i, (action, args) in enumerate(variables): 00180 if action not in self.actions: 00181 self.report.addError('Node {0}: No action taken with var "{1}". Probably wrong action argument: "{2}".'.format(i, args[0], action)) 00182 else: 00183 self.actions[action](*args) 00184
| def EnvConfig::Control::Environment::prepend | ( | self, | |
| name, | |||
| value | |||
| ) |
Prepends to an existing variable, or create a new one.
Definition at line 86 of file Control.py.
00087 : 00088 '''Prepends to an existing variable, or create a new one.''' 00089 if self.asWriter: 00090 self._writeVarToXML(name, 'prepend', value) 00091 else: 00092 if name in self.variables.keys(): 00093 self.variables[name].prepend(value, self.separator, self.variables) 00094 else: 00095 self.declare(name, 'list', False) 00096 self.prepend(name, value)
| def EnvConfig::Control::Environment::remove | ( | self, | |
| name, | |||
| value, | |||
regexp = False |
|||
| ) |
Remove value from variable.
Definition at line 153 of file Control.py.
00154 : 00155 '''Remove value from variable.''' 00156 if self.asWriter: 00157 self._writeVarToXML(name, 'remove', value) 00158 else: 00159 if name in self.variables: 00160 self.variables[name].remove(value, self.separator, regexp) 00161 elif self.loadFromSystem: 00162 self.declare(name, 'list', False) 00163
| def EnvConfig::Control::Environment::remove_regexp | ( | self, | |
| name, | |||
| value | |||
| ) |
Definition at line 164 of file Control.py.
| def EnvConfig::Control::Environment::search | ( | self, | |
| varName, | |||
| expr, | |||
regExp = False |
|||
| ) |
Searches in a variable for a value.
Definition at line 69 of file Control.py.
| def EnvConfig::Control::Environment::searchFile | ( | self, | |
| file, | |||
| varName | |||
| ) |
Searches for appearance of variable in a file.
Definition at line 168 of file Control.py.
| def EnvConfig::Control::Environment::set | ( | self, | |
| name, | |||
| value | |||
| ) |
Sets a single variable - overrides any previous value!
Definition at line 129 of file Control.py.
00130 : 00131 '''Sets a single variable - overrides any previous value!''' 00132 name = str(name) 00133 if self.asWriter: 00134 self._writeVarToXML(name, 'set', value) 00135 else: 00136 if name in self.variables: 00137 self.variables[name].set(value, self.separator, self.variables) 00138 else: 00139 self.declare(name, 'list', False) 00140 self.set(name, value)
| def EnvConfig::Control::Environment::startXMLinput | ( | self ) |
Renew writer for new input.
Definition at line 185 of file Control.py.
| def EnvConfig::Control::Environment::unset | ( | self, | |
| name, | |||
value = None |
|||
| ) |
Unsets a single variable to an empty value - overrides any previous value!
Definition at line 141 of file Control.py.
00142 : 00143 '''Unsets a single variable to an empty value - overrides any previous value!''' 00144 if self.asWriter: 00145 self._writeVarToXML(name, 'unset', '') 00146 else: 00147 if name in self.variables: 00148 self.variables[name].set([], self.separator) 00149 else: 00150 a = Variable.List(name, report=self.report) 00151 self.variables[name] = a 00152
| def EnvConfig::Control::Environment::var | ( | self, | |
| name | |||
| ) |
Gets a single variable. If not available then tries to load from system.
Definition at line 60 of file Control.py.
| def EnvConfig::Control::Environment::vars | ( | self, | |
strings = True |
|||
| ) |
returns dictionary of all variables optionally converted to string
Definition at line 49 of file Control.py.
| def EnvConfig::Control::Environment::writeToFile | ( | self, | |
| fileName, | |||
shell = 'sh' |
|||
| ) |
Creates an output file with a specified name to be used for setting variables by sourcing this file
Definition at line 195 of file Control.py.
00196 : 00197 '''Creates an output file with a specified name to be used for setting variables by sourcing this file''' 00198 f = open(fileName, 'w') 00199 if shell == 'sh': 00200 f.write('#!/bin/bash\n') 00201 for variable in self.variables: 00202 if not self[variable].local: 00203 f.write('export ' +variable+'='+self[variable].value(True, self.sysSeparator)+'\n') 00204 elif shell == 'csh': 00205 f.write('#!/bin/csh\n') 00206 for variable in self.variables: 00207 if not self[variable].local: 00208 f.write('setenv ' +variable+' '+self[variable].value(True, self.sysSeparator)+'\n') 00209 else: 00210 f.write('') 00211 f.write('REM This is an enviroment settings file generated on '+strftime("%a, %d %b %Y %H:%M:%S\n", gmtime())) 00212 for variable in self.variables: 00213 if not self[variable].local: 00214 f.write('set '+variable+'='+self[variable].value(True, self.sysSeparator)+'\n') 00215 00216 f.close() 00217
| def EnvConfig::Control::Environment::writeToXMLFile | ( | self, | |
| fileName | |||
| ) |
Writes the current state of environment to a XML file. NOTE: There is no trace of actions taken, variables are written with a set action only.
Definition at line 218 of file Control.py.
00219 : 00220 '''Writes the current state of environment to a XML file. 00221 00222 NOTE: There is no trace of actions taken, variables are written with a set action only. 00223 ''' 00224 writer = xmlModule.XMLFile() 00225 for var in self.variables.keys(): 00226 writer.writeVar(var, 'set', self.variables[var].value(True, self.separator)) 00227 writer.writeToFile(fileName) 00228
Definition at line 22 of file Control.py.
Definition at line 22 of file Control.py.
Definition at line 22 of file Control.py.
Definition at line 22 of file Control.py.
Definition at line 22 of file Control.py.
Definition at line 22 of file Control.py.
Definition at line 22 of file Control.py.
Definition at line 22 of file Control.py.