X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fpython%2FComponents%2Fconfig.py;h=5507cae9493b23fcc5217416bda5a3404b85d186;hp=d7506e31a275a0fb9a03a62b7cfabdd12b840df4;hb=e7c018fc484ad4263c2e7156d1ab58d1f5f67bda;hpb=905ec92277bf423670ddf0c24a26c2b31483e9c7 diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index d7506e3..5507cae 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -1624,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(' ')] @@ -1644,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: @@ -1651,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() @@ -1668,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)