Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""
Mimic `config` interface, read .gangarc file directly.
USE WITH CARE!
Disclaimer: It can be inaccurate, especially for value not set by user. The genuine mechanism will be able to handle these default values more correctly.
TODO: Use me https://pytest.org/latest/monkeypatch.html
Note: $GANGA_CONFIG_FILE can point to custom location, default to ~/.gangarc
Note: $GANGADIR can override GPI.config.Configuration.gangadir, This is mainly used by Jobtree mechanism outside Gaudi framework.
"""
#-------------------------------------------------------------------------------
""" Locate the fullpath to user's config file. Default to home's ~/.gangarc. Overridable by GANGA_CONFIG_FILE.
>>> _ = getfixture('res_gangarc') >>> gangarc_path() 'tests/res/gangarc_test'
""" if raise_exception: raise IOError('Missing gangarc file: '+path)
"""Helper method to return entire content of .gangarc"""
# @memorized # Not good for testing mulitple gangarc r""" Return entire raw string of given section.
>>> _ = getfixture('res_gangarc') >>> gangarc_section('TESTSECTION1') 'key1 = val1\nkey2 = val2\n#key2 = val2old\n# key3 = val3'
>>> gangarc_section('BAD') Traceback (most recent call last): ... ValueError: Unknown section: 'BAD'
"""
# @memorized """
>>> _ = getfixture('res_gangarc')
>>> gangarc_getraw('TESTSECTION1', 'key1') 'val1'
>>> gangarc_getraw('TESTSECTION1', 'BAD') Traceback (most recent call last): ... KeyError: 'Failed to determine request section:key. TESTSECTION1.BAD'
"""
#-------------------------------------------------------------------------------
"""
>>> _ = getfixture('res_gangarc') >>> config = Config() >>> config.TESTSECTION1.key1 'val1' >>> config.TESTSECTION1.key2 'val2' >>> config.Configuration.Batch 'LSF' >>> config.DIRAC.MaxDiracBulkJobs '2000'
"""
"""
## For 'gangadir', Prefer envvar >>> getfixture('testuser') >>> getfixture('res_gangarc') >>> Config().Configuration.gangadir '/home/testuser/gangadir'
>> monkeypatch.setenv('GANGADIR', '/some/path') >> Config().Configuration.gangadir '/some/path'
"""
## Override: gangadir return os.environ['GANGADIR'] ## Continue like normal except IOError, e: ## Fallback for Configuration.user if (self._name,key) == ('Configuration', 'user'): return os.environ['USER'] ## No fallback, raise raise e |