summaryrefslogtreecommitdiffstats
path: root/ipalib/frontend.py
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2012-05-30 12:55:08 +0200
committerPetr Vobornik <pvoborni@redhat.com>2012-06-07 11:22:15 +0200
commit88170087e1470fd91b8c8867004070cf883d3828 (patch)
treef4474d501fe7cb862db78190931c1a737748d77f /ipalib/frontend.py
parente3d171126f7771c5434b05ea241d76adfff38835 (diff)
downloadfreeipa-88170087e1470fd91b8c8867004070cf883d3828.tar.gz
freeipa-88170087e1470fd91b8c8867004070cf883d3828.tar.xz
freeipa-88170087e1470fd91b8c8867004070cf883d3828.zip
Change json serialization to serialize useful data
json_metadata command creates and sends metadata needed by Web UI. It uses __json__ method for serialization of commands, options, objects... . A lot of data sent was useless for Web UI and some usefull information were missing. We * mostly CLI specific option attribues are not send. * attributes evaluated to false or None are not send * options which are send are not got from takes_aptions attribute but by get_options() method. It finally sends usefull option collection for commands part of metadata. In the end the raw amount of data send is aproximately the same. This patch is needed for Web UI to determine which option it can use in which commands. https://fedorahosted.org/freeipa/ticket/2760
Diffstat (limited to 'ipalib/frontend.py')
-rw-r--r--ipalib/frontend.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index e8a84eabe..10087ba24 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -1003,13 +1003,32 @@ class Command(HasParam):
# list of attributes we want exported to JSON
json_friendly_attributes = (
- 'name', 'takes_args', 'takes_options',
+ 'name', 'takes_args',
)
+ # list of options we want only to mention their presence and not to write
+ # their attributes
+ json_only_presence_options = (
+ 'all', 'raw', 'attrs', 'addattr', 'delattr', 'setattr', 'version',
+ )
+
+ def get_json_options(self):
+ """
+ Get only options we want exported to JSON
+ """
+ for option in self.get_options():
+ if option.name not in self.json_only_presence_options:
+ yield option
+ else:
+ yield { 'name': option.name }
+
def __json__(self):
json_dict = dict(
(a, getattr(self, a)) for a in self.json_friendly_attributes
)
+
+ json_dict['takes_options'] = list(self.get_json_options())
+
return json_dict
class LocalOrRemote(Command):