forked from misterrodg/FacilityMapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (54 loc) · 1.94 KB
/
main.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
from modules.DirPaths import MANIFEST_DIR, NAVDATA_DIR, VIDMAP_DIR
from modules.FileHandler import check_path, delete_all_in_subdir
from modules.Manifest import Manifest
from cifparse import CIFP
import argparse
import os
import sqlite3
DB_FILE_PATH = f"{NAVDATA_DIR}/FAACIFP18.db"
CIFP_FILE_PATH = f"{NAVDATA_DIR}/FAACIFP18"
DEFAULT_MANIFEST_NAME = "manifest.json"
def purge_vidmaps() -> None:
if check_path(VIDMAP_DIR):
delete_all_in_subdir(".geojson", VIDMAP_DIR)
def refresh_database() -> None:
if os.path.exists(DB_FILE_PATH):
os.remove(DB_FILE_PATH)
connection = sqlite3.connect(DB_FILE_PATH)
cursor = connection.cursor()
c = CIFP(CIFP_FILE_PATH)
c.initialize_database(cursor)
c.parse()
c.to_db(cursor)
connection.commit()
connection.close()
def main():
parser = argparse.ArgumentParser(description="FacilityMapper")
parser.add_argument(
"-p", "--purge", action="store_true", help="purge files from vidmaps dir"
)
parser.add_argument("-r", "--refresh", action="store_true", help="refresh database")
parser.add_argument(
"-m", "--manifest", type=str, help="user-defined manifest file name"
)
parser.add_argument("-n", "--nodraw", action="store_true", help="skip draw")
args = parser.parse_args()
should_purge = args.purge
should_refresh = args.refresh
should_skip_draw = args.nodraw
alternate_manifest_file = args.manifest
if should_purge:
purge_vidmaps()
if should_refresh:
refresh_database()
if not should_skip_draw:
connection = sqlite3.connect(DB_FILE_PATH)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
manifest_file = DEFAULT_MANIFEST_NAME
if alternate_manifest_file != None:
manifest_file = f"{MANIFEST_DIR}/{alternate_manifest_file}"
Manifest(cursor, manifest_file)
connection.close()
if __name__ == "__main__":
main()