Skip to content

Commit

Permalink
Add a submit_all command to datapusher.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CarlQLange committed May 16, 2016
1 parent aeb3863 commit b670bbf
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ckanext/datapusher/cli.py
Expand Up @@ -14,6 +14,9 @@ class DatapusherCommand(cli.CkanCommand):
ignoring if their files haven't changed.
submit <pkgname> - 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]
Expand All @@ -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()

Expand All @@ -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

Expand Down

0 comments on commit b670bbf

Please sign in to comment.