This repository was archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagechecking.py
More file actions
executable file
·219 lines (191 loc) · 8.24 KB
/
Copy pathimagechecking.py
File metadata and controls
executable file
·219 lines (191 loc) · 8.24 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#coding=utf-8
import json
import os
import os.path
import random
import string
import cherrypy
import sys
import uuid
reload(sys)
sys.setdefaultencoding('utf8')
MYDIR = os.path.dirname(os.path.realpath(__file__))
class ResultReader(object):
exposed = True
_content = None
_hjob = None
def __init__(self, hjob):
self._hjob = hjob
@cherrypy.tools.accept(media='text/plain')
def POST(self):
cherrypy.response.headers['Content-Type']= 'text/html'
htmltpl = self._load_htmltpl()
content = "<div style='width: 100%'>"
content += "<table style='width:90%'><tr><td>"
content += "<form method='post' action=/resultreader>"
content += "<input type='submit' value='刷新'></form>"
content += "</td></tr></table><br>"
content += "</div>"
if self._hjob.hadoop_outdir:
hout_dir = os.path.join(MYDIR, "data", self._hjob.hadoop_outdir)
if os.path.exists(hout_dir):
content += "<table border='1' style='width:90%;border: 1px solid black;border-collapse: collapse;'><tr>"
content += "<th>图片名称</th>"
content += "<th>是否编辑过</th>"
content += "<th>检查点</th>"
content += "<th>编辑软件</th>"
content += "<th>ELA</th>"
content += "</tr>"
results = []
f = open(os.path.join(hout_dir, "part-00000"))
while True:
line = f.readline()
if not line:
break
try:
results.append(json.loads(line))
except:
pass
results.sort(reverse=True)
for pic_res in results:
if not pic_res:
continue
pic_name = pic_res.get("name")
edited = pic_res.get("edited")
reason = pic_res.get("reason") or ""
software = pic_res.get("software") or ""
ela = pic_res.get("ela") or 0
if not pic_name:
continue
pic_name = pic_name[len(self._hjob.picdir):]
content += "<tr><td>" + pic_name + "</td>"
if "yes" == edited:
content += "<td style='background-color:red;'>" + edited + "</td>"
else:
content += "<td>" + edited + "</td>"
content += "<td>" + reason + "</td>"
content += "<td>" + software + "</td>"
if ela >= 50:
content += "<td style='background-color:yellow;'>%d</td>" % ela
else:
content += "<td>%d</td>" % ela
content += "</tr>"
content += "</table>"
return htmltpl.replace("$$TOREPLACE$$", content)
def _load_htmltpl(self):
if self._content:
return self._content
f = open("./html.tpl")
self._content = f.read()
f.close()
return self._content
class LogReader(object):
exposed = True
_content = None
_hjob = None
def __init__(self, hjob):
self._hjob = hjob
@cherrypy.tools.accept(media='text/plain')
def POST(self):
cherrypy.response.headers['Content-Type']= 'text/html'
htmltpl = self._load_htmltpl()
content = "<div style='width: 100%'>"
content += "<table style='width:40%'><tr><td>"
content += "<form method='post' action=/logreader>"
content += "<input type='submit' value='刷新'></form></td>"
if self._hjob.hadoop_outdir:
hout_dir = os.path.join(MYDIR, "data", self._hjob.hadoop_outdir)
if os.path.exists(hout_dir):
content += "<td><form method='post' action=/resultreader>"
content += "<input type='submit' value='查看运行结果'></form></td>"
content += "</tr></table><br>"
if os.path.exists("./hjob.log"):
content += "<table style='width:80%;border: 1px solid black;border-collapse: collapse;'>"
f = open("./hjob.log")
lines = f.readlines()
f.close()
for line in lines:
content += "<tr><td>" + line + "</td></tr>"
content += "</table><br>"
content += "</div>"
return htmltpl.replace("$$TOREPLACE$$", content)
def _load_htmltpl(self):
if self._content:
return self._content
f = open("./html.tpl")
self._content = f.read()
f.close()
return self._content
class ImageChecking(object):
exposed = True
_content = None
_picdir = "./data/pics"
_hjob = None
def __init__(self, hjob):
self._hjob = hjob
@cherrypy.tools.accept(media='text/plain')
def GET(self):
if not self._hjob.running:
htmltpl = self._load_htmltpl()
content = "<div style='width: 300px'>"
if self._hjob.hadoop_outdir:
content += "<table style='width:100%'><tr><td>"
content += "<form method='post' action=/logreader>"
content += "<input type='submit' value='查看上次运行日志'></form>"
content += "<td><form method='post' action=/resultreader>"
content += "<input type='submit' value='查看上次运行结果'></form>"
content += "</td></tr></table><br><br>"
content += "<p style='font-size: 16px; width: 300px; margin-top: 0px'>"
content += "请选择需要导入的图片目录:</p></div>"
content += "<form method='post' action=/imagechecking>"
content += "<table style='width:100%'>"
if os.path.exists(self._picdir):
pic_dirs = os.listdir(self._picdir)
for d in pic_dirs:
content += "<tr><td><input type='checkbox' name='picdirs' value='%s'>%s</td></tr>" % (d, d)
content += "<br><tr><td><input type='submit' value='开始导入数据'></td></tr></table></form>"
cherrypy.response.headers['Content-Type']= 'text/html'
return htmltpl.replace("$$TOREPLACE$$", content)
else:
htmltpl = self._load_htmltpl()
content = "<div style='width: 300px'>"
content += "<p style='font-size: 16px; width: 300px; margin-top: 0px'>"
content += "已经有job在运行中……<br></p></div>"
content += "<table style='width:100%'><tr><td>"
content += "<form method='post' action=/logreader>"
content += "<input type='submit' value='查看运行日志'></form></td>"
if self._hjob.hadoop_outdir:
content += "<td><form method='post' action=/resultreader>"
content += "<input type='submit' value='查看运行结果'></form>"
content += "</td>"
content += "</tr></table>"
cherrypy.response.headers['Content-Type']= 'text/html'
return htmltpl.replace("$$TOREPLACE$$", content)
def POST(self, picdirs=""):
cherrypy.response.headers['Content-Type']= 'text/html'
htmltpl = self._load_htmltpl()
content = "<div style='width: 300px'>"
content += "<table style='width:100%'><tr><td>"
content += "<form method='post' action=/logreader>"
content += "<input type='submit' value='查看运行日志'></form>"
content += "</td></tr></table><br>"
if not self._hjob.running:
if os.path.exists("./hjob.log"):
os.remove("./hjob.log")
self._hjob.start(picdirs, "./hjob.log")
content += "<h2>启动成功</h2>"
content += "</div>"
return htmltpl.replace("$$TOREPLACE$$", content)
def PUT(self, another_string):
cherrypy.response.headers['Content-Type']= 'text/html'
return "put"
def DELETE(self):
cherrypy.response.headers['Content-Type']= 'text/html'
return "delete"
def _load_htmltpl(self):
if self._content:
return self._content
f = open("./html.tpl")
self._content = f.read()
f.close()
return self._content