Changeset View
Changeset View
Standalone View
Standalone View
pykolab/conf/__init__.py
Show First 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | def check_config(self, val=None): | ||||
config_file = val | config_file = val | ||||
else: | else: | ||||
config_file = self.config_file | config_file = self.config_file | ||||
if not os.access(config_file, os.R_OK): | if not os.access(config_file, os.R_OK): | ||||
log.error(_("Configuration file %s not readable") % config_file) | log.error(_("Configuration file %s not readable") % config_file) | ||||
config = SafeConfigParser() | config = SafeConfigParser() | ||||
log.debug(_("Reading configuration file %s") % config_file, level=8) | log.debug(_("Setting default configuration options: %s") % config.sections(), level=8) | ||||
config.readfp(self.defaults.default_conf()) | |||||
try: | try: | ||||
log.debug(_("Reading configuration file %s") % config_file, level=8) | |||||
config.read(config_file) | config.read(config_file) | ||||
except: | except: | ||||
log.error(_("Invalid configuration file %s") % config_file) | log.error(_("Invalid configuration file %s") % config_file) | ||||
if not config.has_section("kolab"): | if not config.has_section("kolab"): | ||||
log.warning(_("No master configuration section [kolab] in configuration file %s") % config_file) | log.warning(_("No master configuration section [kolab] in configuration file %s") % config_file) | ||||
return config | return config | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | def run(self): | ||||
Run Forest, RUN! | Run Forest, RUN! | ||||
""" | """ | ||||
exitcode = 0 | exitcode = 0 | ||||
if self.cli_args: | if self.cli_args: | ||||
if len(self.cli_args) >= 1: | if len(self.cli_args) >= 1: | ||||
if hasattr(self,"command_%s" % self.cli_args[0].replace('-','_')): | if hasattr(self,"command_%s" % self.cli_args[0].replace('-','_')): | ||||
exec("self.command_%s(%r)" % (self.cli_args[0].replace('-','_'), self.cli_args[1:])) | exec("self.command_%s(%r)" % (self.cli_args[0].replace('-','_'), self.cli_args[1:])) | ||||
else: | else: | ||||
print >> sys.stderr, _("No command supplied") | print >> sys.stderr, _("No command supplied") | ||||
def command_dump(self, *args, **kw): | def command_dump(self, *args, **kw): | ||||
""" | """ | ||||
Dumps applicable, valid configuration that is not defaults. | Dumps applicable, valid configuration that is not defaults. | ||||
""" | """ | ||||
Show All 21 Lines | def command_dump(self, *args, **kw): | ||||
keys = self.cfg_parser.options(mode) | keys = self.cfg_parser.options(mode) | ||||
keys.sort() | keys.sort() | ||||
if self.cfg_parser.has_option(mode, 'leave_this_one_to_me'): | if self.cfg_parser.has_option(mode, 'leave_this_one_to_me'): | ||||
print "Ignoring section %s" % (mode,) | print "Ignoring section %s" % (mode,) | ||||
continue | continue | ||||
for key in keys: | for key in keys: | ||||
print "%s_%s = %s" % (mode, key ,self.cfg_parser.get(mode,key)) | print "%s_%s = %s" % (mode, key, self.cfg_parser.get(mode,key)) | ||||
def read_config(self, value=None): | def read_config(self, value=None): | ||||
""" | """ | ||||
Reads the configuration file, sets a self.cfg_parser. | Reads the configuration file, sets a self.cfg_parser. | ||||
""" | """ | ||||
if not value: | if not value: | ||||
value = self.defaults.config_file | value = self.defaults.config_file | ||||
if hasattr(self, 'cli_keywords') and not self.cli_keywords == None: | if hasattr(self, 'cli_keywords') and not self.cli_keywords == None: | ||||
value = self.cli_keywords.config_file | value = self.cli_keywords.config_file | ||||
self.cfg_parser = SafeConfigParser() | self.cfg_parser = SafeConfigParser() | ||||
self.cfg_parser.readfp(self.defaults.default_conf()) | |||||
self.cfg_parser.read(value) | self.cfg_parser.read(value) | ||||
if hasattr(self, 'cli_keywords') and hasattr(self.cli_keywords, 'config_file'): | if hasattr(self, 'cli_keywords') and hasattr(self.cli_keywords, 'config_file'): | ||||
self.cli_keywords.config_file = value | self.cli_keywords.config_file = value | ||||
self.defaults.config_file = value | |||||
self.config_file = value | self.config_file = value | ||||
def command_get(self, *args, **kw): | def command_get(self, *args, **kw): | ||||
""" | """ | ||||
Get a configuration option. | Get a configuration option. | ||||
Pass me a section and key please. | Pass me a section and key please. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 285 Lines • Show Last 20 Lines |