Skip to content

Commit

Permalink
utils: rise exception if no config found in db
Browse files Browse the repository at this point in the history
Signed-off-by: David Caro <david@dcaro.es>
  • Loading branch information
david-caro committed Mar 6, 2017
1 parent de86233 commit b66bf4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions invenio_oaiharvester/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ class WrongDateCombination(InvenioOAIHarvesterError):

class IdentifiersOrDates(InvenioOAIHarvesterError):
"""Identifiers cannot be used in combination with dates."""


class InvenioOAIHarvesterConfigNotFound(InvenioOAIHarvesterError):
"""No InvenioOAIHarvesterConfig was found."""
12 changes: 11 additions & 1 deletion invenio_oaiharvester/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
from flask import current_app
from lxml import etree

from .errors import InvenioOAIHarvesterConfigNotFound


REGEXP_OAI_ID = re.compile(r"<identifier.*?>(.*?)</identifier>", re.DOTALL)


Expand Down Expand Up @@ -140,7 +143,14 @@ def get_oaiharvest_object(name):
:return: The OAIHarvestConfig object.
"""
from .models import OAIHarvestConfig
return OAIHarvestConfig.query.filter_by(name=name).first()
obj = OAIHarvestConfig.query.filter_by(name=name).first()
if not obj:
raise InvenioOAIHarvesterConfigNotFound(
'Unable to find OAIHarvesterConfig obj with name %s.'
% name
)

return obj


def check_or_create_dir(output_dir):
Expand Down

0 comments on commit b66bf4b

Please sign in to comment.