-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·56 lines (44 loc) · 1.34 KB
/
run.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
from argparse import ArgumentParser
import logging
import sys
from time import perf_counter
import yaml
from sitemanager.commands import get_command
from sitemanager.database import get_db_session
from sitemanager.sites import import_sites
# Suppress warnings.
if not sys.warnoptions:
import warnings
warnings.simplefilter("ignore")
def main():
cli_args = get_commandline_args()
command_name = normalize_command_name(cli_args.command_name)
command = get_command(command_name)
if command:
config = get_config(cli_args.config_filepath)
command(config)()
else:
print("Error: Command not found: " + command_name)
def get_commandline_args():
parser = ArgumentParser()
parser.add_argument(
"command_name",
help="The command to execute.")
parser.add_argument(
"--config",
help="The path to the config file.",
default="config.yml",
dest="config_filepath")
parser.add_argument(
"--debug",
help="Print debugging logs.",
dest="show_debug_logs",
action="store_true")
return parser.parse_args()
def get_config(filepath: str):
with open(filepath) as file:
return yaml.safe_load(file)
def normalize_command_name(command_name: str):
return command_name.replace("-", "_")
if __name__ == "__main__":
main()