X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=time-slider.git;a=blobdiff_plain;f=usr%2Fshare%2Ftime-slider%2Flib%2Ftime_slider%2Flinux%2Ftimesliderconfig.py;h=b656f73cea76cf29e6b1e0e314ad30a542efb542;hp=453abc6e2103970c887970bf206701d9a3c33e53;hb=75feb72a4aa1bf0940b4b2eaddd68c781cdf50ee;hpb=687811925a387da3dca170ff0cf0d5fbf661cfd5 diff --git a/usr/share/time-slider/lib/time_slider/linux/timesliderconfig.py b/usr/share/time-slider/lib/time_slider/linux/timesliderconfig.py index 453abc6..b656f73 100644 --- a/usr/share/time-slider/lib/time_slider/linux/timesliderconfig.py +++ b/usr/share/time-slider/lib/time_slider/linux/timesliderconfig.py @@ -20,8 +20,9 @@ # CDDL HEADER END # -import ConfigParser +import configparser import sys +import time_slider.util as util # Default config file name position configfile = "/etc/time-slider/timesliderd.conf" @@ -68,24 +69,32 @@ default_properties = { }, } +class MyConfigParser(configparser.ConfigParser): + def __init__(self): + configparser.ConfigParser.__init__(self) + + for section, content in default_properties.items(): + if not self.has_section(section): + self.add_section(section) + for k,v in content.items(): + self.set(section, k, str(v)) + class Config: def __init__(self): - self.config = ConfigParser.ConfigParser() + self.config = MyConfigParser() self.config.read(configfile) def get(self, section, option): try: result = self.config.get(section, option) - sys.stderr.write('CONFIG: FILE section %s, option %s with value %s\n' % (section, option, result)) + util.debug('CONFIG: GET section %s, option %s with value %s\n' % (section, option, result), 1) return result - except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): - try: - result = default_properties[section][option] - sys.stderr.write('CONFIG: DEFAULT section %s, option %s with value %s\n' % (section, option, result)) - return result - except KeyError: - sys.stderr.write('CONFIG: NOTFOUND section %s, option %s\n' % (section, option)) - return '' + except (configparser.NoOptionError, configparser.NoSectionError): + util.debug('CONFIG: NOTFOUND section %s, option %s\n' % (section, option), 1) + return '' def sections(self): return self.config.sections() + +def configdump(): + MyConfigParser().write(sys.stdout)