Commit 223ed0aa authored by David Read's avatar David Read
Browse files

Also archive if there is a change of licence or format, since QA makes decisions on these fields.

parent 4b2601ed
...@@ -2,7 +2,6 @@ import os ...@@ -2,7 +2,6 @@ import os
import logging import logging
import ckan.plugins as p import ckan.plugins as p
from ckan import model
from ckan.model.types import make_uuid from ckan.model.types import make_uuid
from ckan.lib.celery_app import celery from ckan.lib.celery_app import celery
...@@ -34,3 +33,10 @@ def create_archiver_package_task(package, queue): ...@@ -34,3 +33,10 @@ def create_archiver_package_task(package, queue):
task_id=task_id, queue=queue) task_id=task_id, queue=queue)
log.debug('Archival of package put into celery queue %s: %s', log.debug('Archival of package put into celery queue %s: %s',
queue, package.name) queue, package.name)
def get_extra_from_pkg_dict(pkg_dict, key, default=None):
for extra in pkg_dict['extras']:
if extra['key'] == key:
return extra['value']
return default
...@@ -45,8 +45,11 @@ class ArchiverPlugin(p.SingletonPlugin, p.toolkit.DefaultDatasetForm): ...@@ -45,8 +45,11 @@ class ArchiverPlugin(p.SingletonPlugin, p.toolkit.DefaultDatasetForm):
lib.create_archiver_package_task(entity, 'priority') lib.create_archiver_package_task(entity, 'priority')
def _is_it_sufficient_change_to_run_archiver(self, package, operation): def _is_it_sufficient_change_to_run_archiver(self, package, operation):
''' Returns True if it is a new dataset or there are resources that ''' Returns True if in this revision any of these happened:
have been added, deleted or URL changed in this revision. * it is a new dataset
* dataset licence changed (affects qa)
* there are resources that have been added or deleted
* resources have changed their URL or format (affects qa)
''' '''
if operation == 'new': if operation == 'new':
log.debug('New package - will archive') log.debug('New package - will archive')
...@@ -89,6 +92,17 @@ class ArchiverPlugin(p.SingletonPlugin, p.toolkit.DefaultDatasetForm): ...@@ -89,6 +92,17 @@ class ArchiverPlugin(p.SingletonPlugin, p.toolkit.DefaultDatasetForm):
log.warn('No sign of previous package - will archive anyway') log.warn('No sign of previous package - will archive anyway')
return True return True
# has the licence changed?
old_licence = (old_pkg_dict['license_id'],
lib.get_extra_from_pkg_dict(old_pkg_dict, 'licence')
or None)
new_licence = (package.license_id,
package.extras.get('licence') or None)
if old_licence != new_licence:
log.debug('Licence has changed - will archive: %r->%r',
old_licence, new_licence)
return True
# have any resources been added or deleted? # have any resources been added or deleted?
old_resources = dict((res['id'], res) old_resources = dict((res['id'], res)
for res in old_pkg_dict['resources']) for res in old_pkg_dict['resources'])
...@@ -105,13 +119,16 @@ class ArchiverPlugin(p.SingletonPlugin, p.toolkit.DefaultDatasetForm): ...@@ -105,13 +119,16 @@ class ArchiverPlugin(p.SingletonPlugin, p.toolkit.DefaultDatasetForm):
added_res_ids) added_res_ids)
return True return True
# have any resource urls changed? # have any resources' url/format changed?
for res in package.resources: for res in package.resources:
old_res_url = old_resources[res.id]['url'] for key in ('url', 'format'):
if old_res_url != res.url: old_res_value = old_resources[res.id][key]
log.debug('Resource url changed - will archive. ' new_res_value = getattr(res, key)
if old_res_value != new_res_value:
log.debug('Resource %s changed - will archive. '
'id=%s pos=%s url="%s"->"%s"', 'id=%s pos=%s url="%s"->"%s"',
res.id[:4], res.position, old_res_url, res.url) key, res.id[:4], res.position,
old_res_value, new_res_value)
return True return True
log.debug('Resource unchanged. pos=%s id=%s', log.debug('Resource unchanged. pos=%s id=%s',
res.position, res.id[:4]) res.position, res.id[:4])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment