11#!/usr/bin/env python3
22
3+ import logging
34from vfb .curation .peevish import get_recs
45from vfb .curation .curation_loader import load_recs
5- #from vfb.curation.cur_load import NewMetaDataWriter, NewImageWriter
66import argparse
77import warnings
88import os
13132. Test load records in 'to_submit/'.
1414"""
1515# What logic, if any should live here?
16-
1716## Should it know about the gross type of records and direct to the appropriate loading method, where gross currently = new_dataSet vs new_metadata, vs new image. Shouldn't a record sorter be able to do that?
18-
19-
17+
18+ # Argument parser setup
2019parser = argparse .ArgumentParser ()
21- parser .add_argument ("endpoint" ,
22- help = "Endpoint for connection to neo4J prod" )
23- parser .add_argument ("usr" ,
24- help = "username" )
25- parser .add_argument ("pwd" ,
26- help = "password" )
27- parser .add_argument ("--import_filepath" ,
28- help = "path to file usable for writing to DB via tsv" , default = '' )
20+ parser .add_argument ("endpoint" , help = "Endpoint for connection to neo4J prod" )
21+ parser .add_argument ("usr" , help = "username" )
22+ parser .add_argument ("pwd" , help = "password" )
23+ parser .add_argument ("--import_filepath" , help = "path to file usable for writing to DB via tsv" , default = '' )
2924parser .add_argument ("--base_path" , help = "Optional" , default = "../" )
3025parser .add_argument ("--test_mode" , help = "Optional" , action = 'store_true' , default = False )
31- parser .add_argument ("--commit" , help = "Optional" , action = 'store_true' , default = False )
32- parser .add_argument ("--verbose" , help = "Optional" , action = 'store_true' , default = False )
33- parser .add_argument ("--allow_duplicates" , help = "Optional" , action = 'store_true' , default = False )
26+ parser .add_argument ("--commit" , help = "Optional" , action = 'store_true' , default = False )
27+ parser .add_argument ("--verbose" , help = "Optional" , action = 'store_true' , default = False )
28+ parser .add_argument ("--allow_duplicates" , help = "Optional" , action = 'store_true' , default = False )
29+ parser .add_argument ("--debug" , help = "Enable debug logging" , action = 'store_true' , default = False )
3430args = parser .parse_args ()
3531
36-
37-
38- def check_records (path , check_dir = "working" ):
39- rec_path = '/' .join ([args .base_path , path , check_dir ]) + '/'
40- recs = get_recs (spec_path = "../records/" + path ,
41- path_to_recs = rec_path )
42- stat = True
43- if len (recs ) == 0 :
44- print ("No records to check in: " + rec_path )
45- else :
46- print ("Testing syntax of %s curation records." % len (recs ))
47- if False in recs :
48- stat = False
49- return stat
50-
51-
52-
53- def load_records (path , load_dir = "to_submit" ):
54- rec_path = os .path .abspath (os .path .join (args .base_path , path , load_dir ))
55- current_dir = os .path .dirname (os .path .realpath (__file__ ))
56- records_path = os .path .abspath (os .path .join (current_dir , "../records" , path ))
57- stat = load_recs (records_path + '/' , rec_path + '/' ,
58- args .endpoint , args .usr , args .pwd , import_filepath = args .import_filepath ,
59- commit = args .commit , verbose = args .verbose , allow_duplicates = args .allow_duplicates )
60- return stat
61-
32+ # Configure logging
33+ if args .debug :
34+ logging .basicConfig (level = logging .DEBUG , format = '%(asctime)s - %(levelname)s - %(message)s' )
35+ elif args .verbose :
36+ logging .basicConfig (level = logging .INFO , format = '%(asctime)s - %(levelname)s - %(message)s' )
37+ else :
38+ logging .basicConfig (level = logging .WARNING , format = '%(asctime)s - %(levelname)s - %(message)s' )
39+
40+ def check_records (path , check_dir = "working" ):
41+ """
42+ Checks the records in the specified directory.
43+
44+ Parameters:
45+ path (str): The base path to check records in.
46+ check_dir (str): The directory within the base path to check records in.
47+
48+ Returns:
49+ bool: True if records pass the check, False otherwise.
50+ """
51+ try :
52+ logging .debug ("Starting check_records with path: %s and check_dir: %s" , path , check_dir )
53+ rec_path = '/' .join ([args .base_path , path , check_dir ]) + '/'
54+ logging .debug ("Constructed rec_path: %s" , rec_path )
55+
56+ recs = get_recs (spec_path = "../records/" + path , path_to_recs = rec_path )
57+ logging .debug ("Retrieved records: %s" , recs )
58+
59+ stat = True
60+ if len (recs ) == 0 :
61+ logging .info ("No records to check in: %s" , rec_path )
62+ else :
63+ logging .info ("Testing syntax of %s curation records." , len (recs ))
64+
65+ if False in recs :
66+ logging .warning ("Some records failed the check." )
67+ stat = False
68+
69+ return stat
70+
71+ except Exception as e :
72+ logging .error ("An error occurred in check_records: %s" , e , exc_info = True )
73+ return False
74+
75+ def load_records (path , load_dir = "to_submit" ):
76+ """
77+ Loads the records from the specified directory.
78+
79+ Parameters:
80+ path (str): The base path to load records from.
81+ load_dir (str): The directory within the base path to load records from.
82+
83+ Returns:
84+ bool: True if records are successfully loaded, False otherwise.
85+ """
86+ try :
87+ logging .debug ("Starting load_records with path: %s and load_dir: %s" , path , load_dir )
88+ rec_path = os .path .abspath (os .path .join (args .base_path , path , load_dir ))
89+ logging .debug ("Constructed rec_path: %s" , rec_path )
90+
91+ current_dir = os .path .dirname (os .path .realpath (__file__ ))
92+ records_path = os .path .abspath (os .path .join (current_dir , "../records" , path ))
93+ logging .debug ("Constructed records_path: %s" , records_path )
94+
95+ stat = load_recs (records_path + '/' , rec_path + '/' ,
96+ args .endpoint , args .usr , args .pwd , import_filepath = args .import_filepath ,
97+ commit = args .commit , verbose = args .verbose , allow_duplicates = args .allow_duplicates )
98+
99+ logging .debug ("load_recs returned status: %s" , stat )
100+ return stat
101+
102+ except Exception as e :
103+ logging .error ("An error occurred in load_records: %s" , e , exc_info = True )
104+ return False
62105
63106stat = True
64107
65-
66108if not check_records (path = "new_metadata/" ): stat = False
67109if not load_records (path = "new_metadata/" ): stat = False
68110if not check_records (path = "new_images/" ): stat = False
69111if not load_records (path = "new_images/" ): stat = False
112+ if not check_records (path = "new_splits/" ): stat = False
113+ if not load_records (path = "new_splits/" ): stat = False
70114
71115if not stat :
72116 raise Exception ("Failing records. See preceding warnings for details." )
@@ -77,8 +121,9 @@ def load_records(path, load_dir = "to_submit"):
77121 print ("Running record syntax fails tests" )
78122 check_records (path = "new_metadata/" , check_dir = "test_syntax_fail" )
79123 check_records (path = "new_images/" , check_dir = "test_syntax_fail" )
124+ # check_records(path="new_splits/", check_dir="test_syntax_fail")
125+
80126 print ("Running fail tests." )
81127 load_records (path = "new_metadata/" , load_dir = "test_load_fail" )
82128 load_records (path = "new_images/" , load_dir = "test_load_fail" )
83-
84-
129+ # load_records(path="new_splits/", load_dir="test_load_fail")
0 commit comments