def import_all(self): """Import content.""" content_digest = Config.operation_digest content_uuid = Config.operation_uuid if content_digest or content_uuid: collection = self._storage.search(uuid=content_uuid, digest=content_digest) if len(collection) == 1: resource = next(collection.resources()) digest = resource.digest updates = Migrate.load(Config.get_operation_file()) self._logger.debug('updating: %s ' % resource.category, ':with: uuid: %.16s' % content_uuid if content_uuid else ':with: digest: %.16s' % resource.digest) if len(updates) == 1: resource.migrate(next(updates.resources())) self._storage.update(digest, resource) else: Cause.push(Cause.HTTP_BAD_REQUEST, 'updates for content: %.16s :could not be used' % digest) else: Config.validate_search_context(collection, 'import') else: self._logger.debug('importing content: %s', Config.get_operation_file()) collection = Migrate.load(Config.get_operation_file()) self._storage.import_content(collection)
def update(self): """Update content.""" collection = self._storage.search( scat=Config.search_cat_kws, sall=Config.search_all_kws, stag=Config.search_tag_kws, sgrp=Config.search_grp_kws, search_filter=Config.search_filter, uuid=Config.operation_uuid, digest=Config.operation_digest, identity=Config.operation_identity, data=Config.content_data ) if len(collection) == 1: stored = next(collection.resources()) digest = stored.digest updates = Config.get_resource(stored) if updates and updates != stored: self._logger.debug('updating stored: %s :with digest: %.16s', self._category, digest) stored.migrate(updates) self.collection = self._storage.update(digest, stored) else: self._logger.debug('content: %s :with digest: %.16s :was not updated', self._category, digest) else: Config.validate_search_context(collection, 'update')
def delete(self): """Delete content.""" collection = self._storage.search( scat=Config.search_cat_kws, sall=Config.search_all_kws, stag=Config.search_tag_kws, sgrp=Config.search_grp_kws, search_filter=Config.search_filter, uuid=Config.operation_uuid, digest=Config.operation_digest, identity=Config.operation_identity, data=Config.content_data ) if len(collection) == 1: resource = next(collection.resources()) self._logger.debug('deleting: %s :with digest: %.16s', resource.category, resource.digest) self._storage.delete(resource.digest) else: Config.validate_search_context(collection, 'delete')
def export_all(self): """Export content.""" if Config.template: self._logger.debug('exporting: %s :template: %s', self._category, Config.get_operation_file()) Migrate.dump_template(self._category) elif Config.complete: Migrate.dump_completion(Config.complete) elif Config.is_search_criteria(): self._logger.debug('exporting: %s :based on search criteria', self._category) collection = self._storage.search( scat=Config.search_cat_kws, sall=Config.search_all_kws, stag=Config.search_tag_kws, sgrp=Config.search_grp_kws, search_filter=Config.search_filter, uuid=Config.operation_uuid, digest=Config.operation_digest, identity=Config.operation_identity, data=Config.content_data ) if not collection: Config.validate_search_context(collection, 'export') else: filename = Config.get_operation_file(collection=collection) Migrate.dump(collection, filename) else: if Config.defaults: for category in Config.search_cat_kws: collection = self._storage.export_content((category,)) filename = Config.default_content_file(category) self._logger.debug('exporting all: %s :content to: %s', category, filename) Migrate.dump(collection, filename) else: collection = self._storage.export_content(Config.search_cat_kws) filename = Config.get_operation_file(collection=collection) self._logger.debug('exporting all: %s :content to: %s', self._category, filename) Migrate.dump(collection, filename)