From e91392536994ce3167a1f025e819926ba6de299f Mon Sep 17 00:00:00 2001 From: David Kupka Date: Thu, 4 Aug 2016 16:14:33 +0200 Subject: [PATCH] Access data for help separately To avoid the need to read all data for a plugin from cache and actualy use the separately stored help data it must be requested and returned separately. https://fedorahosted.org/freeipa/ticket/6048 Reviewed-By: Jan Cholasta --- ipaclient/remote_plugins/schema.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py index c62b74408b448faf794ed9e2b315b03fc1a5a315..c72109ac3bb9b7a71f9cbc056eaf3a4d8371d035 100644 --- a/ipaclient/remote_plugins/schema.py +++ b/ipaclient/remote_plugins/schema.py @@ -114,10 +114,9 @@ class _SchemaPlugin(object): if self._class is not None: return self._class.summary else: - self._schema.load_help() - schema = self._schema[self.schema_key][self.full_name] + halp = self._schema[self.schema_key].get_help(self.full_name) try: - return schema['summary'] + return halp['summary'] except KeyError: return u'<%s>' % self.full_name @@ -244,10 +243,9 @@ class _SchemaCommandPlugin(_SchemaPlugin): if self._class is not None: return self._class.topic else: - self._schema.load_help() - schema = self._schema[self.schema_key][self.full_name] + halp = self._schema[self.schema_key].get_help(self.full_name) try: - return str(schema['topic_topic']).partition('/')[0] + return str(halp['topic_topic']).partition('/')[0] except KeyError: return None @@ -256,9 +254,8 @@ class _SchemaCommandPlugin(_SchemaPlugin): if self._class is not None: return self._class.NO_CLI else: - self._schema.load_help() - schema = self._schema[self.schema_key][self.full_name] - return 'cli' in schema.get('exclude', []) + halp = self._schema[self.schema_key].get_help(self.full_name) + return 'cli' in halp.get('exclude', []) def _create_output(self, api, schema): if schema.get('multivalue', False): @@ -355,6 +352,12 @@ class _SchemaNameSpace(collections.Mapping): def __len__(self): return len(list(self._schema.iter_namespace(self.name))) + def get_help(self, key): + try: + return self._schema.get_help(self.name, key) + except KeyError: + raise KeyError(key) + class NotAvailable(Exception): pass @@ -523,7 +526,7 @@ class Schema(object): for name in schema.namelist(): ns, _slash, key = name.partition('/') if ns in self.namespaces: - self._dict[ns][key] = {} + self._dict[ns][key] = None def __getitem__(self, key): try: @@ -557,7 +560,7 @@ class Schema(object): os.makedirs(self._DIR) except EnvironmentError as e: if e.errno != errno.EEXIST: - logger.warning("Failed ti write schema: {}".format(e)) + logger.warning("Failed to write schema: {}".format(e)) return with self._open_schema(self._fingerprint, 'w') as schema: @@ -580,24 +583,20 @@ class Schema(object): def read_namespace_member(self, namespace, member): value = self._dict[namespace][member] - if (not value) or ('full_name' not in value): + if value is None: path = '{}/{}'.format(namespace, member) - value = self._dict[namespace].setdefault( - member, {} - ).update(self._read(path)) + value = self._dict[namespace][member] = self._read(path) return value def iter_namespace(self, namespace): return iter(self._dict[namespace]) - def load_help(self): + def get_help(self, namespace, member): if not self._help: self._help = self._read('_help') - for ns in self._help: - for member in self._help[ns]: - self._dict[ns][member].update(self._help[ns][member]) + return self._help[namespace][member] def get_package(api, client): -- 2.7.4