Exemple #1
0
def exe_logger_init(logcf):
    try:
        logger_init(logcf.error_log, logcf.log_level)
        return open_logfile(logcf.access_log)
    except IOError:
        raise ConfigError("cannot open logfile for write, \"{0}\"".format(
            excinst()))
    except ValueError:
        raise ConfigError("invalid log level")
Exemple #2
0
 def executor(self, targets=[]):
     """ For runner subclass access executor plugin. """
     if self._executor_plugin == None:
         plugins = PluginLoader(ExecutorPrototype, self.cfg.modules).plugins
         plugins += EXECUTORS
         for EXECUTOR in plugins:
             if EXECUTOR.name() == self.cfg.executor:
                 self._executor_plugin = EXECUTOR
                 LOG.info("using executor: <{0}>".format(EXECUTOR.name()))
                 break
         if self._executor_plugin == None:
             raise ConfigError(
                 "executor plugin <{0}> could not be loaded".format(
                     self.cfg.executor))
     if self._executor_plugin_opts == None:
         try:
             self._executor_plugin_opts = CONF.module(self.cfg.executor)
             LOG.info("executor plugin opts of <{0}> loaded".format(
                 self.cfg.executor))
         except ConfigError:
             self._executor_plugin_opts = {}
             LOG.warning(
                 "no executor opts configuration found for plugin <0>".
                 format(self.cfg.executor))
     try:
         return self._executor_plugin(
             targets, **self._executor_plugin_opts.dict_opts)
     except TypeError:
         raise ExecutorPrepareError("{0} bad executor implementate.".format(
             excinst()))
Exemple #3
0
 def merge(self, default_cfg_dict):
     cfg = deepcopy(default_cfg_dict)
     for opt, val in cfg.iteritems():
         try:
             self._opts[opt] = type(val)(self._opts[opt])
         except KeyError:
             pass
         except ValueError:
             raise ConfigError("bad value type of config opt \"{0}\".".format(opt))
     cfg.update(self._opts)
     self._opts = cfg
Exemple #4
0
 def __init__(self, worker, exe_conf="", **options):
     try:
         if not exe_conf:
             raise ConfigError(
                 "no config file given, "
                 "need parse exe conf before start celery worker.")
         cfgread(exe_conf)
         celery_init(worker.app)
     except ConfigError:
         LOG.error("error while try to parse config file, {0}".format(
             excinst()))
         sys.exit(1)
Exemple #5
0
def cfgread(config_file):
    """ ConfigFile reader, register sections to global `CONF` instance. """

    cfg = ConfigParser()
    if not hasattr(cfg, 'read_file'):
        cfg.read_file = cfg.readfp

    try:
        cfp = open(config_file)
        cfg.read_file(cfp)
        cfp.close()
    except:
        raise ConfigError("cannot open/read configfile, {0}".format(excinst()))

    for _cs in cfg.sections():
        CONF.regisiter_opts(_cs, dict(zip(
            [ c[0] for c in cfg.items(_cs) ],
            [ c[1].strip('\'').strip('"') for c in cfg.items(_cs) ])))

    return CONF
Exemple #6
0
 def __getattr__(self, attr):
     try:
         return self._opts[attr]
     except KeyError:
         raise ConfigError("\"{0}\" no such config option.".format(attr))
Exemple #7
0
 def regisiter_opts(self, cfg_name, cfg_dict):
     if self.ctx.has_key(cfg_name):
         raise ConfigError("duplicated config section \"{0}\".".format(cfg_name))
     self.ctx[cfg_name] = cfg_dict
Exemple #8
0
 def __getattr__(self, attr):
     try:
         return ModuleOpts(attr, self.ctx[attr])
     except KeyError:
         raise ConfigError("\"{0}\", no such config section.".format(attr))