Exemple #1
0
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)
Exemple #2
0
for name, val in program_defaults.items():
    vars(args)[name] = val

if args.verbose:
    print datetime.now(), "Arguments\n", vars(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, query_parms={'query_uri': args.queryuri,
                                                                         'username': args.pwd, 'password': args.pwd},
         uri_prefix=args.uriprefix)
if args.action == 'get':
    n_rows = p.get(args.src, args.inter, args.intra)
    print datetime.now(), n_rows, "rows in", args.src
elif args.action == 'update':
    [add_graph, sub_graph] = p.update(args.src, args.inter, args.intra)
    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()
else:
    print datetime.now(), "Unknown action.  Try sv -h for help"
print datetime.now(), "Finish"
Exemple #3
0
 def test_default_usage(self):
     p = Pump()
     p.update()
     self.assertTrue("data/pump_def.json" in p.summarize())  # Using the default definition
Exemple #4
0
 def test_normal_case(self):
     p = Pump("data/person_def.json", verbose=True)
     print p.summarize()
Exemple #5
0
 def test_pump_summarize(self):
     p = Pump("data/building_def.json")
     result = p.summarize()
     print result
     self.assertTrue("Pump Summary for data/building" in result)