[ckan-dev] check for plugins

Stefan Oderbolz stefan.oderbolz at liip.ch
Thu Feb 23 09:41:48 UTC 2017


I'd agree with Ian that it would be preferable to avoid this situation
altogether.

But if you really need it, just two comments on your code:

1. Once the server is started, no new plugins will be loaded (or I don't
know a way to do this), so I would create the list at startup and not loop
through it for each call in the template
2. You now check for "loaded" plugins, i.e. those that implement any known
CKAN interface. Why not simply check the "ckan.plugins" value from the
config file? If one of those could not be found, CKAN anyway raises a
PluginNotFound exception
3. in ckan.plugins there is a method called plugin_loaded() (
https://github.com/ckan/ckan/blob/048632d73588ed462a1133e796681056fe89ef37/ckan/plugins/core.py#L213-L219)
that probably does what you're looking for

Best reagrds Stefan

On Wed, Feb 22, 2017 at 6:16 PM, Ian Ward <ian at excess.org> wrote:

> Wherever possible I move templates that depend on a plugin into those
> plugins to avoid this kind of checking. It's a trade-off between more
> complicated template hierarchies vs. dependencies creeping into
> unrelated extensions.
>
> What's the larger problem you're solving that you think needs this?
>
> On Wed, Feb 22, 2017 at 11:43 AM, Harald von Waldow
> <harald.vonwaldow at eawag.ch> wrote:
> > I would like to have a template-helper that tells me whether a certain
> plugin is loaded. This here works, but I'd be glad for any hints to achieve
> this less convoluted and more elegantly and future-proof:
> >
> >
> > import ckan.plugins as p
> >
> > def eaw_check_plugin(pluginname):
> >     ifaces = (eval('p.{}'.format(name)) for name in p.interfaces.__all__)
> >     implemented = [item.name
> >                    for iface in ifaces
> >                    for item in p.PluginImplementations(iface)]
> >     return pluginname in implemented
> >
> >
> > Thanks,
> > Harald
> >
> > --
> > Harald von Waldow
> > Eawag
> > ICT Services
> > Ueberlandstrasse 133
> > 8600 Duebendorf
> > http://www.eawag.ch
> >
> >
> > _______________________________________________
> > ckan-dev mailing list
> > ckan-dev at lists.okfn.org
> > https://lists.okfn.org/mailman/listinfo/ckan-dev
> > Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
> >
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>



-- 
Liip AG  // Limmatstrasse 183 //  CH-8005 Zürich
Tel +41 43 500 39 80 // GnuPG 0x7B588C67 // www.liip.ch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170223/c517edd5/attachment-0003.html>


More information about the ckan-dev mailing list