Skip to content

Instantly share code, notes, and snippets.

@amercader
Created May 15, 2012 13:30
Show Gist options
  • Save amercader/2701799 to your computer and use it in GitHub Desktop.
Save amercader/2701799 to your computer and use it in GitHub Desktop.
pycsw / CKAn integration proof of concept
class CSWController(BaseController):
def dispatch(self):
import os
from pycsw.server import server
from pylons import request, response
env = request.environ
pycsw_config = config.get('ckanext.spatial.pycsw.config')
csw = server.Csw(pycsw_config, env)
contents = csw.dispatch_wsgi()
response.headers['Content-Length'] = str(len(contents))
response.headers['Content-Type'] = csw.contenttype
response.status = '200 OK'
return contents
@tomkralidis
Copy link

FYI this would now look like:

class CSWController(BaseController):

    def dispatch(self):
        import os
        from pycsw import server

        from pylons import request, response
        env = request.environ

        pycsw_config = config.get('ckanext.spatial.pycsw.config')
        csw = server.Csw(pycsw_config, env)

        contents = csw.dispatch_wsgi()

        response.headers['Content-Length'] = str(len(contents))
        response.headers['Content-Type'] = csw.contenttype

        response.status = '200 OK'

        return contents

Note that you can now pass a SafeConfigParser object of the configuration, which opens up the idea of storing the configuration either in code or a db, and call with something like:

from ConfigParser import SafeConfigParser

config = SafeConfigParser()
for section, options in settings.CSW.iteritems():
    config.add_section(section)
    for k, v in options.iteritems():
        config.set(section, k, v)

csw = server.Csw(config, env)

A full working example of integrating pycsw cleanly can be found in OpenDataCatalog: https://github.com/tomkralidis/Open-Data-Catalog/tree/csw

@tomkralidis
Copy link

Update: pycsw can now accept configuration as a Python dict as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment