[ckan-dev] Error executing new ckan extension

Ross Jones ross at servercode.co.uk
Wed Jan 14 13:53:48 UTC 2015


Hi,

Try adding

     self._load_config()

before the call to render.


Ross


Isabel Ruiz wrote:
> Hi,
>
> I am developing a ckan extension and I need execute it in a paster command.
>
> I have followed ckan extension tutorial steps:
> * Execute paster create command.
> * python setup.py develop
> * Add plugin in .ini file and restart apache2
>
> This is the code from my commands.py
>
> #############################
> from ckan.lib.cli import CkanCommand
> from ckan.lib.base import render
>
> class Gen(CkanCommand):
> summary = ""
> max_args = 2
> min_args = 2
>
> def generar(self):
>
> cmd = self.args[0]
> import sys
>
> data = render(args[0],load_class=None)
>
> try:
> with open(args[1], 'w') as f:
> f.write(data.encode('utf-8'))
> print "OK"
> except IOError, ioe:
> return "error " + str(ioe)
> #############################
>
> I have create a plugin.py too, but I am not sure about if it is
> necessary. This is plugin.py code:
>
> #############################
> import ckan.plugins as p
>
> class GenPlugin(p.SingletonPlugin):
>
>      p.implements(p.IConfigurer)
>      p.implements(p.ITemplateHelpers)
>      p.implements(p.IRoutes, inherit=True)
>
>      def update_config(self, config):
>          # add template directory that contains our snippet
> p.toolkit.add_template_directory(config,
> '/usr/lib/ckan/default/src/ckanext-extension/ckanext/extension/theme/templates')
> p.toolkit.add_public_directory (config,
> '/usr/lib/ckan/default/src/ckanext-extension/ckanext/extension/public')
>
>      def get_helpers(self):
> return {}
> #############################
>
> I have activated virtual environment.
>
> When I execute paster commands: paster generar agr1 arg2
> --config=myinifile.ini
>
> It returns:
>
> Traceback (most recent call last):
>    File "/usr/lib/ckan/default/bin/paster", line 9, in <module>
>      load_entry_point('PasteScript==1.7.5', 'console_scripts', 'paster')()
>    File
> "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py",
> line 104, in run
>      invoke(command, command_name, options, args[1:])
>    File
> "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py",
> line 143, in invoke
>      exit_code = runner.run(args)
>    File
> "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py",
> line 238, in run
>      result = self.command()
>    File
> "/home/ckan/ckan/lib/default/src/ckanext-extension/ckanext/extension/commands.py",
> line 18, in command
>      data = render(self.args[1], loader_class=None)
>    File "/home/ckan/ckan/lib/default/src/ckan/ckan/lib/base.py", line
> 177, in render
>      if 'Pragma' in response.headers:
>    File
> "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/registry.py",
> line 137, in __getattr__
>      return getattr(self._current_obj(), attr)
>    File
> "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/registry.py",
> line 197, in _current_obj
> 'thread' % self.____name__)
> TypeError: No object (name: response) has been registered for this thread
>
>
> If I change "data = render(args[0],load_class=None)" for "print "hello
> world" ", then console returns "hello world", so setup.py, etc, work.
>
> So I suppose I have created, developed and configured ckan extension
> correctly.
>
> What can be wrong?
>
> Thanks.
>
> --
> Isabel M. Ruiz Mellado
> http://about.me/isabelruiz
>
> _______________________________________________
> 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



More information about the ckan-dev mailing list