-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__main__.py
72 lines (57 loc) · 2.01 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
71
72
from dotenv import load_dotenv
import argparse
import sys
import signal
from tasks import getTask, taskList
import datetime
load_dotenv()
if __name__ == "__main__":
# trap SIGINT and SIGTERM to ensure graceful exit
def signal_handler(sig, frame):
print(f"{datetime.datetime.now()} Signal {sig} received. Exiting.\n\n")
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
parser = argparse.ArgumentParser(
prog="polis-argmap",
description="Run tasks on Polis datasets using ArgMap",
epilog="Source: https://github.com/aadityabhatia/polis-argmap"
)
parser.add_argument(
'--datasets', '-d',
help="Comma-separated list of datasets to process",
type=str,
required=True,
)
parser.add_argument(
'--output', '-o',
help="Output file for console log; default is stdout",
type=argparse.FileType('a'),
default=sys.stdout
)
parser.add_argument(
'tasks',
help="List of tasks to run, space-separated",
type=str,
nargs='+',
choices=taskList,
)
args = parser.parse_args()
datasets = args.datasets.split(",")
sys.stdout = args.output
print("=" * 80)
print(f"{datetime.datetime.now()} Starting Polis ArgMap Tasks...", flush=True)
for dataset in datasets:
print(f"{datetime.datetime.now()} Dataset: {dataset}", flush=True)
for task in args.tasks:
try:
print(f"{datetime.datetime.now()} Task: {task}", flush=True)
Task = getTask(task)
Task.run(dataset)
print(f"{datetime.datetime.now()} Task Complete: {task}", flush=True)
except Exception as e:
print(f"{datetime.datetime.now()} ERROR: {e}")
print(f"{datetime.datetime.now()} ERROR: {e}", file=sys.stderr)
import traceback
traceback.print_exc()
print()
print(f"{datetime.datetime.now()} All Datasets Processed.\n")