-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path6_build_cdm_era_tbl.py
42 lines (38 loc) · 1.57 KB
/
6_build_cdm_era_tbl.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
import os
import sys
import time
import glob
from importlib.machinery import SourceFileLoader
mapping_util = SourceFileLoader('mapping_util', os.path.dirname(os.path.realpath(__file__)) + '/mapping_util.py').load_module()
# ---------------------------------------------------------
# MAIN PROGRAM
# ---------------------------------------------------------
def main():
ret = True
try:
(ret, dir_study, db_conf, debug) = mapping_util.get_parameters()
if ret == True and dir_study != '':
database_type = db_conf['database_type']
target_schema = db_conf['target_schema']
dir_sql = os.getcwd() + "\\sql_scripts\\"
# ---------------------------------------------------------
# Create ERA tables
# ---------------------------------------------------------
qa = input('Are you sure you want to create the ERA tables (y/n):')
while qa.lower() not in ['y', 'n', 'yes', 'no']:
qa = input('I did not understand that. Are you sure you want to create the era tables (y/n):')
if qa.lower() in ['y', 'yes']:
time1 = time.time()
print('Create ERA tables ...')
sql_file_list = sorted(glob.iglob(dir_sql + '6a_cdm_era_*.sql'))
ret = mapping_util.execute_sql_files_parallel(db_conf, sql_file_list, True)
if ret == True:
msg = 'All ERA tables built on ' + database_type.upper() + ' in ' + mapping_util.calc_time(time.time() - time1)
print(msg)
except:
print(str(sys.exc_info()[1]))
# ---------------------------------------------------------
# Protect entry point
# ---------------------------------------------------------
if __name__ == "__main__":
main()