From 99e04876f2b3eb1c6d9150ad0ac17ad8fc1f7e97 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 5 Apr 2006 14:48:32 +0200 Subject: * merged the patch from Jani for fakegconf --- UpdateManager/fakegconf.py | 61 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) (limited to 'UpdateManager') diff --git a/UpdateManager/fakegconf.py b/UpdateManager/fakegconf.py index fd465fa3..7e387b56 100644 --- a/UpdateManager/fakegconf.py +++ b/UpdateManager/fakegconf.py @@ -1,24 +1,69 @@ -# This is a class which contains stubs for the gconf methods -# used in Update Manager. When gconf is unavailable it will -# still work but not retain the user settings. +# Copyright (c) 2006 Jani Monoses + +# This is a class which handles settings when the gconf library +# is unavailable such as in a non-Gnome environment +# The configuration is stored in python hash format which is sourced +# at program start and dumped at exit + +import string +import atexit + +CONFIG_FILE="/root/.update-manager-conf" class FakeGconf: + + def __init__(self): + self.config = {} + try: + #execute python file which contains the dictionary called config + exec open (CONFIG_FILE) + self.config = config + except: + pass + #only get the 'basename' from the gconf key + def keyname(self, key): + return string.rsplit(key, '/', 1)[-1] + def get_bool(self, key): - return False + key = self.keyname(key) + return self.config.setdefault(self.keyname(key), True) def set_bool(self, key,value): - pass + key = self.keyname(key) + self.config[key] = value + # FIXME assume type is int for now def get_pair(self, key, ta = None, tb = None): - return [300,300] + key = self.keyname(key) + return self.config.setdefault(self.keyname(key), [400, 500]) + # FIXME assume type is int for now def set_pair(self, key, ta, tb, a, b): - pass + key = self.keyname(key) + self.config[key] = [a, b] + + #Save current dictionary to config file + def save(self): + file = open(CONFIG_FILE, "w") + data = "config = {" + for i in self.config: + data += "'"+i+"'" + ":" + str(self.config[i])+",\n" + data += "}" + file.write(data) + file.close() + VALUE_INT = "" +fakegconf = FakeGconf() + def client_get_default(): - return FakeGconf() + return fakegconf + +def fakegconf_atexit(): + fakegconf.save() + +atexit.register(fakegconf_atexit) -- cgit v1.2.3