-
Notifications
You must be signed in to change notification settings - Fork 1
/
entry.py
executable file
·65 lines (51 loc) · 1.95 KB
/
entry.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
# PYTHON_ARGCOMPLETE_OK
import os
import argcomplete
import argparse
from importlib import import_module
SUBMODULES = {
"cmdl": "porthouse.cmdl",
"launch": "porthouse.launcher",
"scheduler": "porthouse.gs.scheduler.schedule",
"packets": "porthouse.mcs.packets.packets",
"housekeeping": "porthouse.mcs.housekeeping.tools"
}
PORTHOUSE_BANNER = "\n".join([
r" _ _ ",
r" _ __ ___ _ __| |_| |__ ___ _ _ ___ ___ ",
r"| '_ \ / _ \| '__| __| '_ \ / _ \| | | / __|/ _ \ ",
r"| |_) | (_) | | | |_| | | | (_) | |_| \__ \ __/ ",
r"| .__/ \___/|_| \__|_| |_|\___/ \__,_|___/\___| ",
r"|_| ",
"\n"
])
class PorthouseHelpFormatter(argparse.HelpFormatter):
""" Custom Help formatter class to add the porthouse banner. """
def format_help(self):
return PORTHOUSE_BANNER + super().format_help()
def main():
"""
"""
parser = argparse.ArgumentParser(description="Porthouse command line utility", formatter_class=PorthouseHelpFormatter)
utility = parser.add_argument('utility', choices=SUBMODULES.keys())
# General configs
parser.add_argument('--amqp', dest="amqp_url",
help="AMQP connection URL.")
parser.add_argument('--db', dest="db_url",
help="PostgreSQL database URL.")
if "_ARGCOMPLETE" in os.environ:
# Call custom setup_parser before trying autocompleting
package = None
line = os.environ["COMP_LINE"]
for module, package_import in SUBMODULES.items():
if module in line:
package = import_module(package_import)
package.setup_parser(parser)
break
argcomplete.autocomplete(parser)
return
args, _ = parser.parse_known_args()
package = import_module(SUBMODULES[args.utility])
package.setup_parser(parser)
args = parser.parse_args()
package.main(parser, args)