Skip to content

Commit

Permalink
Remove old CLI from processors.py
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed May 6, 2024
1 parent a8e4e34 commit ad7a2bd
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions ckanext/dcat/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,59 +394,3 @@ def _get_from_extra(key):
g.add((agent, predicate, _type(val)))

return catalog_ref


if __name__ == '__main__':

parser = argparse.ArgumentParser(
description='DCAT RDF - CKAN operations')
parser.add_argument('mode',
default='consume',
help='''
Operation mode.
`consume` parses DCAT RDF graphs to CKAN dataset JSON objects.
`produce` serializes CKAN dataset JSON objects into DCAT RDF.
''')
parser.add_argument('file', nargs='?', type=argparse.FileType('r'),
default=sys.stdin,
help='Input file. If omitted will read from stdin')
parser.add_argument('-f', '--format',
default='xml',
help='''Serialization format (as understood by rdflib)
eg: xml, n3 ... Defaults to \'xml\'.''')
parser.add_argument('-P', '--pretty',
action='store_true',
help='Make the output more human readable')
parser.add_argument('-p', '--profile', nargs='*',
action='store',
help='RDF Profiles to use, defaults to euro_dcat_ap_2')
parser.add_argument('-m', '--compat-mode',
action='store_true',
help='Enable compatibility mode')

parser.add_argument('-s', '--subcatalogs', action='store_true', dest='subcatalogs',
default=False,
help="Enable subcatalogs handling (dct:hasPart support)")
args = parser.parse_args()

contents = args.file.read()

config.update({DCAT_EXPOSE_SUBCATALOGS: args.subcatalogs})

if args.mode == 'produce':
serializer = RDFSerializer(profiles=args.profile,
compatibility_mode=args.compat_mode)

dataset = json.loads(contents)
out = serializer.serialize_dataset(dataset, _format=args.format)
print(out)
else:
parser = RDFParser(profiles=args.profile,
compatibility_mode=args.compat_mode)

parser.parse(contents, _format=args.format)

ckan_datasets = [d for d in parser.datasets()]

indent = 4 if args.pretty else None
print(json.dumps(ckan_datasets, indent=indent))

0 comments on commit ad7a2bd

Please sign in to comment.