diff --git a/ipalib/cli.py b/ipalib/cli.py index 05acad929..e4de60310 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 9880b0a08..761d8a955 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, )