From ee24739a261c69fc792041925fc74a5f863ce3af Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 24 Dec 2007 04:50:42 -0800 Subject: Use a custom RawConfigParser config implementation, with a special order for the keys. --- gitosis/configutil.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) 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) + -- cgit v1.2.3