The Identity, Policy and Audit system
CentOS Sources
2016-11-03 403b09ab980c02ef36095973349a13e0181c794a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From e91392536994ce3167a1f025e819926ba6de299f Mon Sep 17 00:00:00 2001
From: David Kupka <dkupka@redhat.com>
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 <jcholast@redhat.com>
---
 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