def resubmit(yes: bool): u'''Resubmit updated datastore resources. ''' confirm(yes) resource_ids = datastore_backend.get_all_resources_ids_in_datastore() _submit(resource_ids)
def _submit_all_existing(self): import ckan.model as model from ckanext.datastore.backend \ import get_all_resources_ids_in_datastore resource_ids = get_all_resources_ids_in_datastore() print('Processing %d resources' % len(resource_ids)) user = p.toolkit.get_action('get_site_user')({ 'model': model, 'ignore_auth': True }, {}) for resource_id in resource_ids: try: resource_dict = p.toolkit.get_action('resource_show')( { 'model': model, 'ignore_auth': True }, { 'id': resource_id }) except p.toolkit.ObjectNotFound: print( ' Skipping resource {} found in datastore but not in ' 'metadata'.format(resource_id)) continue self._submit_resource(resource_dict, user, indent=2)
def test_get_all_resources_ids_in_datastore(self): resource_in_datastore = factories.Resource() resource_not_in_datastore = factories.Resource() data = {"resource_id": resource_in_datastore["id"], "force": True} helpers.call_action("datastore_create", **data) resource_ids = backend.get_all_resources_ids_in_datastore() assert resource_in_datastore["id"] in resource_ids assert resource_not_in_datastore["id"] not in resource_ids
def status(context, data_dict): deleted = _resource_set() active = _resource_set('active') datastore_ids = set(backend.get_all_resources_ids_in_datastore()) return { 'active': len(active & datastore_ids), 'deleted': len(deleted & datastore_ids), 'datastore': len(datastore_ids) }
def test_get_all_resources_ids_in_datastore(self): resource_in_datastore = factories.Resource() resource_not_in_datastore = factories.Resource() data = { 'resource_id': resource_in_datastore['id'], 'force': True, } helpers.call_action('datastore_create', **data) resource_ids = backend.get_all_resources_ids_in_datastore() assert resource_in_datastore['id'] in resource_ids assert resource_not_in_datastore['id'] not in resource_ids
def purge(context, data_dict): deleted = _resource_set() datastore_ids = set(backend.get_all_resources_ids_in_datastore()) # ok, getting dangerous here. # we can't actually call datastore_delete on a deleted resource # since datastore tries to get the resource through the packate. backend.DatastoreBackend.register_backends() backend.DatastoreBackend.set_active_backend(ckan.common.config) _backend = backend.DatastoreBackend.get_active_backend() _backend.configure(ckan.common.config) for resource in (deleted & datastore_ids): resp = _backend.delete(context, {'resource_id': resource}) #log.debug(resp) log.debug("Deleted %s from datastore" % resource) return {'deleted': len(deleted & datastore_ids)}
def _resubmit_all(self): resource_ids = datastore_backend.get_all_resources_ids_in_datastore() self._submit(resource_ids)
def _resubmit_all(self): resource_ids = datastore_backend.get_all_resources_ids_in_datastore() self._submit(resource_ids)