forked from mconlon17/vivo-pump
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsv.py
executable file
·90 lines (76 loc) · 3.5 KB
/
sv.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
sv.py: Simple VIVO
Uses the VIVO Pump to provide data management service for VIVO. Tabular data is mapped by the pump in and out
of VIVO.
Produce a spreadsheet from VIVO that has the entities and attributes ready for editing and updating
Inputs: spreadsheet containing updates and additions. Definition file containing maps to/from columns to
VIVO objects. Enumeration tables for translating spreadsheet values to VIVO values and back. VIVO for
current state. Config file with parameters describing VIVO and the pump actions.
Outputs: spreadsheet with current state. VIVO state changes. stdout with date times and messages.
See CHANGELOG.md for history
"""
__author__ = "Michael Conlon"
__copyright__ = "Copyright (c) 2015 Michael Conlon"
__license__ = "New BSD License"
__version__ = "0.8.5"
# Simple VIVO uses three sources for parameters to control its actions. The _last_ value found is the value that
# is used
# 1. Defaults in the code. These defaults are coded for each parameter in the add_argument calls below
# 2. Values in the config file. sv.py will read a config file and set the values of the parameters
# 3. Command line parameters
#
# Program defaults are overwritten by config file values which are overwritten by command line parameters. Each
# parameter is handled independently of the others. So one parameter might be set by the command line, another
# by program defaults (because it was unspecified on the command line and was not specified in the config file)
# and a third parameter's value might come from the config file, overwriting the program default and left unspecified
# on the command line
def main():
"""
The main function. Does the work of Simple VIVO
:return: None
"""
import sys
from datetime import datetime
from vivopump import get_args
from pump import Pump
return_code = 0
print datetime.now(), "Start"
args = get_args()
# Create a Pump and use it to perform the requested actions based on arguments
p = Pump(args.defn, args.src, args.verbose, args.nofilters, args.inter, args.intra, args.rdfprefix,
query_parms={'queryuri': args.queryuri,
'username': args.username,
'password': args.password,
'prefix': args.prefix,
'uriprefix': args.uriprefix})
if args.action == 'get':
n_rows = p.get()
print datetime.now(), n_rows, "rows in", args.src
elif args.action == 'update':
try:
[add_graph, sub_graph] = p.update()
except IOError:
print "File not found"
return_code = 1
else:
add_file = open(args.rdfprefix + '_add.rdf', 'w')
print >>add_file, add_graph.serialize(format='nt')
add_file.close()
sub_file = open(args.rdfprefix + '_sub.rdf', 'w')
print >>sub_file, sub_graph.serialize(format='nt')
sub_file.close()
print datetime.now(), len(add_graph), 'triples to add', len(sub_graph), 'triples to sub'
elif args.action == 'summarize':
print p.summarize()
elif args.action == 'serialize':
print p.serialize()
elif args.action == 'test':
print p.test()
else:
print datetime.now(), "Unknown action. Try sv -h for help"
print datetime.now(), "Finish"
sys.exit(return_code)
if __name__ == "__main__":
main()