From f44cb0ff16d7cc2a849d9c53da65ca2cf4f1e9bd Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 28 Apr 2014 15:26:38 +0100 Subject: [PATCH 1/4] bumped version number --- oaiharvest/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oaiharvest/__init__.py b/oaiharvest/__init__.py index 8b07702..460c167 100644 --- a/oaiharvest/__init__.py +++ b/oaiharvest/__init__.py @@ -1,4 +1,4 @@ __name__ = "OAI-PMH Harvester" __package = "oaiharvest" __all__ = ['harvest', 'metadata'] -__version__ = "1.1.4" +__version__ = "1.1.5" From 067849ee5f03020321c158838228b3c3eb8a1b30 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 28 Apr 2014 16:12:34 +0100 Subject: [PATCH 2/4] use absolute_import with . prefix for local imports --- oaiharvest/harvest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oaiharvest/harvest.py b/oaiharvest/harvest.py index 3e0940d..8ee1d64 100644 --- a/oaiharvest/harvest.py +++ b/oaiharvest/harvest.py @@ -42,7 +42,7 @@ Distributed under the terms of the BSD 3-clause License . """ -from __future__ import with_statement +from __future__ import with_statement, absolute_import import logging import os @@ -56,8 +56,8 @@ from oaipmh.client import Client from oaipmh.error import NoRecordsMatchError -from metadata import DefaultingMetadataRegistry, XMLMetadataReader -from registry import verify_database +from .metadata import DefaultingMetadataRegistry, XMLMetadataReader +from .registry import verify_database class OAIHarvester(object): From 6cefb10257ad8ea0d051fffd199089ffd849fe31 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 28 Apr 2014 16:10:40 +0100 Subject: [PATCH 3/4] add exceptions module --- oaiharvest/exceptions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 oaiharvest/exceptions.py diff --git a/oaiharvest/exceptions.py b/oaiharvest/exceptions.py new file mode 100644 index 0000000..dbbe48f --- /dev/null +++ b/oaiharvest/exceptions.py @@ -0,0 +1,11 @@ +"""OAI-PMH Harvesting Exceptions.""" + + +class OAIPMHHarvestException(Exception): + """Base Class for OAI-PMH Harvesting Exceptions.""" + pass + + +class NotOAIPMHBaseURLException(OAIPMHHarvestException): + """URL is not an OAI-PMH base URL.""" + pass From 303182ef5022a6490821648edef23046c5ec4b17 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Mon, 28 Apr 2014 16:15:02 +0100 Subject: [PATCH 4/4] check baseUrl is OAI-PMH target before harvesting Check by carrying out an Identify request, raise an appropriate Exception if not. --- oaiharvest/harvest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/oaiharvest/harvest.py b/oaiharvest/harvest.py index 8ee1d64..da6ed04 100644 --- a/oaiharvest/harvest.py +++ b/oaiharvest/harvest.py @@ -56,6 +56,7 @@ from oaipmh.client import Client from oaipmh.error import NoRecordsMatchError +from .exceptions import NotOAIPMHBaseURLException from .metadata import DefaultingMetadataRegistry, XMLMetadataReader from .registry import verify_database @@ -75,6 +76,14 @@ def _listRecords(self, baseUrl, metadataPrefix="oai_dc", **kwargs): # Add metatdataPrefix to args kwargs['metadataPrefix'] = metadataPrefix client = Client(baseUrl, metadata_registry) + # Check that baseUrl actually represents an OAI-PMH target + try: + client.identify() + except IndexError: + raise NotOAIPMHBaseURLException( + "{0} does not appear to be an OAI-PMH compatible base URL" + "".format(baseUrl) + ) # Check server timestamp granularity support client.updateGranularity() for record in client.listRecords(**kwargs):