-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapibox.py
93 lines (65 loc) · 2.4 KB
/
apibox.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
#!/usr/bin/python
"""
API Box Launcher.
Sample usage to launch mock API server:
with a specified port (default - 5000):
apibox.py -p <port_number>
with a api config file (default file type - JSON)
apibox.py -f <path_to_file> -t <file_content_type>
with user interface enabled:
apibox.py -ui
"""
import logging as log
import sys
import getopt
import argparse
import multiprocessing as mp
from apibox.ui.server import UIServer
from apibox.server import *
def verify_virtualenv():
'Verifies the virtual environment.'
# TODO verify dependencies
pass
Mul = mp
def process_arguments(args):
"""
Entry point of the project. Parses args and processes.
:param argv: commandline arguments.
"""
port = args.port
file_path = args.file
file_type = args.type
enable_ui = args.ui
verbose = args.verbosity
# launch APP server from file
if file_path and enable_ui:
p = mp.Process(target=launch_app_server_from_file, args=(port, file_path, file_type))
p.daemon = True
p.start()
ui_server = UIServer()
q = mp.Process(target=ui_server.start())
q.daemon=True
q.start()
p.join()
q.join()
if file_path:
launch_app_server_from_file(port, file_path,file_type)
# Launch the UI server
if enable_ui:
ui_server = UIServer()
ui_server.start()
# TODO Handle verbosity
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
#parser.add_argument("cmd")
#parser.add_argument("-h", "--host", default="0.0.0.0", help="Server hostname")
parser.add_argument("-p", "--port", action="store", type=int, default=5000, help="Server port")
parser.add_argument("-ui", "--ui", action="store_true", default=False, help="Initiate the server with UI")
parser.add_argument("-f", "--file", action="store", required=False, help="RESTful api configuration file")
parser.add_argument("-t", "--type", action="store", default="JSON", help="Configuration file type")
parser.add_argument("-v", "--verbosity", action="store_true", default=False, help="Increase output verbosity")
args = parser.parse_args()
# Verify vitual environment settings
verify_virtualenv()
# Process the arguments and start the necessary services accordingly.
process_arguments(args)