| The Gaudi Framework v27r1

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

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

Static Public Attributes | Private Member Functions | List of all members
GaudiKernel.ProcessJobOptions.JobOptsParser Class Reference
Collaboration diagram for GaudiKernel.ProcessJobOptions.JobOptsParser:
[legend]

## Static Public Attributes
tuple | comment = re.compile(r'(//.*)$')
tuple | comment_in_string
list | l = l[string_end+1:]
| in_string = False
string | l = ''
tuple | string_start = l.find('"') if string_start >= 0: string_end = l.find('"', string_start + 1)
tuple | l = f.readline()
tuple | i = l.index(self.statement_sep)
list | statement = l[i+1:]
string | statement = ""

## Private Member Functions
def | _parse_units (self, file)
def | _eval_statement (self, statement)

## Detailed Description

Definition at line 132 of file ProcessJobOptions.py.

## Member Function Documentation

def GaudiKernel.ProcessJobOptions.JobOptsParser._eval_statement | ( |  | self,
|  |  | statement
| ) |  |
| private

Definition at line 297 of file ProcessJobOptions.py.

297 def _eval_statement(self,statement):
298 from GaudiKernel.Proxy.Configurable import (ConfigurableGeneric,
299 Configurable,
300 PropertyReference)
301 #statement = statement.replace("\n","").strip()
302 _log.info("%s%s", statement, self.statement_sep)
303
304 property,value = statement.split("=",1)
305
306 inc = None
307 if property[-1] in [ "+", "-" ]:
308 inc = property[-1]
309 property = property[:-1]
310
311 property = property.strip()
312 value = value.strip()
313
314 ## find the configurable to apply the property to
315 #parent_cfg = None
316 #while '.' in property:
317 # component, property = property.split('.',1)
318 # if parent_cfg:
319 # if hasattr(parent_cfg,component):
320 # cfg = getattr(parent_cfg,component)
321 # else:
322 # cfg = ConfigurableGeneric(component)
323 # setattr(parent_cfg,component,cfg)
324 # else:
325 # cfg = ConfigurableGeneric(component)
326 # parent_cfg = cfg
327
328 # remove spaces around dots
329 property = '.'.join([w.strip() for w in property.split('.')])
330 component, property = property.rsplit('.',1)
331 if component in Configurable.allConfigurables:
332 cfg = Configurable.allConfigurables[component]
333 else:
334 cfg = ConfigurableGeneric(component)
335
336 #value = os.path.expandvars(value)
337 value = value.replace('true','True').replace('false','False')
338 if value[0] == '{' :
339 # Try to guess if the values looks like a dictionary
340 if ':' in value and not ( value[:value.index(':')].count('"')%2 or value[:value.index(':')].count("'")%2 ) :
341 # for dictionaries, keep the surrounding {}
342 value = '{'+value[1:-1].replace('{','[').replace('}',']')+'}'
343 else : # otherwise replace all {} with []
344 value = value.replace('{','[').replace('}',']')
345
346 # We must escape '\' because eval tends to interpret them
347 value = value.replace('\\', '\\\\')
348 # Restore special cases ('\n', '\t' and '\"') (see GAUDI-1001)
349 value = (value.replace(r"\\n", r"\n")
350 .replace(r"\\t", r"\t")
351 .replace(r'\\"', r'\"'))
352 # replace r'\n' and r'\t' that are outside double quoted strings
353 value = '"'.join([(v if i % 2 else re.sub(r'\\[nt]', ' ', v))
354 for i, v in enumerate(value.split('"'))])
355
356 # interprete the @ operator
357 m = self.reference.match(value)
358 if m:
359 # this allows late binding of references
360 value = PropertyReference(m.group(1))
361 else:
362 value = eval(value,self.units)
363
364 #if type(value) is str : value = os.path.expandvars(value)
365 #elif type(value) is list : value = [ type(item) is str and os.path.expandvars(item) or item for item in value ]
366
367 if property not in cfg.__slots__ and not hasattr(cfg,property):
368 # check if the case of the property is wrong (old options are case insensitive)
369 lprop = property.lower()
370 for p in cfg.__slots__:
371 if lprop == p.lower():
372 _log.warning("property '%s' was requested for %s, but the correct spelling is '%s'", property, cfg.name(), p)
373 property = p
374 break
375
376 # consider the += and -=
377 if inc == "+":
378 if hasattr(cfg,property):
379 prop = getattr(cfg,property)
380 if type(prop) == dict:
381 for k in value:
382 prop[k] = value[k]
383 else:
384 prop += value
385 else:
386 setattr(cfg,property,value)
387 elif inc == "-":
388 if hasattr(cfg,property):
389 prop = getattr(cfg,property)
390 if type(prop) is dict:
391 for k in value:
392 if k in prop:
393 del prop[k]
394 else:
395 _log.warning("key '%s' not in %s.%s", k, cfg.name(), property)
396 else:
397 for k in value:
398 if k in prop:
399 prop.remove(k)
400 else:
401 _log.warning("value '%s' not in %s.%s", k, cfg.name(), property)
402 else:
403 setattr(cfg,property,value)
404
GaudiKernel.ProcessJobOptions.JobOptsParser._eval_statement
def _eval_statement(self, statement)
Definition: ProcessJobOptions.py:297
gaudirun.type
string type
Definition: gaudirun.py:151

