-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_ingest_finalization.py
95 lines (69 loc) · 3.24 KB
/
run_ingest_finalization.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
91
92
93
94
95
import argparse
import psycopg2
DB_ENDPOINT = "localhost"
DB_PORT = 5432
DB_USER = ""
DB_PASSWD = ""
DB_NAME = ""
def execute_procedure(stmt, cur, verbose=False):
if verbose is True:
print "Running procedure:", stmt, "...."
sql = """
begin;
select {statement}();
""".format(statement=stmt)
cur.execute(sql)
if verbose is True:
print " Done"
def msf_purge_joins_and_clean_inactive_entries(cur, verbose=False):
execute_procedure("msf_purge_joins_and_clean_inactive_entries", cur, verbose)
def msf_build_vista_sources_relationship(cur, verbose=False):
execute_procedure("msf_build_vista_sources_relationship", cur, verbose)
def msf_build_vista_aviris_plumes_relationship(cur, verbose=False):
execute_procedure("msf_build_vista_aviris_plumes_relationship", cur, verbose)
def msf_build_vista_flightlines_relationship(cur, verbose=False):
execute_procedure("msf_build_vista_flightlines_relationship", cur, verbose)
def msf_build_vista_oil_wells_field_boundary_relationship(cur, verbose=False):
execute_procedure("msf_build_vista_oil_wells_field_boundary_relationship", cur, verbose)
def msf_build_vista_counties_relationship(cur, verbose=False):
execute_procedure("msf_build_vista_counties_relationship", cur, verbose)
def msf_build_sources_flightlines_relationship(cur, verbose=False):
execute_procedure("msf_build_sources_flightlines_relationship", cur, verbose)
def msf_build_sources_counties_relationship(cur, verbose=False):
execute_procedure("msf_build_sources_counties_relationship", cur, verbose)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--endpoint", help="Target PostgreSQL endpoint", type=str, default=DB_ENDPOINT, required=False)
parser.add_argument("-p", "--port", help="Target PostgreSQL port", type=str, default=DB_PORT, required=False)
parser.add_argument("-v", "--verbose",
help="Extra output",
required=False, action="store_true")
parser.add_argument("-t", "--test",
help="Test by parsing and assembling upload document. Don't actually upload to PostgreSQL.",
required=False, action="store_true")
args = parser.parse_args()
test_only = args.test
verbose = args.verbose
db_endpoint = args.endpoint
db_port = args.port
# TODO: Use correct credentials
conn = psycopg2.connect(dbname=DB_NAME, user=DB_USER, password=DB_PASSWD, host=db_endpoint, port=db_port)
cur = conn.cursor()
msf_purge_joins_and_clean_inactive_entries(cur, verbose)
msf_build_vista_sources_relationship(cur, verbose)
msf_build_vista_aviris_plumes_relationship(cur, verbose)
msf_build_vista_flightlines_relationship(cur, verbose)
msf_build_vista_oil_wells_field_boundary_relationship(cur, verbose)
msf_build_vista_counties_relationship(cur, verbose)
msf_build_sources_flightlines_relationship(cur, verbose)
msf_build_sources_counties_relationship(cur, verbose)
if test_only:
if verbose:
print("Testing only, rolling back changes")
conn.rollback()
else:
if verbose:
print("Committing changes")
conn.commit()
cur.close()
conn.close()