Skip to content
Browse files

[MetaSearch]: use OWSLib for connection testing, add task to build CS…

…W connection file
  • Loading branch information
tomkralidis committed Feb 27, 2015
1 parent f106a2e commit c33c0977062e6290dcf354dad97bc848268f11b7
Showing with 43 additions and 21 deletions.
  1. +43 −21 python/plugins/MetaSearch/
@@ -23,14 +23,14 @@
import getpass
import os
import shutil
from urllib import urlencode
from urllib2 import urlopen
import xml.etree.ElementTree as etree
import xmlrpclib
import zipfile

from paver.easy import (call_task, cmdopts, error, info, options, path,
pushd, sh, task, Bunch)
sh, task, Bunch)

from owslib.csw import CatalogueServiceWeb

PLUGIN_NAME = 'MetaSearch'
BASEDIR = os.path.abspath(os.path.dirname(__file__))
@@ -180,24 +180,46 @@ def test_default_csw_connections():
relpath = 'resources%sconnections-default.xml' % os.sep
csw_connections_xml = options.base.plugin / relpath

csws = etree.parse(csw_connections_xml)

for csw in csws.findall('csw'):
# name = csw.attrib.get('name')
data = {
'service': 'CSW',
'version': '2.0.2',
'request': 'GetCapabilities'
values = urlencode(data)
url = '%s?%s' % (csw.attrib.get('url'), values)
content = urlopen(url)
if content.getcode() != 200:
raise ValueError('Bad HTTP status code')
csw_xml = etree.fromstring(
tag = '{}Capabilities'
if csw_xml.tag != tag:
raise ValueError('root element should be csw:Capabilities')
conns = etree.parse(csw_connections_xml)

for conn in conns.findall('csw'):
csw = CatalogueServiceWeb(conn.attrib.get('url'))
info('Success: %s', csw.identification.title)
except Exception, err:
raise ValueError('ERROR: %s', err)

('filename=', 'f', 'Path to file of CSW URLs'),
def generate_csw_connections_file():
"""generate a CSW connections file from a flat file of CSW URLs"""

filename = options.get('filename', False)

if not filename:
raise ValueError('path to file of CSW URLs required')

conns = etree.Element('qgsCSWConnections')
conns.attrib['version'] = '1.0'

with open(filename) as connsfh:
for line in connsfh:
url = line.strip()
if not url: # blank line
csw = CatalogueServiceWeb(url)
title = unicode(csw.identification.title)
conn = etree.SubElement(conns, 'csw', name=title, url=url)
#conn.attrib['name'] = title
#conn.attrib['url'] = url
except Exception, err:
error('ERROR on CSW %s: %s', url, err)

info(etree.tostring(conns, encoding='utf-8'))

def get_package_filename():

0 comments on commit c33c097

Please sign in to comment.
You can’t perform that action at this time.