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