-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathplate.py
57 lines (43 loc) · 1.44 KB
/
plate.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
# -*- coding:utf-8 -*-
try:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
except NameError:
pass
import optparse
from plate import create_app
from plate import start_service_server
from plate import start_test_server
from plate.api_document import APIDocument
from plate.common.config import Config
from plate.watchdocs.api_document_observer import APIDocumentObserver
def parse_argument():
p = optparse.OptionParser('-m [test] or [run]')
try:
p.add_option('-m', dest='mode', type='string', default='run')
options, args = p.parse_args()
return options.mode
except:
print(p.get_usage())
sys.exit()
def test_mode(app):
start_test_server(app=app, port=app.config['PORT'])
def service_mode(app):
start_service_server(app=app, port=app.config['PORT'])
if __name__ == '__main__':
m = parse_argument()
config = Config.load_conf('./config.json')
# create documents
api_doc = APIDocument(config)
app = create_app(config=config)
api_doc_observer = APIDocumentObserver(doc_path=app.config['API_DOC_PATH'],
doc_index_path=app.config['API_DOC_INDEX_PATH'],
doc_file_path_list=api_doc.toc['ORDER'])
api_doc_observer.start_watch()
if m == 'test':
test_mode(app=app)
elif m == 'run':
service_mode(app=app)
else:
raise Exception("Not valid mode")