diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-08 21:37:02 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-08 21:37:02 +0000 |
commit | e74713a076a72e75d6ca44d12df8500fb5cad8d2 (patch) | |
tree | 021c4af1ac13b0e021e936efa6c1d7841cd8582f /ipalib | |
parent | 641403278e00c30f24d9a6b4938b1e4ab3ecb427 (diff) | |
download | freeipa-e74713a076a72e75d6ca44d12df8500fb5cad8d2.tar.gz freeipa-e74713a076a72e75d6ca44d12df8500fb5cad8d2.tar.xz freeipa-e74713a076a72e75d6ca44d12df8500fb5cad8d2.zip |
267: Finished builtin CLI api command
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/cli.py | 37 | ||||
-rw-r--r-- | ipalib/plugable.py | 5 |
2 files changed, 34 insertions, 8 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 05acad92..e4de6031 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -27,6 +27,7 @@ import code import optparse import public import errors +import plugable def to_cli(name): @@ -70,6 +71,37 @@ class console(public.Application): class print_api(public.Application): 'Print details on the loaded plugins.' + def __call__(self): + lines = self.__traverse() + ml = max(len(l[1]) for l in lines) + for line in lines: + if line[0] == 0: + print '' + print '%s%s %r' % ( + ' ' * line[0], + line[1].ljust(ml), + line[2], + ) + + def __traverse(self): + lines = [] + for name in self.api: + namespace = self.api[name] + self.__traverse_namespace(name, namespace, lines) + return lines + + def __traverse_namespace(self, name, namespace, lines, tab=0): + lines.append((tab, name, namespace)) + for member_name in namespace: + member = namespace[member_name] + lines.append((tab + 1, member_name, member)) + if not hasattr(member, '__iter__'): + continue + for n in member: + attr = member[n] + if isinstance(attr, plugable.NameSpace): + self.__traverse_namespace(n, attr, lines, tab + 2) + class KWCollector(object): def __init__(self): @@ -89,7 +121,6 @@ class KWCollector(object): return dict(self.__d) - class CLI(object): __d = None __mcl = None @@ -184,8 +215,6 @@ class CLI(object): error = e.error cmd(*args, **kw) - - def parse(self, cmd, argv): parser = self.build_parser(cmd) (kwc, args) = parser.parse_args(argv, KWCollector()) @@ -202,8 +231,6 @@ class CLI(object): ) return parser - - def __get_mcl(self): """ Returns the Max Command Length. diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 9880b0a0..761d8a95 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -354,7 +354,7 @@ class Plugin(ReadOnly): Returns a fully qualified module_name.class_name() representation that could be used to construct this Plugin instance. """ - return '%s.%s()' % ( + return '%s.%s' % ( self.__class__.__module__, self.__class__.__name__ ) @@ -450,11 +450,10 @@ class PluginProxy(SetProxy): Returns a Python expression that could be used to construct this Proxy instance given the appropriate environment. """ - return '%s(%s, %r, %r)' % ( + return '%s(%s, %r)' % ( self.__class__.__name__, self.__base.__name__, self.__target, - self.__name_attr, ) |