home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.2)
-
- from ConfigParser import ConfigParser
- cfg_default = {
- 'Paths': {
- 'Torrent': 'torrent',
- 'History': 'history',
- 'Incoming': 'incoming',
- 'Temp': 'temp' },
- 'Download': {
- 'AutoStart': 1,
- 'AutoPause': 0,
- 'MaxSimDown': 3,
- 'MaxSpeedDown': 0,
- 'MaxSpeedUp': 0,
- 'KeepUpload': 1 },
- 'Hash': {
- 'Background': 1,
- 'NumSimHash': 1,
- 'Strict': 0 },
- 'Bind': {
- 'Ip': '',
- 'PortMin': 6881,
- 'PortMax': 7881 },
- 'LookFeel': {
- 'ConfirmExit': 0,
- 'TPAuto': 0,
- 'TPWord': '' },
- 'GUI': {
- 'WndPosX': -1,
- 'WndPosY': -1,
- 'WndSizeX': 800,
- 'WndSizeY': 450,
- 'GridCol0': 230,
- 'GridCol1': 80,
- 'GridCol2': 80,
- 'GridCol3': 90,
- 'GridCol4': 120,
- 'GridCol5': 70,
- 'GridCol6': 90,
- 'GridCol7': 90,
- 'HistCol0': 230,
- 'HistCol1': 80,
- 'HistCol2': 80,
- 'HistCol3': 70,
- 'HistCol4': 120 } }
-
- class ConfigFile:
-
- def __init__(self):
- self._File = None
- self._Defaults = None
-
-
- def Read(self, file):
- self._File = file
- self.Refresh()
-
-
- def InstallDefaults(self, defaults):
- self._Defaults = defaults
-
-
- def Refresh(self):
- if self._File != None:
- self._Config = ConfigParser()
- self._Config.read([
- self._File])
-
-
-
- def Get(self, section, option):
- if self._Defaults == None:
- if not self._Config.has_option(section, option):
- return self._Defaults[section][option]
-
- return self._Config.get(section, option)
- elif not self._Config.has_option(section, option):
- return self._Defaults[section][option]
-
- var = self._Config.get(section, option)
- typ = type(self._Defaults[section][option])
- if typ == type(0):
- if var:
- return int(var)
- else:
- return 0
-
- if typ == type(0.0):
- if var:
- return float(var)
- else:
- return 0.0
-
- return var
-
-
- def Set(self, section, option, value):
- value = str(value)
- if not self._Config.has_section(section):
- self._Config.add_section(section)
-
- self._Config.set(section, option, value)
-
-
- def Save(self):
- fp = open(self._File, 'w')
- self._Config.write(fp)
- fp.close()
- Config.Refresh()
-
-
- def DelSection(self, section):
- if self._Config.has_section(section):
- self._Config.remove_section(section)
-
-
-
- def DelOption(self, section, option):
- if self._Config.has_section(section):
- self._Config.remove_option(section, option)
-
-
-
- def HasOption(self, section, option):
- if not self._Config.has_section(section):
- return 0
-
- return self._Config.has_option(section, option)
-
-
- def GetSections(self):
- return self._Config.sections()
-
-
- def GetOptions(self, section):
- if not self._Config.has_section(section):
- return []
-
- return self._Config.options(section)
-
-
- def GetMap(self, section):
- if not self._Config.has_section(section):
- return { }
-
- dic = { }
- opt = self._Config.options(section)
- for o in opt:
- dic[o] = self.Get(section, o)
-
- return dic
-
-
- Config = ConfigFile()
- Config.Read('preferences.ini')
- Config.InstallDefaults(cfg_default)
-