def GaudiKernel.ProcessJobOptions.JobOptsParser._parse_units | ( |  | self,
|  |  | file
| ) |  |
| private

Definition at line 285 of file ProcessJobOptions.py.

285 def _parse_units(self,file):
286 for line in open(file):
287 if '//' in line:
288 line = line[:line.index('//')]
289 line = line.strip()
290 if not line:
291 continue
292 nunit, value = line.split('=')
293 factor, unit = nunit.split()
294 value = eval(value)/eval(factor)
295 self.units[unit] = value
296
GaudiKernel.ProcessJobOptions.JobOptsParser._parse_units
def _parse_units(self, file)
Definition: ProcessJobOptions.py:285

## Member Data Documentation

tuple GaudiKernel.ProcessJobOptions.JobOptsParser.comment = re.compile(r'(//.*)$')
| static

Definition at line 133 of file ProcessJobOptions.py.

tuple GaudiKernel.ProcessJobOptions.JobOptsParser.comment_in_string
| static

Definition at line 136 of file ProcessJobOptions.py.

tuple GaudiKernel.ProcessJobOptions.JobOptsParser.i = l.index(self.statement_sep)
| static

Definition at line 272 of file ProcessJobOptions.py.

GaudiKernel.ProcessJobOptions.JobOptsParser.in_string = False
| static

Definition at line 252 of file ProcessJobOptions.py.

tuple GaudiKernel.ProcessJobOptions.JobOptsParser.l = l[string_end+1:]
| static

Definition at line 251 of file ProcessJobOptions.py.

string GaudiKernel.ProcessJobOptions.JobOptsParser.l = ''
| static

Definition at line 255 of file ProcessJobOptions.py.

tuple GaudiKernel.ProcessJobOptions.JobOptsParser.l = f.readline()
| static

Definition at line 268 of file ProcessJobOptions.py.

list GaudiKernel.ProcessJobOptions.JobOptsParser.statement = l[i+1:]
| static

Definition at line 275 of file ProcessJobOptions.py.

string GaudiKernel.ProcessJobOptions.JobOptsParser.statement = ""
| static

Definition at line 279 of file ProcessJobOptions.py.

tuple GaudiKernel.ProcessJobOptions.JobOptsParser.string_start = l.find('"') if string_start >= 0: string_end = l.find('"', string_start + 1)
| static

Definition at line 257 of file ProcessJobOptions.py.

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

- GaudiKernel/python/GaudiKernel/ProcessJobOptions.py