[ckan-dev] check for plugins

Harald von Waldow harald.vonwaldow at eawag.ch
Fri Feb 24 08:17:04 UTC 2017


Ian, Stefan, thanks a lot.

Stefan, yes "in ckan.plugins there is a method called plugin_loaded()"
was what I was looking for.

But I'll heed you advice and get rid of that altogether. It is about a
template that can't reasonably be integrated into the extension in
question and was supposed to show a checkbox if an option provided by
the other extension is available. But I guess it is a better UI decision
anyway in this case to move this choice into a config option.

Best,
Harald

On 2017-02-23 10:41, Stefan Oderbolz wrote:
> 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
> <mailto: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 <mailto: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 <http://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 <mailto:ckan-dev at lists.okfn.org>
>     > https://lists.okfn.org/mailman/listinfo/ckan-dev
>     <https://lists.okfn.org/mailman/listinfo/ckan-dev>
>     > Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>     <https://lists.okfn.org/mailman/options/ckan-dev>
>     >
>     _______________________________________________
>     ckan-dev mailing list
>     ckan-dev at lists.okfn.org <mailto:ckan-dev at lists.okfn.org>
>     https://lists.okfn.org/mailman/listinfo/ckan-dev
>     <https://lists.okfn.org/mailman/listinfo/ckan-dev>
>     Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>     <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
> <http://www.liip.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
> 

-- 
Harald von Waldow
Eawag
ICT Services
Ueberlandstrasse 133
8600 Duebendorf
http://www.eawag.ch

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170224/d2908640/attachment-0003.sig>


More information about the ckan-dev mailing list