[ckan-changes] [okfn/ckan] dc7b7f: add paster command `plugin-info` to document insta...
GitHub
noreply at github.com
Mon Apr 23 16:01:57 UTC 2012
Branch: refs/heads/master
Home: https://github.com/okfn/ckan
Commit: dc7b7f6f820b0bda80ea610624922aab69d10764
https://github.com/okfn/ckan/commit/dc7b7f6f820b0bda80ea610624922aab69d10764
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-23 (Mon, 23 Apr 2012)
Changed paths:
M ckan/lib/cli.py
M ckan/plugins/toolkit.py
M setup.py
Log Message:
-----------
add paster command `plugin-info` to document installed plugins
diff --git a/ckan/lib/cli.py b/ckan/lib/cli.py
index 6798cc4..fd52cc6 100644
--- a/ckan/lib/cli.py
+++ b/ckan/lib/cli.py
@@ -879,3 +879,96 @@ def clean(self, user_ratings=True):
rating.purge()
model.repo.commit_and_remove()
+
+class PluginInfo(CkanCommand):
+ ''' Provide info on installed plugins.
+ '''
+
+ summary = __doc__.split('\n')[0]
+ usage = __doc__
+ max_args = 0
+ min_args = 0
+
+ def command(self):
+ self.get_info()
+
+ def get_info(self):
+ ''' print info about current plugins from the .ini file'''
+ import ckan.plugins as p
+ self._load_config()
+ interfaces = {}
+ plugins = {}
+ for name in dir(p):
+ item = getattr(p, name)
+ try:
+ if issubclass(item, p.Interface):
+ interfaces[item] = {'class' : item}
+ except TypeError:
+ pass
+
+ for interface in interfaces:
+ for plugin in p.PluginImplementations(interface):
+ name = plugin.name
+ if name not in plugins:
+ plugins[name] = {'doc' : plugin.__doc__,
+ 'class' : plugin,
+ 'implements' : []}
+ plugins[name]['implements'].append(interface.__name__)
+
+ for plugin in plugins:
+ p = plugins[plugin]
+ print plugin + ':'
+ print '-' * (len(plugin) + 1)
+ if p['doc']:
+ print p['doc']
+ print 'Implements:'
+ for i in p['implements']:
+ extra = None
+ if i == 'ITemplateHelpers':
+ extra = self.template_helpers(p['class'])
+ if i == 'IActions':
+ extra = self.actions(p['class'])
+ print ' %s' % i
+ if extra:
+ print extra
+ print
+
+
+ def actions(self, cls):
+ ''' Return readable action function info. '''
+ actions = cls.get_actions()
+ return self.function_info(actions)
+
+ def template_helpers(self, cls):
+ ''' Return readable helper function info. '''
+ helpers = cls.get_helpers()
+ return self.function_info(helpers)
+
+ def function_info(self, functions):
+ ''' Take a dict of functions and output readable info '''
+ import inspect
+ output = []
+ for function_name in functions:
+ fn = functions[function_name]
+ args_info = inspect.getargspec(fn)
+ params = args_info.args
+ num_params = len(params)
+ if args_info.varargs:
+ params.append('*' + args_info.varargs)
+ if args_info.keywords:
+ params.append('**' + args_info.keywords)
+ if args_info.defaults:
+ offset = num_params - len(args_info.defaults)
+ for i, v in enumerate(args_info.defaults):
+ params[i + offset] = params[i + offset] + '=' + repr(v)
+ # is this a classmethod if so remove the first parameter
+ if inspect.ismethod(fn) and inspect.isclass(fn.__self__):
+ params = params[1:]
+ params = ', '.join(params)
+ output.append(' %s(%s)' % (function_name, params))
+ # doc string
+ if fn.__doc__:
+ bits = fn.__doc__.split('\n')
+ for bit in bits:
+ output.append(' %s' % bit)
+ return ('\n').join(output)
diff --git a/ckan/plugins/toolkit.py b/ckan/plugins/toolkit.py
index 671449e..fa1f2c3 100644
--- a/ckan/plugins/toolkit.py
+++ b/ckan/plugins/toolkit.py
@@ -183,6 +183,8 @@ def __getattr__(self, name):
if name in self._toolkit:
return self._toolkit[name]
else:
+ if name == '__bases__':
+ return self.__class__.__bases__
raise Exception('`%s` not found in plugins toolkit' % name)
toolkit = _Toolkit()
diff --git a/setup.py b/setup.py
index 33f6d6b..cd37609 100644
--- a/setup.py
+++ b/setup.py
@@ -71,6 +71,7 @@
roles = ckan.lib.authztool:RolesCommand
celeryd = ckan.lib.cli:Celery
rdf-export = ckan.lib.cli:RDFExport
+ plugin-info = ckan.lib.cli:PluginInfo
[console_scripts]
ckan-admin = bin.ckan_admin:Command
================================================================
Commit: ce27ac5f28fb5dc3c233dc56eee8c88a60c5ead9
https://github.com/okfn/ckan/commit/ce27ac5f28fb5dc3c233dc56eee8c88a60c5ead9
Author: Toby <toby.junk at gmail.com>
Date: 2012-04-23 (Mon, 23 Apr 2012)
Changed paths:
M ckan/logic/converters.py
M requires/lucid_missing.txt
Log Message:
-----------
Merge branch 'master' of github.com:okfn/ckan
diff --git a/ckan/logic/converters.py b/ckan/logic/converters.py
index 5de75a7..6b927ae 100644
--- a/ckan/logic/converters.py
+++ b/ckan/logic/converters.py
@@ -60,13 +60,11 @@ def callable(key, data, errors, context):
context['vocabulary'] = v
for tag in new_tags:
- tag_length_validator(tag, context)
- tag_name_validator(tag, context)
tag_in_vocabulary_validator(tag, context)
for num, tag in enumerate(new_tags):
- data[('tags', num+n, 'name')] = tag
- data[('tags', num+n, 'vocabulary_id')] = v.id
+ data[('tags', num + n, 'name')] = tag
+ data[('tags', num + n, 'vocabulary_id')] = v.id
return callable
def convert_from_tags(vocab):
diff --git a/requires/lucid_missing.txt b/requires/lucid_missing.txt
index 8b5789e..dccb362 100644
--- a/requires/lucid_missing.txt
+++ b/requires/lucid_missing.txt
@@ -20,3 +20,4 @@ ofs==0.4.1
apachemiddleware==0.1.1
# markupsafe is required by webhelpers==1.2 required by formalchemy with SQLAlchemy 0.6
markupsafe==0.9.2
+celery==2.5.3
================================================================
Compare: https://github.com/okfn/ckan/compare/f4f506c...ce27ac5
More information about the ckan-changes
mailing list