home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / BTpp-0.5.4-bin.exe / $INSTDIR / BT++.exe / ConfigFile.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-19  |  4.9 KB  |  159 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. from ConfigParser import ConfigParser
  5. cfg_default = {
  6.     'Paths': {
  7.         'Torrent': 'torrent',
  8.         'History': 'history',
  9.         'Incoming': 'incoming',
  10.         'Temp': 'temp' },
  11.     'Download': {
  12.         'AutoStart': 1,
  13.         'AutoPause': 0,
  14.         'MaxSimDown': 3,
  15.         'MaxSpeedDown': 0,
  16.         'MaxSpeedUp': 0,
  17.         'KeepUpload': 1 },
  18.     'Hash': {
  19.         'Background': 1,
  20.         'NumSimHash': 1,
  21.         'Strict': 0 },
  22.     'Bind': {
  23.         'Ip': '',
  24.         'PortMin': 6881,
  25.         'PortMax': 7881 },
  26.     'LookFeel': {
  27.         'ConfirmExit': 0,
  28.         'TPAuto': 0,
  29.         'TPWord': '' },
  30.     'GUI': {
  31.         'WndPosX': -1,
  32.         'WndPosY': -1,
  33.         'WndSizeX': 800,
  34.         'WndSizeY': 450,
  35.         'GridCol0': 230,
  36.         'GridCol1': 80,
  37.         'GridCol2': 80,
  38.         'GridCol3': 90,
  39.         'GridCol4': 120,
  40.         'GridCol5': 70,
  41.         'GridCol6': 90,
  42.         'GridCol7': 90,
  43.         'HistCol0': 230,
  44.         'HistCol1': 80,
  45.         'HistCol2': 80,
  46.         'HistCol3': 70,
  47.         'HistCol4': 120 } }
  48.  
  49. class ConfigFile:
  50.     
  51.     def __init__(self):
  52.         self._File = None
  53.         self._Defaults = None
  54.  
  55.     
  56.     def Read(self, file):
  57.         self._File = file
  58.         self.Refresh()
  59.  
  60.     
  61.     def InstallDefaults(self, defaults):
  62.         self._Defaults = defaults
  63.  
  64.     
  65.     def Refresh(self):
  66.         if self._File != None:
  67.             self._Config = ConfigParser()
  68.             self._Config.read([
  69.                 self._File])
  70.         
  71.  
  72.     
  73.     def Get(self, section, option):
  74.         if self._Defaults == None:
  75.             if not self._Config.has_option(section, option):
  76.                 return self._Defaults[section][option]
  77.             
  78.             return self._Config.get(section, option)
  79.         elif not self._Config.has_option(section, option):
  80.             return self._Defaults[section][option]
  81.         
  82.         var = self._Config.get(section, option)
  83.         typ = type(self._Defaults[section][option])
  84.         if typ == type(0):
  85.             if var:
  86.                 return int(var)
  87.             else:
  88.                 return 0
  89.         
  90.         if typ == type(0.0):
  91.             if var:
  92.                 return float(var)
  93.             else:
  94.                 return 0.0
  95.         
  96.         return var
  97.  
  98.     
  99.     def Set(self, section, option, value):
  100.         value = str(value)
  101.         if not self._Config.has_section(section):
  102.             self._Config.add_section(section)
  103.         
  104.         self._Config.set(section, option, value)
  105.  
  106.     
  107.     def Save(self):
  108.         fp = open(self._File, 'w')
  109.         self._Config.write(fp)
  110.         fp.close()
  111.         Config.Refresh()
  112.  
  113.     
  114.     def DelSection(self, section):
  115.         if self._Config.has_section(section):
  116.             self._Config.remove_section(section)
  117.         
  118.  
  119.     
  120.     def DelOption(self, section, option):
  121.         if self._Config.has_section(section):
  122.             self._Config.remove_option(section, option)
  123.         
  124.  
  125.     
  126.     def HasOption(self, section, option):
  127.         if not self._Config.has_section(section):
  128.             return 0
  129.         
  130.         return self._Config.has_option(section, option)
  131.  
  132.     
  133.     def GetSections(self):
  134.         return self._Config.sections()
  135.  
  136.     
  137.     def GetOptions(self, section):
  138.         if not self._Config.has_section(section):
  139.             return []
  140.         
  141.         return self._Config.options(section)
  142.  
  143.     
  144.     def GetMap(self, section):
  145.         if not self._Config.has_section(section):
  146.             return { }
  147.         
  148.         dic = { }
  149.         opt = self._Config.options(section)
  150.         for o in opt:
  151.             dic[o] = self.Get(section, o)
  152.         
  153.         return dic
  154.  
  155.  
  156. Config = ConfigFile()
  157. Config.Read('preferences.ini')
  158. Config.InstallDefaults(cfg_default)
  159.