def delete_item(self, resource, graph): if resource.uri in self.resources.completed: logger.info( f'Resource {resource.uri} has already been deleted; skipping') return title = get_title_string(graph) if self.dry_run: logger.info(f'Would delete resource {resource} {title}') else: response = self.repository.delete(resource.uri) if response.status_code == 204: logger.info(f'Deleted resource {resource} {title}') timestamp = parsedate_to_datetime( response.headers['date']).isoformat('T') self.resources.log_completed(resource.uri, title, timestamp) else: raise RESTAPIException(response)
def update_item(self, resource, graph): if self.resources.completed and resource.uri in self.resources.completed: logger.info( f'Resource {resource.uri} has already been updated; skipping') return headers = {'Content-Type': 'application/sparql-update'} title = get_title_string(graph) if self.validate: try: # Apply the update in-memory to the resource graph graph.update(self.sparql_update.decode()) except ParseException as parse_error: self.stats['errors'][resource.uri].append(str(parse_error)) return # Validate the updated in-memory Graph using the model item = self.model_class.from_graph(graph, subject=resource.uri) validation_result = validate(item) is_valid = validation_result.is_valid() if not is_valid: logger.warning(f'Resource {resource.uri} failed validation') self.stats['invalid'][resource.uri].extend( str(failed) for failed in validation_result.failed()) return if self.dry_run: logger.info(f'Would update resource {resource} {title}') return response = self.repository.patch(resource.description_uri, data=self.sparql_update, headers=headers) if response.status_code == 204: logger.info(f'Updated resource {resource} {title}') timestamp = parsedate_to_datetime( response.headers['date']).isoformat('T') self.resources.log_completed(resource.uri, title, timestamp) self.stats['updated'].append(resource.uri) else: self.stats['errors'][resource.uri].append(str(response))
def update_item(self, resource, graph): if resource.uri in self.resources.completed: logger.info( f'Resource {resource.uri} has already been updated; skipping') return headers = {'Content-Type': 'application/sparql-update'} title = get_title_string(graph) if self.dry_run: logger.info(f'Would update resource {resource} {title}') else: response = self.repository.patch(resource.description_uri, data=self.sparql_update, headers=headers) if response.status_code == 204: logger.info(f'Updated resource {resource} {title}') timestamp = parsedate_to_datetime( response.headers['date']).isoformat('T') self.resources.log_completed(resource.uri, title, timestamp) else: raise RESTAPIException(response)
def list_item(self, resource, graph): if self.long: title = get_title_string(graph) print(f'{resource} {title}') else: print(resource)