From c36d9bdd8ec52fdceea1895c838d44863d50fb14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Mercader?= Date: Tue, 6 Sep 2011 18:25:17 +0100 Subject: [PATCH] Add new command to create new jobs for all active sources --- README.rst | 3 +++ ckanext/harvest/commands/harvester.py | 9 +++++++++ ckanext/harvest/lib/__init__.py | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/README.rst b/README.rst index b5c9a93..7d553b7 100644 --- a/README.rst +++ b/README.rst @@ -94,6 +94,9 @@ The following operations can be run from the command line using the It will only affect the last fetched objects already present in the database. + harvester job-all + - create new harvest jobs for all active sources. + The commands should be run from the ckanext-harvest directory and expect a development.ini file to be present. Most of the time you will specify the config explicitly though:: diff --git a/ckanext/harvest/commands/harvester.py b/ckanext/harvest/commands/harvester.py index 13b4795..e725a9e 100644 --- a/ckanext/harvest/commands/harvester.py +++ b/ckanext/harvest/commands/harvester.py @@ -44,6 +44,9 @@ class Harvester(CkanCommand): Please note that no objects will be fetched from the remote server. It will only affect the last fetched objects already present in the database. + harvester job-all + - create new harvest jobs for all active sources. + The commands should be run from the ckanext-harvest directory and expect a development.ini file to be present. Most of the time you will specify the config explicitly though:: @@ -91,6 +94,8 @@ class Harvester(CkanCommand): self.initdb() elif cmd == 'import': self.import_stage() + elif cmd == 'job-all': + self.create_harvest_job_all() else: print 'Command %s not recognized' % cmd @@ -212,6 +217,10 @@ class Harvester(CkanCommand): source_id = None import_last_objects(source_id) + def create_harvest_job_all(self): + jobs = create_harvest_job_all() + print "Created %s new harvest jobs" % len(jobs) + def print_harvest_sources(self, sources): if sources: print '' diff --git a/ckanext/harvest/lib/__init__.py b/ckanext/harvest/lib/__init__.py index ac84dfc..d43538d 100644 --- a/ckanext/harvest/lib/__init__.py +++ b/ckanext/harvest/lib/__init__.py @@ -377,6 +377,18 @@ def import_last_objects(source_id=None): return imported_objects +def create_harvest_job_all(): + + # Get all active sources + sources = get_harvest_sources(active=True) + jobs = [] + # Create a new job for each + for source in sources: + job = create_harvest_job(source['id']) + jobs.append(job) + + return jobs + def get_registered_harvesters_info(): available_harvesters = [] for harvester in PluginImplementations(IHarvester):