-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstartTester.py
More file actions
executable file
·185 lines (157 loc) · 3.9 KB
/
startTester.py
File metadata and controls
executable file
·185 lines (157 loc) · 3.9 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python
import sys, logging.config, json
from bottle import route, post, error, run, template, static_file, request, response
import constant, config, operation, program
logger = logging.getLogger(__name__)
####
@error(404)
def error404(error):
return "404 not found."
@route('/static/<filename>')
def static(filename):
return static_file(filename, root='./static')
@route('/')
def index():
return template(
'main',
)
####
@route('/getProgramSequence')
def getProgramSequence():
try:
html = ''
for op in program.getSequence():
html += template(
'operation/disp/' + op.getType(),
operation = op,
)
return json.dumps({'html' : html})
except Exception as e:
return __exceptionResponse(e)
@route('/addOperation')
def addOperation():
try:
type_ = request.params['type']
op = operation.createByType(type_)
program.addOperation(op)
html = template(
'operation/edit/' + op.getType(),
operation = op,
)
return json.dumps({'html' : html})
except Exception as e:
return __exceptionResponse(e)
@route('/saveOperation')
def saveOperation():
try:
id_ = request.params['id']
op = program.operationById(id_)
op.save(request.params)
html = template(
'operation/disp/' + op.getType(),
operation = op,
)
return json.dumps({'html' : html})
except Exception as e:
return __exceptionResponse(e)
@route('/editOperation')
def editOperation():
try:
id_ = request.params['id']
op = program.operationById(id_)
html = template(
'operation/edit/' + op.getType(),
operation = op,
)
return json.dumps({'html' : html})
except Exception as e:
return __exceptionResponse(e)
@route('/moveOperation')
def moveOperation():
try:
id_ = request.params['id']
upDown = request.params['upDown']
res = program.moveOperationById(id_, upDown)
return json.dumps({'result' : res})
except Exception as e:
return __exceptionResponse(e)
@route('/deleteOperation')
def deleteOperation():
try:
id_ = request.params['id']
op = program.removeOperationById(id_)
del op
html = ''
return json.dumps({'html' : html})
except Exception as e:
return __exceptionResponse(e)
####
@route('/startProgram')
def startProgram():
try:
res = program.start()
return json.dumps({'result' : res})
except Exception as e:
return __exceptionResponse(e)
@route('/stopProgram')
def stopProgram():
try:
res = program.stop()
return json.dumps({'result' : res})
except Exception as e:
return __exceptionResponse(e)
@route('/isProgramRunning')
def isProgramRunning():
try:
res = program.isRunning()
return json.dumps({'result' : res})
except Exception as e:
return __exceptionResponse(e)
@route('/getProgramLog')
def getProgramLog():
try:
res = program.getLog()
return json.dumps({'result' : res})
except Exception as e:
return __exceptionResponse(e)
@route('/eraseProgramLog')
def eraseProgramLog():
try:
res = program.eraseLog()
return json.dumps({'result' : res})
except Exception as e:
return __exceptionResponse(e)
####
@route('/dumpProgram')
def dumpProgram():
try:
dic = program.dump()
return json.dumps({'result' : dic})
except Exception as e:
return str(type(e)) + ' ' + e.message
@post('/restoreProgram')
def restoreProgram():
try:
info = request.files.get('file')
if info.filename.endswith('.json'):
raw = info.file.read()
data = json.loads(raw)
program.restore(data)
else:
raise RuntimeError('file suffix should be : .json')
except Exception as e:
return __exceptionResponse(e)
return getProgramSequence()
####
def __exceptionResponse(e):
return json.dumps({'error' : str(type(e)) + ' ' + e.message})
####
def __startWebServer():
run(server="tornado", host=config.my_host, port=config.my_port, quiet=False, reloader=False)
def main(argv):
logger.debug('starting tester ...')
__startWebServer()
####
if __name__ == "__main__":
logging.config.fileConfig("conf/logger.conf", disable_existing_loggers=False)
main(sys.argv[1:])