-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·109 lines (79 loc) · 2.54 KB
/
server.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
#!/usr/bin/env python
import argparse as _argparse
import logging
import sys as _sys
from application.config.config import DefaultConfig
from application.factory import create_app
_DESCRIPTION_MSG = """ """
_EPILOG_MSG = """
Examples:
"""
class MainArgParse(object):
def __init__(self):
self._g_help = False
self.__verbose__ = False
self._subparser_name = None
self.app = None
self.configuration = ""
self.host_setting = ""
self.port = None
self.psr = _argparse.ArgumentParser(
prog=__file__,
description=_DESCRIPTION_MSG,
epilog=_EPILOG_MSG,
formatter_class=_argparse.RawTextHelpFormatter,
)
self._add_generic_args(self.psr)
self._add_subparser(self.psr)
self.psr.parse_args(args=self._sort_args(), namespace=self)
def apply(self):
config = DefaultConfig("python")
config.obtain_environment_variables()
config.DEBUG = True
config.ENV = "development"
config.LOG_LEVEL = logging.DEBUG
self.app = create_app(config=config)
self.host_setting = self.app.config["FLASK_RUN_HOST"]
self.port = self.app.config["FLASK_RUN_PORT"]
def _add_subparser(self, psr):
# sub = psr.add_subparsers(
# dest="_subparser_name", metavar="sub_commands", help="this is help"
# )
# Example
# sub_command = sub.add_parser("sub_command")
# Add sub commands to list
self._sub_list = []
for item in self._sub_list:
self._add_generic_args(item)
@staticmethod
def _add_generic_args(psr):
psr.add_argument(
"-v",
"--verbose",
dest="__verbose__",
action="store_true",
default=False,
help="enable verbose output debug",
)
def _sort_args(self):
"""
Move all subparsers to the front
"""
sub_names = [x.prog.split()[1] for x in self._sub_list]
sargs = _sys.argv[1:]
for f in sub_names:
if f in sargs:
sargs.remove(f)
sargs.insert(0, f)
return sargs
def __str__(self):
return "\n".join(["Class info goes here!"])
##############################################################################
if __name__ == "__main__":
"""
Main script entry point
"""
_arg = MainArgParse()
_arg.apply()
if _arg.app is not None:
_arg.app.run(host=_arg.host_setting, port=_arg.port)