summaryrefslogtreecommitdiffstats
path: root/ipalib/base.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-07-19 08:31:46 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-07-19 08:31:46 +0000
commit26c9f4c8818e9904dab838ac95839c0d527219b8 (patch)
tree3d83f1d2bbab8508e7b5ff2904300e097fb07645 /ipalib/base.py
parent91adc9c2d060b65d96a8515d08fc7192be79da83 (diff)
downloadfreeipa-26c9f4c8818e9904dab838ac95839c0d527219b8.tar.gz
freeipa-26c9f4c8818e9904dab838ac95839c0d527219b8.tar.xz
freeipa-26c9f4c8818e9904dab838ac95839c0d527219b8.zip
7: Roughed out API.finalize(); added corresponding unit tests
Diffstat (limited to 'ipalib/base.py')
-rw-r--r--ipalib/base.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/ipalib/base.py b/ipalib/base.py
index 97fb7c90c..51324f938 100644
--- a/ipalib/base.py
+++ b/ipalib/base.py
@@ -158,7 +158,7 @@ class NameSpace(object):
class API(object):
- __commands = None
+ __cmd = None
__objects = None
__locked = False
@@ -171,9 +171,9 @@ class API(object):
return self.__objects
objects = property(__get_objects)
- def __get_commands(self):
- return self.__commands
- commands = property(__get_commands)
+ def __get_cmd(self):
+ return self.__cmd
+ cmd = property(__get_cmd)
def __merge(self, base, cls, override):
assert issubclass(base, Named)
@@ -184,17 +184,24 @@ class API(object):
raise exceptions.DuplicateError(cls.__name__, id(cls))
if cls.__name__ in self.__names and not override:
raise exceptions.OverrideError(cls.__name__)
+ prefix = base.prefix
+ assert cls.__name__.startswith(prefix)
self.__classes.add(cls)
self.__names.add(cls.__name__)
- if base not in self.__stage:
- self.__stage[base.prefix] = {}
- self.__stage[base.prefix][cls.__name__] = cls
+ if prefix not in self.__stage:
+ self.__stage[prefix] = {}
+ self.__stage[prefix][cls.__name__] = cls
def register_command(self, cls, override=False):
self.__merge(Command, cls, override)
def finalize(self):
- pass
- #i = cls()
- #assert cls.__name__ == (base.prefix + '_' + i.name)
+ for (prefix, d) in self.__stage.items():
+ n = {}
+ for cls in d.values():
+ i = cls()
+ assert cls.__name__ == (prefix + '_' + i.name)
+ n[i.name] = i
+ if prefix == 'cmd':
+ self.__cmd = NameSpace(n)