home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / UpdateManager / fakegconf.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  1.8 KB  |  78 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. import os.path
  11.  
  12. class FakeGconf:
  13.     
  14.     def __init__(self):
  15.         self.CONFIG_FILE=os.path.expanduser("~/.update-manager-conf")
  16.         self.config = {}
  17.         try:
  18.             #execute python file which contains the dictionary called config
  19.             exec open (self.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.     def get_string(self, key):
  37.         key = self.keyname(key)
  38.         return self.config.setdefault(self.keyname(key), "")
  39.  
  40.     def set_string(self, key):
  41.         key = self.keyname(key)
  42.         self.config[key] = value
  43.  
  44.     # FIXME assume type is int for now
  45.     def get_pair(self, key, ta = None, tb = None):
  46.         key = self.keyname(key)
  47.         return self.config.setdefault(self.keyname(key), [400, 500])
  48.         
  49.     # FIXME assume type is int for now
  50.     def set_pair(self, key, ta, tb, a, b):
  51.         key = self.keyname(key)
  52.         self.config[key] = [a, b]
  53.  
  54.     #Save current dictionary to config file
  55.     def save(self):
  56.         file = open(self.CONFIG_FILE, "w")
  57.         data = "config = {"
  58.         for i in self.config:
  59.             data +=  "'"+i+"'" + ":" + str(self.config[i])+",\n"
  60.         data += "}"
  61.         file.write(data)
  62.         file.close()
  63.         
  64.  
  65. VALUE_INT = ""
  66.  
  67. fakegconf = FakeGconf()
  68.  
  69. def client_get_default():
  70.     return  fakegconf
  71.  
  72. def fakegconf_atexit():
  73.     fakegconf.save()
  74.  
  75. atexit.register(fakegconf_atexit)
  76.  
  77.  
  78.