-
Notifications
You must be signed in to change notification settings - Fork 2
/
tool.py
59 lines (43 loc) · 1.56 KB
/
tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
PIT command line tool
Use:
show provenance file infomration
pit <filepath>
"""
import click
import os
import json
import sys
from pit.prov import Provenance, load_prov
import pprint
@click.command()
@click.option("--add", is_flag=True, help="Add provenance information layer to file")
@click.option("--agent", "-a", default="", help="Provenance information: agent")
@click.option("--activity", default="", help="Provenane information: activity")
@click.option("--desc", "-d", default="", help="Provenance information: Description of the data manipulation process")
@click.option("--origin", "-o", default="", help="Provenance information: Data origin")
@click.option("--sources", "-s", multiple=True, default="", help="Provenance information: Source files")
@click.argument("filepath")
def cli(agent, filepath, add, desc, activity, origin, sources):
pp = pprint.PrettyPrinter(indent=1)
if not os.path.exists(filepath):
print("Invalid filepath")
return
if not add:
prov = load_prov(filepath)
if not prov:
print("No provenance Information available")
return
elif add:
prov = Provenance(filepath)
if agent and activity and desc:
prov.add(agent=agent, activity=activity, description=desc)
prov.save()
if sources:
for source in sources:
prov.add_sources(source)
prov.save()
if origin:
prov.add_primary_source(origin)
prov.save()
pp.pprint(prov.tree())