- def _parseKDEConfig(self, filename = KDE_CONFIG):
- fd = open(filename, 'r')
- result = collection.defaultdict(dict)
- section = None
- for line in fd:
- line = line.strip()
- if not line or line.startswith('#'):
- continue
-
- if line.startswith('[') and line.endswith(']'):
- section = line[1:-1]
- result[section] = {}
- continue
- elif not section:
- raise Exception('Invalid kdesktoprc file')
-
- unpack = line.split('=', 1)
- if len(unpack) == 2:
- key, val = unpack
- else:
- key, val = unpack[0], None
- result[section][key] = val
-
- fd.close()
- return result
-
- def _writeKDEConfig(self, config, filename = KDE_CONFIG):
- fd = open(filename, 'w')
- for section, values in config.items():
- print >>fd, '[%s]' % section
- for k, v in values.items():
- if v != None:
- print >>fd, '%s=%s' % (k,v)
- else:
- print >>fd, k
- print >>fd
- fd.close()
-