From b670bbfe0dc05b831ef8a4798f44784a4345ac7d Mon Sep 17 00:00:00 2001 From: Carl Lange Date: Mon, 16 May 2016 10:11:43 +0100 Subject: [PATCH 1/2] Add a submit_all command to datapusher. this allows you to add every resource of every package to the datastore. this is useful if you're setting up datastore for a a ckan that's already got datasets. Also renames the existing submit_all function to resubmit_all, because it would not act on resources that had not already been submitted to datastore. --- ckanext/datapusher/cli.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ckanext/datapusher/cli.py b/ckanext/datapusher/cli.py index 7db5bc81711..2328b051f14 100644 --- a/ckanext/datapusher/cli.py +++ b/ckanext/datapusher/cli.py @@ -14,6 +14,9 @@ class DatapusherCommand(cli.CkanCommand): ignoring if their files haven't changed. submit - Submits all resources from the package identified by pkgname (either the short name or ID). + submit_all - Submit every package to the datastore. + This is useful if you're setting up datastore + for a ckan that already has datasets. ''' summary = __doc__.split('\n')[0] @@ -24,7 +27,12 @@ def command(self): self._confirm_or_abort() self._load_config() - self._submit_all() + self._resubmit_all() + elif self.args and self.args[0] == 'submit_all': + self._confirm_or_abort() + + self._load_config() + self._submit_all_packages() elif self.args and self.args[0] == 'submit': self._confirm_or_abort() @@ -49,10 +57,18 @@ def _confirm_or_abort(self): print "Aborting..." sys.exit(0) - def _submit_all(self): + def _resubmit_all(self): resources_ids = datastore_db.get_all_resources_ids_in_datastore() self._submit(resource_ids) + def _submit_all_packages(self): + # submit every package + # for each package in the package list, submit each resource w/ _submit_package + import ckan.model as model + package_list = p.toolkit.get_action('package_list') + for p_id in package_list({'model': model, 'ignore_auth': True}, {}): + self._submit_package(p_id) + def _submit_package(self, pkg_id): import ckan.model as model From dfd2a9187cde6161fc85ba2aba5feefa2516e227 Mon Sep 17 00:00:00 2001 From: Carl Lange Date: Wed, 22 Jun 2016 00:01:59 +0100 Subject: [PATCH 2/2] Fix Pep8 error (long comment) --- ckanext/datapusher/cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ckanext/datapusher/cli.py b/ckanext/datapusher/cli.py index 2328b051f14..c5d098c9671 100644 --- a/ckanext/datapusher/cli.py +++ b/ckanext/datapusher/cli.py @@ -63,7 +63,8 @@ def _resubmit_all(self): def _submit_all_packages(self): # submit every package - # for each package in the package list, submit each resource w/ _submit_package + # for each package in the package list, + # submit each resource w/ _submit_package import ckan.model as model package_list = p.toolkit.get_action('package_list') for p_id in package_list({'model': model, 'ignore_auth': True}, {}):