diff options
author | 2007-12-24 04:50:42 -0800 | |
---|---|---|
committer | 2007-12-24 04:50:42 -0800 | |
commit | ee24739a261c69fc792041925fc74a5f863ce3af (patch) | |
tree | 50ba41af92b8979b43952ce3dd39e4f6dfaf71b1 | |
parent | Renable test. (diff) | |
download | gitosis-gentoo-ee24739a261c69fc792041925fc74a5f863ce3af.tar.gz gitosis-gentoo-ee24739a261c69fc792041925fc74a5f863ce3af.tar.bz2 gitosis-gentoo-ee24739a261c69fc792041925fc74a5f863ce3af.zip |
Use a custom RawConfigParser config implementation, with a special order for the keys.
-rw-r--r-- | gitosis/configutil.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/gitosis/configutil.py b/gitosis/configutil.py index 799c84b..42d7b18 100644 --- a/gitosis/configutil.py +++ b/gitosis/configutil.py @@ -1,7 +1,8 @@ """ Useful wrapper functions to access ConfigParser structures. """ -from ConfigParser import NoSectionError, NoOptionError +from ConfigParser import NoSectionError, NoOptionError, RawConfigParser +from UserDict import IterableUserDict def getboolean_default(config, section, option, default_value): """ @@ -13,3 +14,33 @@ def getboolean_default(config, section, option, default_value): except (NoSectionError, NoOptionError): value = default_value return value + +class GitosisConfigDict(IterableUserDict): + def keys(self): + return list(self.__iter__()) + def __iter__(self): + saw = set() + if 'gitosis' in self.data: + saw.add('gitosis') + yield 'gitosis' + sorted_keys = self.data.keys() + sorted_keys.sort() + for _ in sorted_keys: + if _.startswith('group '): + saw.add(_) + yield _ + for _ in sorted_keys: + if _.startswith('repo '): + saw.add(_) + yield _ + for _ in sorted_keys: + if _ not in saw: + saw.add(_) + yield _ + + +class GitosisRawConfigParser(RawConfigParser): + def __init__(self, defaults=None): + RawConfigParser.__init__(self, defaults) + self._sections = GitosisConfigDict(self._sections) + |