Made print method more robust against KeyErrors
This is especially needed if you create a new harvest source which does not have all the optional arguments. Before this lead to a KeyError after the creation of the source. Now this simply output 'None'.
This commit is contained in:
parent
1249564be5
commit
7ae9d6e208
|
@ -306,14 +306,14 @@ class Harvester(CkanCommand):
|
||||||
self.print_harvest_source(source)
|
self.print_harvest_source(source)
|
||||||
|
|
||||||
def print_harvest_source(self, source):
|
def print_harvest_source(self, source):
|
||||||
print 'Source id: %s' % source['id']
|
print 'Source id: %s' % source.get('id')
|
||||||
print ' url: %s' % source['url']
|
print ' url: %s' % source.get('url')
|
||||||
print ' type: %s' % source['type']
|
print ' type: %s' % source.get('type')
|
||||||
print ' active: %s' % source['active']
|
print ' active: %s' % source.get('active')
|
||||||
print ' user: %s' % source['user_id']
|
print ' user: %s' % source.get('user_id')
|
||||||
print 'publisher: %s' % source['publisher_id']
|
print 'publisher: %s' % source.get('publisher_id')
|
||||||
print 'frequency: %s' % source['frequency']
|
print 'frequency: %s' % source.get('frequency')
|
||||||
print ' jobs: %s' % source['status']['job_count']
|
print ' jobs: %s' % source.get('status').get('job_count')
|
||||||
print ''
|
print ''
|
||||||
|
|
||||||
def print_harvest_jobs(self, jobs):
|
def print_harvest_jobs(self, jobs):
|
||||||
|
@ -323,9 +323,9 @@ class Harvester(CkanCommand):
|
||||||
self.print_harvest_job(job)
|
self.print_harvest_job(job)
|
||||||
|
|
||||||
def print_harvest_job(self, job):
|
def print_harvest_job(self, job):
|
||||||
print ' Job id: %s' % job['id']
|
print ' Job id: %s' % job.get('id')
|
||||||
print ' status: %s' % job['status']
|
print ' status: %s' % job.get('status')
|
||||||
print ' source: %s' % job['source_id']
|
print ' source: %s' % job.get('source_id')
|
||||||
print ' objects: %s' % len(job.get('objects', []))
|
print ' objects: %s' % len(job.get('objects', []))
|
||||||
|
|
||||||
print 'gather_errors: %s' % len(job.get('gather_errors', []))
|
print 'gather_errors: %s' % len(job.get('gather_errors', []))
|
||||||
|
|
Loading…
Reference in New Issue