X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/6ff491caab739113f212543e4a70a0773cf6ce37..2c5e4d6c412c1988b32cb7dbede988bc9dfb815d:/lib/python/Components/config.py diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 1afd398e..5507cae9 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -29,6 +29,7 @@ from time import localtime, strftime class ConfigElement(object): def __init__(self): self.saved_value = None + self.save_forced = False self.last_value = None self.save_disabled = False self.__notifiers = None @@ -83,7 +84,7 @@ class ConfigElement(object): # you need to override this if str(self.value) doesn't work def save(self): - if self.save_disabled or self.value == self.default: + if self.save_disabled or (self.value == self.default and not self.save_forced): self.saved_value = None else: self.saved_value = self.tostring(self.value) @@ -178,7 +179,7 @@ class choicesList(object): # XXX: we might want a better name for this def __list__(self): if self.type == choicesList.LIST_TYPE_LIST: - ret = [not isinstance(x, tuple) and x or len(x) > 0 and x[0] or len(x) == 0 and x for x in self.choices] + ret = [not isinstance(x, tuple) and x or x[0] for x in self.choices] else: ret = self.choices.keys() return ret or [""] @@ -1623,16 +1624,17 @@ class Config(ConfigSubsection): self.pickle_this("config", self.saved_value, result) return ''.join(result) - def unpickle(self, lines): + def unpickle(self, lines, base_file=True): tree = { } for l in lines: if not l or l[0] == '#': continue n = l.find('=') + name = l[:n] val = l[n+1:].strip() - names = l[:n].split('.') + names = name.split('.') # if val.find(' ') != -1: # val = val[:val.find(' ')] @@ -1643,6 +1645,15 @@ class Config(ConfigSubsection): base[names[-1]] = val + if not base_file: # not the initial config file.. + #update config.x.y.value when exist + try: + configEntry = eval(name) + if configEntry is not None: + configEntry.value = val + except (SyntaxError, KeyError): + pass + # we inherit from ConfigSubsection, so ... #object.__setattr__(self, "saved_value", tree["config"]) if "config" in tree: @@ -1650,13 +1661,16 @@ class Config(ConfigSubsection): def saveToFile(self, filename): text = self.pickle() - f = open(filename, "w") - f.write(text) - f.close() + try: + f = open(filename, "w") + f.write(text) + f.close() + except IOError: + print "Config: Couldn't write %s" % filename - def loadFromFile(self, filename): + def loadFromFile(self, filename, base_file=False): f = open(filename, "r") - self.unpickle(f.readlines()) + self.unpickle(f.readlines(), base_file) f.close() config = Config() @@ -1667,7 +1681,7 @@ class ConfigFile: def load(self): try: - config.loadFromFile(self.CONFIG_FILE) + config.loadFromFile(self.CONFIG_FILE, True) except IOError, e: print "unable to load config (%s), assuming defaults..." % str(e)