home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import ConfigParser
- import cStringIO as StringIO
- import os.path as os
- from lpconstants import CONFIG
-
- class Config(dict):
- ''' Config system for python-launchpad-bugs
-
- this is working in layers, first the default values (CONFIG.DEFAULT)
- are used, hen the ones defined in the global config file located in
- CONFIG.FILE and at last the configuration set in the file with the
- given filename
- '''
- MAPPING = dict()
-
- def __init__(self, filename = None, ignore = None):
- d = { }
- self._Config__filename = filename
- self._Config__config = ConfigParser.ConfigParser()
- self._Config__config.readfp(StringIO.StringIO(CONFIG.DEFAULT))
-
- try:
- self._Config__config.read(CONFIG.FILE)
- except ConfigParser.MissingSectionHeaderError:
- if os.path.exists(CONFIG.FILE):
- f = file(CONFIG.FILE, 'r')
-
- try:
- self._Config__config.set('user', 'username', f.read().strip(' \n'))
- finally:
- f.close()
-
-
- except:
- os.path.exists(CONFIG.FILE)
-
- if self._Config__filename is not None:
- self._Config__config.read(self._Config__filename)
-
- ignore = self._create_ignore_dict(ignore)
- for section in self._Config__config.sections():
- d[section] = { }
- for key, value in self._Config__config.items(section):
- if key in ignore[section]:
- value = ''
-
-
- try:
- func = self.MAPPING[section][key][0]
- except (KeyError, IndexError):
- d[section][key] = value
- continue
-
- d[section][key] = func(value)
-
-
- dict.__init__(self, d)
-
-
- def save(self):
- for section in self._Config__config.sections():
- for key, value in self._Config__config.items(section):
-
- try:
- func = self.MAPPING[section][key][1]
- except (KeyError, IndexError):
- self._Config__config.set(section, key, self[section][key])
- continue
-
- self._Config__config.set(section, key, func(self[section][key]))
-
-
- if not self._Config__filename:
- pass
- f = file(CONFIG.FILE, 'w')
-
- try:
- f.write(CONFIG.COMMENT)
- self._Config__config.write(f)
- finally:
- f.close()
-
-
-
- def _create_ignore_dict(self, ignore_list):
- ret_dict = dict((lambda .0: for s in .0:
- (s, set()))(self._Config__config.sections()))
- if ignore_list is None:
- return ret_dict
- ignore = map((lambda x: x.split('.')), ignore_list)
- for i in ignore:
- if i[0] not in ret_dict:
- continue
-
-
- try:
- ret_dict[i[0]].add(i[1])
- continue
- except IndexError:
- ret_dict[i[0]] = set(self._Config__config.options(i[0]))
- continue
-
-
-
- return ret_dict
-
-
-