From ed63bc5435723d408fa1ef8681a0faf863f63d11 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 20 Aug 2004 06:58:25 +0000 Subject: [PATCH] I think there are bugs here, some tests are failing, but it's late and I can't figure out why. --- src/registry.py | 51 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/registry.py b/src/registry.py index 59711b054..982a83ce4 100644 --- a/src/registry.py +++ b/src/registry.py @@ -67,7 +67,6 @@ def open(filename, clear=False): for (i, line) in enumerate(fd): line = line.rstrip('\r\n') try: - #print '***', repr(line) (key, value) = re.split(r'(?', _cache[name] self.set(_cache[name]) if self._supplyDefault: + # We do this because otherwise these values won't get registered, + # and thus won't be saved unless they're used. That's baaaaaaad. for (k, v) in _cache.iteritems(): - if k.startswith(self._name): - group = split(k)[-1] - try: - self.__makeChild(group, v) - except InvalidRegistryValue: - # It's probably supposed to be registered later. - pass + if k.startswith(self._name) and k != self._name: + rest = k[len(self._name)+1:] # +1 for leftmost dot. + restGroups = split(rest) + if len(restGroups) == 1: + group = restGroups[0] + try: + self.__makeChild(group, v) + except InvalidRegistryValue: + # It's probably supposed to be registered later. + pass def register(self, name, node=None): if not isValidRegistryName(name): - raise InvalidRegistryName, name + raise InvalidRegistryName, repr(name) if node is None: - node = Group(self._supplyDefault) - if name not in self._children: # XXX Is this right? - self._children[name] = node - self.added.append(name) - names = split(self._name) - names.append(name) - fullname = join(names) - node.setName(fullname) + node = Group() + if name in self._children: + # It's already here, let's copy some stuff over. + oldNode = self._children[name] + node._added = oldNode._added + node._children = oldNode._children + self._children[name] = node + if name not in self._added: + self._added.append(name) + names = split(self._name) + names.append(name) + fullname = join(names) + node.setName(fullname) return node def unregister(self, name): try: node = self._children[name] del self._children[name] - self.added.remove(name) + self._added.remove(name) if node._name in _cache: del _cache[node._name] return node @@ -229,7 +236,7 @@ class Group(object): def getValues(self, getChildren=False, fullNames=True): L = [] - for name in self.added: + for name in self._added: node = self._children[name] if hasattr(node, 'value') or hasattr(node, 'help'): if node.__class__ is not self.X: