The Gaudi Framework  v33r1 (b1225454)
Gaudi.Main Namespace Reference

Classes

class  BootstrapHelper
 
class  gaudimain
 

Functions

def getAllOpts (explicit_defaults=False)
 
def toOpt (value)
 
def parseOpt (s)
 

Variables

 log = logging.getLogger(__name__)
 

Function Documentation

◆ getAllOpts()

def Gaudi.Main.getAllOpts (   explicit_defaults = False)

Definition at line 169 of file Main.py.

169 def getAllOpts(explicit_defaults=False):
170  from itertools import chain
171  # old conf
172  from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
173  old_opts = {}
174 
175  # some algorithms may be generater when we call "getValuedProperties"
176  # so we need a few iterations before we get the full list
177  # (see GaudiConfig.ControlFlow)
178  needed_conf = []
179  count = 0
180  new_count = -1
181  while count != new_count:
182  count = new_count
183  needed_conf = getNeededConfigurables()
184  new_count = len(needed_conf)
185  for n in needed_conf:
186  c = Configurable.allConfigurables[n]
187  if hasattr(c, 'getValuedProperties'):
188  c.getValuedProperties()
189 
190  for n in needed_conf:
191  c = Configurable.allConfigurables[n]
192  items = (chain(c.getDefaultProperties().items(),
193  c.getValuedProperties().items())
194  if explicit_defaults else c.getValuedProperties().items())
195  for p, v in items:
196  # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
197  if hasattr(Configurable, "PropertyReference") and type(
198  v) == Configurable.PropertyReference:
199  # this is done in "getFullName", but the exception is ignored,
200  # so we do it again to get it
201  v = v.__resolve__()
202  if isinstance(v, str):
203  # properly escape quotes in the string (see gaudi/Gaudi#78)
204  v = '"%s"' % v.replace('"', '\\"')
205  elif sys.version_info < (3, ) and isinstance(v, long):
206  v = '%d' % v # prevent pending 'L'
207  elif hasattr(v, '__opt_value__'):
208  v = v.__opt_value__()
209  old_opts['.'.join((n, p))] = str(v)
210 
211  import GaudiConfig2
212  opts = GaudiConfig2.all_options(explicit_defaults)
213 
214  conflicts = [
215  n for n in set(opts).intersection(old_opts) if opts[n] != old_opts[n]
216  ]
217  if conflicts:
218  conflicts.sort()
219  log.error('Some properties are set in old and new style configuration')
220  log.warning('name: old -> new')
221  for n in conflicts:
222  log.warning('%s: %s -> %s', n, old_opts[n], opts[n])
223  sys.exit(10)
224 
225  opts.update(old_opts)
226  return opts
227 
228 
getNeededConfigurables
Definition: Proxy.py:31
def getAllOpts(explicit_defaults=False)
Definition: Main.py:169

◆ parseOpt()

def Gaudi.Main.parseOpt (   s)
Helper to parse option strings to Python values.

Ideally it should just be "eval", but the string parser of Gaudi
is different from the Python one, so we get string options that
cannot be just evaluated.

>>> print(parseOpt('123'))
123
>>> print(parseOpt('"some\\n\\\\"text\\\\""'))
some
"text"
>>> print(parseOpt(''))
<BLANKLINE>

(see gaudi/Gaudi#78)

Definition at line 252 of file Main.py.

252 def parseOpt(s):
253  '''
254  Helper to parse option strings to Python values.
255 
256  Ideally it should just be "eval", but the string parser of Gaudi
257  is different from the Python one, so we get string options that
258  cannot be just evaluated.
259 
260  >>> print(parseOpt('123'))
261  123
262  >>> print(parseOpt('"some\\n\\\\"text\\\\""'))
263  some
264  "text"
265  >>> print(parseOpt(''))
266  <BLANKLINE>
267 
268  (see gaudi/Gaudi#78)
269  '''
270  import re
271  quoted_string = re.compile(r'^"(.*)"$', re.DOTALL)
272  # FIXME: this is needed because we cannot use repr for strings
273  # (see gaudi/Gaudi#78)
274  if not s: # pass through empty strings
275  return s
276  m = quoted_string.match(s)
277  if m:
278  return m.group(1).replace('\\"', '"')
279  return eval(s)
280 
281 
def parseOpt(s)
Definition: Main.py:252

◆ toOpt()

def Gaudi.Main.toOpt (   value)
Helper to convert values to old .opts format.

>>> print(toOpt('some "text"'))
"some \\"text\\""
>>> print(toOpt('first\\nsecond'))
"first
second"
>>> print(toOpt({'a': [1, 2, '3']}))
{"a": [1, 2, "3"]}

Definition at line 229 of file Main.py.

229 def toOpt(value):
230  '''
231  Helper to convert values to old .opts format.
232 
233  >>> print(toOpt('some "text"'))
234  "some \\"text\\""
235  >>> print(toOpt('first\\nsecond'))
236  "first
237  second"
238  >>> print(toOpt({'a': [1, 2, '3']}))
239  {"a": [1, 2, "3"]}
240  '''
241  if isinstance(value, six.string_types):
242  return '"{0}"'.format(value.replace('"', '\\"'))
243  elif isinstance(value, dict):
244  return '{{{0}}}'.format(', '.join(
245  '{0}: {1}'.format(toOpt(k), toOpt(v)) for k, v in value.items()))
246  elif hasattr(value, '__iter__'):
247  return '[{0}]'.format(', '.join(map(toOpt, value)))
248  else:
249  return repr(value)
250 
251 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
def toOpt(value)
Definition: Main.py:229
struct GAUDI_API map
Parametrisation class for map-like implementation.

Variable Documentation

◆ log

Gaudi.Main.log = logging.getLogger(__name__)

Definition at line 20 of file Main.py.