Skip to content

Commit

Permalink
email correctly; obey a config var to force deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
jstange committed Aug 8, 2014
1 parent 7341786 commit ef8deae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ckanext/datajson/harvester_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,20 @@ def gather_stage(self, harvest_job):
deletia+=1

log.warn('%d datasets in %s; marked %d for deletion' % (dataset_count, harvest_job.source.url, deletia))
if dataset_count > 0 and float(deletia)/float(dataset_count) > 0.1:
if dataset_count > 0 and float(deletia)/float(dataset_count) > 0.1 and DataJsonPlugin.allow_harvester_deletion != "true":
log.warn('Too many deleted datasets in %s, skipping deletion' % (harvest_job.source.url))
package_titles = u"The following datasets have been dropped from this feed, but since there are so many I'm going to hold off on actually deleting them:\n\n"
for upstreamid, pkg in existing_datasets.items():
if upstreamid in seen_datasets: continue # was just updated
if pkg.get("state") == "deleted": continue # already deleted
log.warn('%s (%s) would be deleted' % (pkg["title"], pkg["id"]))
log.warn('%s (%s) would be deleted %s' % (pkg["title"], pkg["id"], DataJsonPlugin.allow_harvester_deletion))
package_titles += pkg["title"] + "\n\n"
msg = MIMEText(package_titles, _charset='utf-8')
msg['Subject'] = "Harvested dataset "+harvest_job.source.url+" has too many deletions!"
msg['From'] = DataJsonPlugin.error_email_from
msg['To'] = DataJsonPlugin.email_to
server = smtplib.SMTP('localhost')
server.sendmail(DataJsonPlugin.error_email_from, DataJsonPlugin.email_to, msg.as_string())
server.sendmail(DataJsonPlugin.error_email_from, DataJsonPlugin.email_to.split(","), msg.as_string())
server.quit()
return object_ids

Expand Down
1 change: 1 addition & 0 deletions ckanext/datajson/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def update_config(self, config):
DataJsonPlugin.ld_title = config.get("ckan.site_title", "Catalog")
DataJsonPlugin.site_url = config.get("ckan.site_url")
DataJsonPlugin.error_email_from = config.get("error_email_from")
DataJsonPlugin.allow_harvester_deletion = config.get("ckanext.datajson.allow_harvester_deletion", True)
DataJsonPlugin.email_to = config.get("email_to")
DataJsonPlugin.default_contactpoint = config.get("ckanext.datajson.default_contactpoint")
DataJsonPlugin.default_mbox = config.get("ckanext.datajson.default_mbox")
Expand Down

0 comments on commit ef8deae

Please sign in to comment.