def get_engine(conf): try: enginepath = conf['nomad']['engine'] if '.' not in enginepath: enginepath = 'nomad.engine.' + enginepath except KeyError: raise NomadError('nomad.engine is not defined in config file') try: enginemod = __import__(enginepath, {}, {}, ['']) except ImportError as e: raise NomadError('cannot use engine %s: %s' % (enginepath, e)) try: url = geturl(conf['nomad']['url']) except KeyError: abort('database url was not found in the nomad Configuration') engine = getattr(enginemod, 'engine')(url) try: engine.connection except DBError as e: abort(e) return engine, url
def __init__(self, confpath, overrides=None): self.conf = ConfigParser(interpolation=ExtendedInterpolation(), defaults={ 'confpath': op.abspath(confpath), 'confdir': op.dirname(op.abspath(confpath)), }) self.conf.read_dict(self.DEFAULTS) if not self.conf.read([confpath]): raise IOError('configuration file %r not found' % confpath) for k, v in (overrides or {}).iteritems(): section, key = k.split('.') self.conf.set(section, key, v) self.path = self.conf.get('nomad', 'path', fallback=op.dirname(confpath) or '.') try: enginepath = self.conf['nomad']['engine'] except KeyError: raise NomadError('nomad.engine is not defined in config file') if not '.' in enginepath: enginepath = 'nomad.engine.' + enginepath try: enginemod = __import__(enginepath, {}, {}, ['']) except ImportError: raise NomadError('engine %s is unknown' % enginepath) self.engine = getattr(enginemod, 'engine')(geturl(self))
def __init__(self, confpath, overrides=None): self.conf = ConfigParser( interpolation=ExtendedInterpolation(), defaults={ 'confpath': op.abspath(confpath), 'confdir': op.dirname(op.abspath(confpath)), }) self.conf.read_dict(self.DEFAULTS) if not self.conf.read([confpath]): raise NomadIniNotFound(confpath) for k, v in (overrides or {}).iteritems(): section, key = k.split('.') self.conf.set(section, key, v) self.confpath = confpath self.path = self.conf.get('nomad', 'path', fallback=op.dirname(confpath) or '.') try: enginepath = self.conf['nomad']['engine'] if not '.' in enginepath: enginepath = 'nomad.engine.' + enginepath except KeyError: raise NomadError('nomad.engine is not defined in config file') try: enginemod = __import__(enginepath, {}, {}, ['']) except ImportError as e: raise NomadError('cannot use engine %s: %s' % (enginepath, e)) try: self.url = geturl(self.conf['nomad']['url']) except KeyError: abort('database url in %s is not found' % self) self.engine = getattr(enginemod, 'engine')(self.url) try: self.engine.connection except DBError as e: abort(e)