Skip to content

Commit

Permalink
check baseUrl is OAI-PMH target before harvesting
Browse files Browse the repository at this point in the history
Check by carrying out an Identify request, raise an appropriate
Exception if not.
  • Loading branch information
bloomonkey committed Apr 28, 2014
1 parent 6cefb10 commit 303182e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions oaiharvest/harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down

0 comments on commit 303182e

Please sign in to comment.