-
-
-# Define HDF5- and YAML-backed subclasses of the basic _Config types.
-for name,obj in locals().items():
- if (obj != _Config and
- type(obj) == type and
- issubclass(obj, _Config) and
- not issubclass(obj, _BackedConfig)):
- for prefix,base in [('HDF5', _HDF5Config), ('YAML', _YAMLConfig)]:
- _name = '%s%s' % (prefix, name)
- _bases = (base, obj)
- _dict = {}
- _class = type(_name, _bases, _dict)
- setattr(_sys.modules[__name__], _name, _class)
-
-del name, obj, prefix, base, _name, _bases, _dict, _class
-
-
-def find_base_config():
- "Return the best `_BaseConfig` match after scanning the filesystem"
- _LOG.info('looking for base_config file')
- user_basepath = _os_path.join(_os_path.expanduser('~'), '.calibcantrc')
- system_basepath = _os_path.join('/etc', 'calibcant', 'config')
- distributed_basepath = _os_path.join(
- '/usr', 'share', 'calibcant', 'config')
- for basepath in [user_basepath, system_basepath, distributed_basepath]:
- for (extension, config) in [('.h5', HDF5_BaseConfig),
- ('.yaml', YAML_BaseConfig)]:
- filename = basepath + extension
- if _os_path.exists(filename):
- _LOG.info('base_config file found at %s' % filename)
- base_config = config(filename)
- base_config.load()
- return base_config
- else:
- _LOG.debug('no base_config file at %s' % filename)
- _LOG.info('new base_config file at %s' % filename)
- basepath = user_basepath
- filename = basepath + extension
- return config(filename)