Changeset View
Changeset View
Standalone View
Standalone View
pykolab/conf/__init__.py
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | def finalize_conf(self, fatal=True): | ||||
# - a customly supplied file (by customer) | # - a customly supplied file (by customer) | ||||
# - a file we write out | # - a file we write out | ||||
# - this python class | # - this python class | ||||
# | # | ||||
# Look, we want defaults | # Look, we want defaults | ||||
self.defaults = Defaults(self.plugins) | self.defaults = Defaults(self.plugins) | ||||
# But, they should be available in our class as well | # But, they should be available in our class as well | ||||
for option in self.defaults.__dict__.keys(): | for option in self.defaults.__dict__: | ||||
log.debug( | log.debug( | ||||
_("Setting %s to %r (from defaults)") % ( | _("Setting %s to %r (from defaults)") % ( | ||||
option, | option, | ||||
self.defaults.__dict__[option] | self.defaults.__dict__[option] | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
setattr(self, option, self.defaults.__dict__[option]) | setattr(self, option, self.defaults.__dict__[option]) | ||||
# This is where we check our parser for the defaults being set there. | # This is where we check our parser for the defaults being set there. | ||||
self.set_defaults_from_cli_options() | self.set_defaults_from_cli_options() | ||||
self.options_set_from_config() | self.options_set_from_config() | ||||
# Also set the cli options | # Also set the cli options | ||||
if hasattr(self, 'cli_keywords') and self.cli_keywords is not None: | if hasattr(self, 'cli_keywords') and self.cli_keywords is not None: | ||||
for option in self.cli_keywords.__dict__.keys(): | for option in self.cli_keywords.__dict__: | ||||
retval = False | retval = False | ||||
if hasattr(self, "check_setting_%s" % (option)): | if hasattr(self, "check_setting_%s" % (option)): | ||||
exec( | exec( | ||||
"retval = self.check_setting_%s(%r)" % ( | "retval = self.check_setting_%s(%r)" % ( | ||||
option, | option, | ||||
self.cli_keywords.__dict__[option] | self.cli_keywords.__dict__[option] | ||||
) | ) | ||||
) | ) | ||||
Show All 24 Lines | def finalize_conf(self, fatal=True): | ||||
setattr(self, option, self.cli_keywords.__dict__[option]) | setattr(self, option, self.cli_keywords.__dict__[option]) | ||||
def load_config(self, config): | def load_config(self, config): | ||||
""" | """ | ||||
Given a SafeConfigParser instance, loads a configuration | Given a SafeConfigParser instance, loads a configuration | ||||
file and checks, then sets everything it can find. | file and checks, then sets everything it can find. | ||||
""" | """ | ||||
for section in self.defaults.__dict__.keys(): | for section in self.defaults.__dict__: | ||||
if section == 'testing': | if section == 'testing': | ||||
continue | continue | ||||
if not config.has_section(section): | if not config.has_section(section): | ||||
continue | continue | ||||
for key in self.defaults.__dict__[section].keys(): | for key in self.defaults.__dict__[section]: | ||||
retval = False | retval = False | ||||
if not config.has_option(section, key): | if not config.has_option(section, key): | ||||
continue | continue | ||||
if isinstance(self.defaults.__dict__[section][key], int): | if isinstance(self.defaults.__dict__[section][key], int): | ||||
value = config.getint(section, key) | value = config.getint(section, key) | ||||
elif isinstance(self.defaults.__dict__[section][key], bool): | elif isinstance(self.defaults.__dict__[section][key], bool): | ||||
value = config.getboolean(section, key) | value = config.getboolean(section, key) | ||||
▲ Show 20 Lines • Show All 362 Lines • ▼ Show 20 Lines | def create_logger(self): | ||||
# Initialize logger | # Initialize logger | ||||
log = pykolab.logger.Logger( | log = pykolab.logger.Logger( | ||||
loglevel=loglevel, | loglevel=loglevel, | ||||
debuglevel=self.cli_keywords.debuglevel, | debuglevel=self.cli_keywords.debuglevel, | ||||
logfile=self.cli_keywords.logfile | logfile=self.cli_keywords.logfile | ||||
) | ) | ||||
def set_defaults_from_cli_options(self): | def set_defaults_from_cli_options(self): | ||||
for long_opt in self.cli_parser.__dict__['_long_opt'].keys(): | for long_opt in self.cli_parser.__dict__['_long_opt']: | ||||
if long_opt == "--help": | if long_opt == "--help": | ||||
continue | continue | ||||
setattr( | setattr( | ||||
self.defaults, | self.defaults, | ||||
self.cli_parser._long_opt[long_opt].dest, | self.cli_parser._long_opt[long_opt].dest, | ||||
self.cli_parser._long_opt[long_opt].default | self.cli_parser._long_opt[long_opt].default | ||||
) | ) | ||||
# But, they should be available in our class as well | # But, they should be available in our class as well | ||||
for option in self.cli_parser.defaults.keys(): | for option in self.cli_parser.defaults: | ||||
log.debug( | log.debug( | ||||
_("Setting %s to %r (from the default values for CLI options)") % ( | _("Setting %s to %r (from the default values for CLI options)") % ( | ||||
option, | option, | ||||
self.cli_parser.defaults[option] | self.cli_parser.defaults[option] | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 244 Lines • Show Last 20 Lines |