Coverage for oc_meta / run / meta_editor.py: 18%
22 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-03 17:25 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-03 17:25 +0000
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3# Copyright 2021-2022 Arcangelo Massari <arcangelo.massari@unibo.it>
4#
5# Permission to use, copy, modify, and/or distribute this software for any purpose
6# with or without fee is hereby granted, provided that the above copyright notice
7# and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
12# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
13# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15# SOFTWARE.
17from argparse import ArgumentParser
19from rdflib import URIRef
21from oc_meta.core.editor import MetaEditor
23if __name__ == '__main__':
24 arg_parser = ArgumentParser('meta_editor.py', description='This script edits OpenCitations Meta triplestore, RDF and provenance')
25 arg_parser.add_argument('-c', '--config', dest='config', required=True, help='Configuration file directory')
26 arg_parser.add_argument('-op', '--operation', dest='operation', required=True, choices=['update', 'delete', 'sync', 'merge'], help='The CRUD operation to perform')
27 arg_parser.add_argument('-s', '--subject', dest='res', required=True, type=URIRef, help='The subject entity')
28 arg_parser.add_argument('-p', '--property', dest='property', required=False, help='The property')
29 arg_parser.add_argument('-o', '--object', dest='value', required=False, help='The value')
30 arg_parser.add_argument('-ot', '--other', dest='other', required=False, help='Other res to be merged with res')
31 arg_parser.add_argument('-r', '--resp', dest='resp_agent', required=True, help='Your ORCID')
32 args = arg_parser.parse_args()
33 meta_editor = MetaEditor(args.config, args.resp_agent)
34 if args.operation == 'update':
35 meta_editor.update_property(args.res, args.property, args.value)
36 elif args.operation == 'delete':
37 meta_editor.delete(args.res, args.property, args.value)
38 elif args.operation == 'sync':
39 meta_editor.sync_rdf_with_triplestore(args.res)
40 elif args.operation == 'merge':
41 meta_editor.merge(URIRef(args.res), URIRef(args.other))