diff --git a/ckanext/harvest/commands/harvester.py b/ckanext/harvest/commands/harvester.py index da99375..1ab3ecd 100644 --- a/ckanext/harvest/commands/harvester.py +++ b/ckanext/harvest/commands/harvester.py @@ -118,10 +118,20 @@ class Harvester(CkanCommand): packages = [extra.package \ for extra in \ Session.query(PackageExtra).filter(PackageExtra.key == 'bbox-east-long').all()] - for package in packages: - save_extent(package) - print "Done. Extents generated for %i packages" % len(packages) + error = False + for package in packages: + try: + save_extent(package) + except: + errors = True + + if error: + msg = "There was an error saving the package extent. Have you set up the package_extent table in the DB?" + else: + msg = "Done. Extents generated for %i packages" % len(packages) + + print msg def run_harvester(self, *args, **kwds): from pylons.i18n.translation import _get_translator diff --git a/ckanext/harvest/controllers/harvesting.py b/ckanext/harvest/controllers/harvesting.py index 272c5a6..1003909 100644 --- a/ckanext/harvest/controllers/harvesting.py +++ b/ckanext/harvest/controllers/harvesting.py @@ -224,8 +224,7 @@ class HarvestingJobController(object): # Create new package from data. package = self._create_package_from_data(package_data) if package.extras.get('bbox-east-long'): - save_extent(package) - + self.save_package_extent(package) log.info("Created new package ID %s with GEMINI guid %s", package.id, gemini_guid) harvested_doc = HarvestedDocument( content=content, @@ -241,8 +240,7 @@ class HarvestingJobController(object): else: package = self._create_package_from_data(package_data, package = package) if package.extras.get('bbox-east-long'): - save_extent(package) - + self.save_package_extent(package) log.info("Updated existing package ID %s with existing GEMINI guid %s", package.id, gemini_guid) harvested_doc.content = content harvested_doc.source = self.job.source @@ -252,6 +250,13 @@ class HarvestingJobController(object): assert gemini_guid == package.documents[0].guid return package + def save_package_extent(self,package): + try: + save_extent(package) + except: + log.error("There was an error saving the package extent. Have you set up the package_extent table in the DB?") + raise Exception + def get_content(self, url): try: http_response = urllib2.urlopen(url) diff --git a/ckanext/harvest/lib/__init__.py b/ckanext/harvest/lib/__init__.py index 7fda58d..ab1e82d 100644 --- a/ckanext/harvest/lib/__init__.py +++ b/ckanext/harvest/lib/__init__.py @@ -106,8 +106,7 @@ def save_extent(package,extent=False): Session.commit() log.info(msg, package.id) + return package except: log.error('An error occurred when saving the extent for package %s',package.id) - finally: - return package - + raise Exception