home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / UpdateManager / fakegconf.py < prev    next >
Encoding:
Python Source  |  2006-08-24  |  1.5 KB  |  70 lines

  1. # Copyright (c) 2006 Jani Monoses  <jani@ubuntu.com>
  2.  
  3. # This is a class which handles settings when the gconf library
  4. # is unavailable such as in a non-Gnome environment
  5. # The configuration is stored in python hash format which is sourced
  6. # at program start and dumped at exit
  7.  
  8. import string
  9. import atexit
  10.  
  11. CONFIG_FILE="/root/.update-manager-conf"
  12.  
  13. class FakeGconf:
  14.     
  15.     def __init__(self):
  16.         self.config = {}
  17.         try:
  18.             #execute python file which contains the dictionary called config
  19.             exec open (CONFIG_FILE) 
  20.             self.config = config
  21.         except:
  22.             pass
  23.  
  24.     #only get the 'basename' from the gconf key
  25.     def keyname(self, key):
  26.         return string.rsplit(key, '/', 1)[-1]
  27.     
  28.     def get_bool(self, key):
  29.         key = self.keyname(key)
  30.         return self.config.setdefault(self.keyname(key), True)
  31.  
  32.     def set_bool(self, key,value):
  33.         key = self.keyname(key)
  34.         self.config[key] = value
  35.  
  36.     # FIXME assume type is int for now
  37.     def get_pair(self, key, ta = None, tb = None):
  38.         key = self.keyname(key)
  39.         return self.config.setdefault(self.keyname(key), [400, 500])
  40.         
  41.     # FIXME assume type is int for now
  42.     def set_pair(self, key, ta, tb, a, b):
  43.         key = self.keyname(key)
  44.         self.config[key] = [a, b]
  45.  
  46.     #Save current dictionary to config file
  47.     def save(self):
  48.         file = open(CONFIG_FILE, "w")
  49.         data = "config = {"
  50.         for i in self.config:
  51.             data +=  "'"+i+"'" + ":" + str(self.config[i])+",\n"
  52.         data += "}"
  53.         file.write(data)
  54.         file.close()
  55.         
  56.  
  57. VALUE_INT = ""
  58.  
  59. fakegconf = FakeGconf()
  60.  
  61. def client_get_default():
  62.     return  fakegconf
  63.  
  64. def fakegconf_atexit():
  65.     fakegconf.save()
  66.  
  67. atexit.register(fakegconf_atexit)
  68.  
  69.  
  70.