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)
# Put the final values back in args 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:
def test_get_filter(self): p = Pump("data/building_def.json") n_rows = p.get("data/buildings_filtered.txt") self.assertEqual(951, n_rows)
def test_get_no_filter(self): p = Pump("data/building_def.json") p.filter = False n_rows = p.get("data/buildings_nofilter.txt") self.assertEqual(951, n_rows)
def test_pump_get(self): p = Pump("data/building_def.json") n_rows = p.get("data/buildings.txt") print n_rows self.assertEqual(951, n_rows)
def test_pump_get_no_filename(self): p = Pump("data/building_def.json") with self.assertRaises(TypeError): n_rows = p.get() print n_rows