summaryrefslogtreecommitdiffstats
path: root/ipaclient/remote_plugins/schema.py
diff options
context:
space:
mode:
authorDavid Kupka <dkupka@redhat.com>2016-07-20 13:23:33 +0200
committerJan Cholasta <jcholast@redhat.com>2016-08-03 16:32:39 +0200
commit29f7f822aba674ebc4184ecc126854adb4330a89 (patch)
tree27e2da44c822334e41b1dc9ecd13d78d10840bfa /ipaclient/remote_plugins/schema.py
parent47a693d17430e82787d9704637c022a2fcac531a (diff)
downloadfreeipa-29f7f822aba674ebc4184ecc126854adb4330a89.tar.gz
freeipa-29f7f822aba674ebc4184ecc126854adb4330a89.tar.xz
freeipa-29f7f822aba674ebc4184ecc126854adb4330a89.zip
frontend: Change doc, summary, topic and NO_CLI to class properties
Avoid need to instantiate all commands just to get information for displaying help. https://fedorahosted.org/freeipa/ticket/6048 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipaclient/remote_plugins/schema.py')
-rw-r--r--ipaclient/remote_plugins/schema.py53
1 files changed, 47 insertions, 6 deletions
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index 70cd7536d..b183fa137 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -89,10 +89,32 @@ class _SchemaPlugin(object):
bases = None
schema_key = None
- def __init__(self, full_name):
+ def __init__(self, schema, full_name):
self.name, _slash, self.version = full_name.partition('/')
self.full_name = full_name
- self.__class = None
+ self._schema = schema
+ self._class = None
+
+ @property
+ def doc(self):
+ if self._class is not None:
+ return self._class.doc
+ else:
+ schema = self._schema[self.schema_key][self.full_name]
+ try:
+ return schema['doc']
+ except KeyError:
+ return None
+
+ @property
+ def summary(self):
+ if self._class is not None:
+ return self._class.summary
+ else:
+ if self.doc is not None:
+ return self.doc.split('\n\n', 1)[0].strip()
+ else:
+ return u'<%s>' % self.full_name
def _create_default_from(self, api, name, keys):
cmd_name = self.full_name
@@ -200,18 +222,37 @@ class _SchemaPlugin(object):
return self.name, self.bases, class_dict
def __call__(self, api):
- if self.__class is None:
+ if self._class is None:
schema = api._schema[self.schema_key][self.full_name]
name, bases, class_dict = self._create_class(api, schema)
- self.__class = type(name, bases, class_dict)
+ self._class = type(name, bases, class_dict)
- return self.__class(api)
+ return self._class(api)
class _SchemaCommandPlugin(_SchemaPlugin):
bases = (_SchemaCommand,)
schema_key = 'commands'
+ @property
+ def topic(self):
+ if self._class is not None:
+ return self._class.topic
+ else:
+ schema = self._schema[self.schema_key][self.full_name]
+ try:
+ return str(schema['topic_topic']).partition('/')[0]
+ except KeyError:
+ return None
+
+ @property
+ def NO_CLI(self):
+ if self._class is not None:
+ return self._class.NO_CLI
+ else:
+ schema = self._schema[self.schema_key][self.full_name]
+ return 'cli' in schema.get('exclude', [])
+
def _create_output(self, api, schema):
if schema.get('multivalue', False):
type_type = (tuple, list)
@@ -565,7 +606,7 @@ def get_package(api, client):
module.register = plugable.Registry()
for plugin_cls in (_SchemaCommandPlugin, _SchemaObjectPlugin):
for full_name in schema[plugin_cls.schema_key]:
- plugin = plugin_cls(str(full_name))
+ plugin = plugin_cls(schema, str(full_name))
plugin = module.register()(plugin)
sys.modules[module_name] = module