-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoterwarehouse.py
120 lines (109 loc) · 3.8 KB
/
voterwarehouse.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# -*- coding: utf-8 -*-
import argparse
import importlib
import os
from Warehouse.version import __version__
from Warehouse.ImplementedStates import __implemented_states__
# VoterWarehouse command-line Voter and Voter History handling tool
def import_type(args: argparse.Namespace) -> None:
"""
import_type Initializes conditional importing workflows based on what type was requested
:param argparse.Namespace args: Argument dictionary to be evaluated by import types
:return: None
"""
try:
if args.state in __implemented_states__:
if os.path.isfile(args.config):
with getattr(
importlib.import_module(f"Warehouse.{args.state}"),
f"{args.state}"
)(args.config) as state_db:
with getattr(
importlib.import_module(f"Import.{args.state}"),
f"{args.state}"
)(state_db) as state:
if args.file is not None:
if os.path.isfile(args.file):
if args.type in state.valid_import_types.keys():
state.import_source(
args.file,
args.type
)
else:
raise ValueError(f"Usage: Type {args.type} is not valid")
else:
raise FileExistsError(f"Usage: File {args.file} must exist!")
else:
raise ValueError(f"Usage: File must be provided")
else:
raise FileExistsError(f"Usage: Config File must exist!")
else:
raise ValueError(f"Usage: State {args.state} is not implemented")
except Exception as error:
print('Caught this error: ' + repr(error))
raise
def main(args: argparse.Namespace) -> None:
"""
main Sets up the conditional actions workflow based on the specified action
:param argparse.Namespace args: Argument dictionary to be evaluated by action types
:return: None
"""
try:
match args.action:
case "import":
if args.file is not None:
import_type(args)
else:
raise ValueError(f"Usage: File must be provided")
case _:
raise ValueError(f"Usage: Action {args.action} is not valid")
except Exception as error:
print('Caught this error: ' + repr(error))
raise
if __name__ == '__main__':
"""
__name__ Initializes the application and parses the parameters
:return: None
"""
try:
parser = argparse.ArgumentParser()
parser.add_argument(
"-s",
"--state",
help="The State Name",
default="Florida"
)
parser.add_argument(
"-a",
"--action",
help="Action"
)
parser.add_argument(
"-t",
"--type",
help="Type"
)
parser.add_argument(
"-f",
"--file",
help="File"
)
parser.add_argument(
"-c",
"--config",
help="Config YAML File",
default="/etc/VoterWarehouse/config.yml"
)
parser.add_argument(
'-v',
'--version',
action='version',
version=__version__
)
try:
main(parser.parse_args())
except KeyboardInterrupt:
print("\nShutdown by keyboard interrupt...exiting")
except Exception as e:
print('Caught this error: ' + repr(e))
raise