From 3c505693ff9847e0cb81a2b20227d9265f6f14e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Mercader?= Date: Fri, 8 Apr 2011 17:07:19 +0100 Subject: [PATCH] [refactoring] Do not delete sources, just inactivate them. Also don't delete jobs. --- ckanext/harvest/commands/harvester.py | 32 ++++++++++----------------- ckanext/harvest/lib/__init__.py | 24 +++++--------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/ckanext/harvest/commands/harvester.py b/ckanext/harvest/commands/harvester.py index 1f06b05..469758c 100644 --- a/ckanext/harvest/commands/harvester.py +++ b/ckanext/harvest/commands/harvester.py @@ -14,16 +14,14 @@ class Harvester(CkanCommand): - create new harvest source harvester rmsource {id} - - remove a harvester source (and associated jobs) + - remove (inactivate) a harvester source - harvester sources + harvester sources [all] - lists harvest sources + If 'all' is defined, it also shows the Inactive sources harvester job {source-id} - create new harvest job - - harvester rmjob {job-id} - - remove a harvest job harvester jobs - lists harvest jobs @@ -70,8 +68,6 @@ class Harvester(CkanCommand): self.list_harvest_sources() elif cmd == 'job': self.create_harvest_job() - elif cmd == "rmjob": - self.remove_harvest_job() elif cmd == 'jobs': self.list_harvest_jobs() elif cmd == 'run': @@ -145,13 +141,19 @@ class Harvester(CkanCommand): print 'Please provide a source id' sys.exit(1) - delete_harvest_source(source_id) + remove_harvest_source(source_id) print 'Removed harvest source: %s' % source_id def list_harvest_sources(self): - sources = get_harvest_sources() + if len(self.args) >= 2 and self.args[1] == 'all': + sources = get_harvest_sources() + what = 'harvest source' + else: + sources = get_harvest_sources(active=True) + what = 'active harvest source' + self.print_harvest_sources(sources) - self.print_there_are(what="harvest source", sequence=sources) + self.print_there_are(what=what, sequence=sources) def create_harvest_job(self): if len(self.args) >= 2: @@ -167,16 +169,6 @@ class Harvester(CkanCommand): jobs = get_harvest_jobs(status=status) self.print_there_are('harvest jobs', jobs, condition=status) - def remove_harvest_job(self): - if len(self.args) >= 2: - job_id = unicode(self.args[1]) - else: - print 'Please provide a job id' - sys.exit(1) - - delete_harvest_job(job_id) - print 'Removed harvest job: %s' % job_id - def list_harvest_jobs(self): jobs = get_harvest_jobs() self.print_harvest_jobs(jobs) diff --git a/ckanext/harvest/lib/__init__.py b/ckanext/harvest/lib/__init__.py index bc0561f..d7804d8 100644 --- a/ckanext/harvest/lib/__init__.py +++ b/ckanext/harvest/lib/__init__.py @@ -81,16 +81,15 @@ def create_harvest_source(source_dict): return _source_as_dict(source) -def delete_harvest_source(source_id): +def remove_harvest_source(source_id): try: source = HarvestSource.get(source_id) except: raise Exception('Source %s does not exist' % source_id) - - source.delete() - repo.commit_and_remove() - - #TODO: Jobs? + + # Don't actually delete the record, just flag it as inactive + source.active = False + source.save() return True @@ -122,19 +121,6 @@ def create_harvest_job(source_id): return _job_as_dict(job) -def delete_harvest_job(job_id): - try: - job = HarvestJob.get(job_id) - except: - raise Exception('Job %s does not exist' % job_id) - - job.delete() - repo.commit_and_remove() - - #TODO: objects? - - return True - def run_harvest_jobs(): # Check if there are pending harvest jobs jobs = get_harvest_jobs(status=u'New')