-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurge_vista.py
53 lines (43 loc) · 1.48 KB
/
purge_vista.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
import os.path
from osgeo import gdal,ogr,osr
import argparse
import psycopg2
from ingestutils import sectors
DB_ENDPOINT = "localhost"
DB_PORT = 5432
DB_USER = ""
DB_PASSWD = ""
DB_NAME = ""
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()
sql = """
begin;
select msf_purge_vista();
"""
cur.execute(sql)
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()