diff options
author | Adam Young <ayoung@redhat.com> | 2010-08-13 17:56:16 -0400 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2010-08-13 17:56:16 -0400 |
commit | 3e6f0f5721f76977475792f09758f6b8dcc4ed4e (patch) | |
tree | 4ff874f431b047d525f5e6d460753ce6a6689831 | |
parent | 030b5dab93971495d8656f7886c29136e118a9e6 (diff) | |
download | freeipa-3e6f0f5721f76977475792f09758f6b8dcc4ed4e.tar.gz freeipa-3e6f0f5721f76977475792f09758f6b8dcc4ed4e.tar.xz freeipa-3e6f0f5721f76977475792f09758f6b8dcc4ed4e.zip |
From: Pavel Zuna <pzuna@redhat.com>
Date: Tue, 10 Aug 2010 16:41:28 -0400
Subject: [PATCH 2/6] Add a new INTERNAL plugin that exports plugin meta-data into JSON.
This is required for the webUI, since we're dropping Genshi. *ehm* :)
You can't use this command on the CLI. It takes one optional argument:
the name of an IPA object. If not specified, meta-data for all objects
are returned.
-rw-r--r-- | ipalib/plugins/internal.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py new file mode 100644 index 000000000..6f0c2cf10 --- /dev/null +++ b/ipalib/plugins/internal.py @@ -0,0 +1,65 @@ +# Authors: +# Pavel Zuna <pzuna@redhat.com> +# +# Copyright (c) 2010 Red Hat +# See file 'copying' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the gnu general public license as +# published by the free software foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but without any warranty; without even the implied warranty of +# merchantability or fitness for a particular purpose. See the +# gnu general public license for more details. +# +# You should have received a copy of the gnu general public license +# along with this program; if not, write to the Free Software +# Foundation, inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" +Plugins not accessible directly through the CLI, commands used internally +""" + +import json + +from ipalib import api, errors +from ipalib import Command +from ipalib import Str +from ipalib.output import Output +from ipalib.text import _ +from ipalib.util import json_serialize + +class json_metadata(Command): + """ + Export plugin meta-data for the webUI. + """ + INTERNAL = True + + takes_args = ( + Str('objname?', + doc=_('Name of object to export'), + ), + ) + + has_output = ( + Output('result', dict, doc=_('Dict of JSON encoded IPA Objects')), + ) + + def execute(self, objname): + if objname and objname in self.api.Object: + return dict( + result=dict( + ((objname, json_serialize(self.api.Object[objname])), ) + ) + ) + return dict( + result=dict( + (o.name, json_serialize(o)) for o in self.api.Object() + ) + ) + + def output_for_cli(self, textui, result, *args, **options): + print json.dumps(result, default=json_serialize) + +api.register(json_metadata) + |