-
Notifications
You must be signed in to change notification settings - Fork 1
/
request_input.py
440 lines (405 loc) · 12.6 KB
/
request_input.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# -*- coding: utf-8 -*-
#
# Author: Jack Ding
# E-Mail: jack.w.ding@gmail.com
# Date: 09/14/2010
# Version: 0.1
#
import os
import xml.parsers.expat
import threading
import logging
import subprocess
import traceback
from xml.dom.minidom import parse, parseString, getDOMImplementation
import xml.parsers.expat
#import xml.dom.minidom
from util import *
env_path = os.getenv('PATH')
def check_str_type(ss):
if isinstance(ss, unicode):
print u"## unicode"
else:
#print u"## no unicode"
try:
unicode(ss, "ascii")
except UnicodeError:
#print u"## not ascii"
try:
unicode(ss, "utf-8")
except UnicodeError:
print u"## not utf-8"
else:
print u"## utf-8"
else:
# str was valid ASCII data
print u"## ASCII"
#pass
#
class BlogerData():
def __init__(self, filename):
self.filename = filename
self.level = 0
self.requests = {}
self.find_blog = False
self.find_host = False
self.find_uri = False
self.find_referer = False
self.index = 0;
def get_request_items(self, blogname):
self.index = 0;
self.blogname = blogname
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = self.start_element
p.EndElementHandler = self.end_element
p.CharacterDataHandler = self.char_data
p.returns_unicode = True
f = file(self.filename)
p.ParseFile(f)
f.close()
return self.requests
def start_element(self, name, attrs):
if name == 'blog':
self.find_blog = True
elif name == 'request':
self.index += 1
elif name == 'host':
self.find_host = True
elif name == 'uri':
self.find_uri = True
elif name == 'referer':
self.find_referer = True
self.level = self.level + 1
def end_element(self, name):
if name == 'blog':
self.find_blog = False
self.level = self.level - 1
def char_data(self, data):
data = data.strip(' ').strip('\n')
if self.find_host:
key = 'host_%d' % self.index
value = data.encode('utf-8')
self.requests[key] = value
self.find_host = False
if self.find_uri:
key = 'uri_%d' % self.index
value = data.encode('utf-8')
self.requests[key] = value
self.find_uri = False
if self.find_referer:
key = 'referer_%d' % self.index
value = data.encode('utf-8')
self.requests[key] = value
self.find_referer = False
def get_count(self):
return self.index
def print_data(self):
print u""
#
#
class UtilConfigData(object):
logger = logging.getLogger('PVLog')
platform = ""
compile_target = "" # "Emulator WINSCW UDEB", "Phone GCCE DEBUG", "Phone GCCE RELEASE"
sdk_path_dict = {}
project_build_files = []
# build_options[project_id][]
build_options = [["" for x in range(10)] for y in range(10)]
__inst = None # make it so-called private
__lock = threading.Lock() # used to synchronize code
def __init__():
"disable the __init__ method"
@staticmethod
def getInst():
UtilConfigData.__lock.acquire()
if not UtilConfigData.__inst:
UtilConfigData.__inst = object.__new__(UtilConfigData)
object.__init__(UtilConfigData.__inst)
UtilConfigData.__lock.release()
return UtilConfigData.__inst
@staticmethod
def __reset_data():
UtilConfigData.platform = ""
UtilConfigData.sdk_path = ""
UtilConfigData.symbian_project = []
@staticmethod
def load_data(file_name):
UtilConfigData.logger.debug("UtilConfigData:load_data()")
UtilConfigData.__reset_data()
try:
f = open(file_name, 'r')
str = f.read()
#print u"str=", str
f.close()
UtilConfigData.handle_input_xml(str)
except:
UtilConfigData.logger.error("UtilConfigData:load_data() failed!")
print u"Can not load data:", file_name
UtilConfigData.__reset_data()
@staticmethod
def save_data(file_name):
UtilConfigData.logger.debug("UtilConfigData:save_data()")
str = UtilConfigData.encode_xml_data()
f = open(file_name,'w')
t = str.encode('utf=8')
f.write(t)
f.close()
@staticmethod
def handle_input_xml(xml_data):
try:
#UtilConfigData.logger.debug("UtilConfigData:handle_input_xml=%s", xml_data.decode('utf-8').encode('gb2312'))
dom = parseString(xml_data)
blog_node = dom.getElementsByTagName('visit-blog')[0]
print blog_node
UtilConfigData.parse_visti_blog(blog_node)
except Exception, e:
exstr = traceback.format_exc()
print exstr
@staticmethod
def parse_visti_blog(blog_node):
node2ss = blog_node.getElementsByTagName('blog')
for node2s in node2ss:
print u"blog=", node2s.toxml()
blog_name = node2s.attributes['name'].value
print u"blog_name=", blog_name
#node_items = node2s.getElementsByTagName('request-items')[0]
@staticmethod
def parse_platform_data(client_node):
print u"client_node=", client_node.toxml()
node1s = client_node.getElementsByTagName('platform')[0]
#print u"node1s=", node1s
for node1 in node1s.childNodes:
if node1.nodeType == node1.TEXT_NODE:
UtilConfigData.platform = node1.data
UtilConfigData.logger.debug("platform=%s", UtilConfigData.platform)
return True
UtilConfigData.logger.debug("Error:parse_platform_data: can not find platform")
return False
@staticmethod
def parse_compile_target(client_node):
#print u"client_node=", client_node.toxml()
node1s = client_node.getElementsByTagName('build-config')[0]
#print u"node1s=", node1s
for node1 in node1s.childNodes:
if node1.nodeType == node1.TEXT_NODE:
UtilConfigData.compile_target = node1.data
UtilConfigData.logger.debug("compile_target=%s", UtilConfigData.compile_target)
return True
UtilConfigData.logger.debug("Error:parse_platform_data: can not find compile_target")
return False
@staticmethod
def parse_project_info(client_node):
node1s = client_node.getElementsByTagName('symbian-projects')[0]
node2ss = node1s.getElementsByTagName('project')
project_id = 0
for node2s in node2ss:
print u"node2s=", node2s.toxml()
node_bld = node2s.getElementsByTagName('build-file')[0]
for node_bld_t in node_bld.childNodes:
if node_bld_t.nodeType == node_bld_t.TEXT_NODE:
print u"bld file=", node_bld_t.data
UtilConfigData.project_build_files.append(node_bld_t.data)
node_options = node2s.getElementsByTagName('build-options')[0]
mode_cmds = node_options.getElementsByTagName('command')
for node_cmd in mode_cmds:
print u"node_cmd=", node_cmd.toxml()
cmd = node_cmd.childNodes[0]
if cmd.nodeType == cmd.TEXT_NODE:
print u"cmd=", cmd.data
UtilConfigData.build_options[project_id].append(cmd.data)
project_id += 1
@staticmethod
def encode_xml_data():
print u"encode_xml_data"
impl = getDOMImplementation()
newdoc = impl.createDocument(None, "mas", None)
top_element = newdoc.documentElement
snode = newdoc.createElement("env")
# SDK config
for sdk_str in UtilConfigData.sdk_path_dict.keys():
print u"sdk=%s,path=%s" % (sdk_str, UtilConfigData.sdk_path_dict[sdk_str])
sdk_node = newdoc.createElement("sdk")
sdk_ver_node = newdoc.createElement("sdk-ver")
text = newdoc.createTextNode(sdk_str)
sdk_ver_node.appendChild(text)
sdk_path_node = newdoc.createElement("sdk-path")
text = newdoc.createTextNode(UtilConfigData.sdk_path_dict[sdk_str])
sdk_path_node.appendChild(text)
sdk_node.appendChild(sdk_ver_node)
sdk_node.appendChild(sdk_path_node)
snode.appendChild(sdk_node)
top_element.appendChild(snode)
snode = newdoc.createElement("mobile-client")
# platform
p_node = newdoc.createElement("platform")
text = newdoc.createTextNode(UtilConfigData.platform)
print u"platform=", UtilConfigData.platform
p_node.appendChild(text)
snode.appendChild(p_node)
# build config: Emulator, Debug GCCE....
p_node = newdoc.createElement("build-config")
text = newdoc.createTextNode(UtilConfigData.compile_target)
print u"compile_target=", UtilConfigData.compile_target
p_node.appendChild(text)
snode.appendChild(p_node)
# SDK path
# p_node = newdoc.createElement("sdk-path")
# text = newdoc.createTextNode(UtilConfigData.sdk_path)
# print u"sdk=", UtilConfigData.sdk_path
# p_node.appendChild(text)
# snode.appendChild(p_node)
# Symbian Project
ps_node = newdoc.createElement("symbian-projects")
id = 0
for x in UtilConfigData.project_build_files:
print u"symbian-projects=", x
p_node = newdoc.createElement("project")
bld_node = newdoc.createElement("build-file")
text = newdoc.createTextNode(x)
bld_node.appendChild(text)
p_node.appendChild(bld_node)
o_node = newdoc.createElement("build-options")
tt = UtilConfigData.build_options[id]
for cmd in tt:
if cmd <> '':
c_node = newdoc.createElement("command")
cmd_text = newdoc.createTextNode(cmd)
c_node.appendChild(cmd_text)
o_node.appendChild(c_node)
p_node.appendChild(o_node)
ps_node.appendChild(p_node)
id += 1
snode.appendChild(ps_node)
top_element.appendChild(snode)
return top_element.toxml()
@staticmethod
def get_sdk_list():
print u"sdk list=", UtilConfigData.sdk_path_dict.keys()
return UtilConfigData.sdk_path_dict.keys()
@staticmethod
def set_platform(platform_str):
UtilConfigData.platform = platform_str
@staticmethod
def get_platform():
return UtilConfigData.platform
@staticmethod
def set_sdk_path(sdk, sdk_path):
UtilConfigData.logger.debug("set_sdk_path:%s=%s", sdk, sdk_path)
UtilConfigData.sdk_path_dict[sdk] = sdk_path
@staticmethod
def get_sdk_path(sdk):
if sdk in UtilConfigData.sdk_path_dict.keys():
return UtilConfigData.sdk_path_dict[sdk]
else:
return ""
@staticmethod
def set_project_info_list(bld_file_list):
UtilConfigData.logger.debug("set_project_info:%s", bld_file_list)
UtilConfigData.project_build_files = bld_file_list
@staticmethod
def get_project_build_files():
# project_build_files[]
return UtilConfigData.project_build_files
@staticmethod
def get_compile_target():
return UtilConfigData.compile_target
@staticmethod
def set_compile_target(config):
UtilConfigData.compile_target = config
@staticmethod
def get_build_option(project_id):
return UtilConfigData.build_options[project_id]
@staticmethod
def set_build_option(project_id, options):
print u"set_build_option=", options
UtilConfigData.build_options[project_id] = options
@staticmethod
def gen_script_file():
f = open('run.bat','w')
# SET EPOCROOT
sdk_path = UtilConfigData.sdk_path_dict[UtilConfigData.platform]
tt = sdk_path.split(':')
#print u"sdk_path=", sdk_path
epocroot = "%s\\" % (tt[1])
t_str = "SET EPOCROOT=%s\n" % epocroot
f.write(t_str)
#
t_str = "REM \n"
f.write(t_str)
drive = "C:"
count = 0
for project in UtilConfigData.project_build_files:
#
UtilConfigData.logger.info("gen_script_file:project=%s", project)
t_str = "REM project:%s\n" % project
f.write(t_str)
path = os.path.dirname(project)
print u"path=%s" % path
t_str = "cd %s\n" % path
f.write(t_str)
#
cmd_list = UtilConfigData.build_options[count]
print u"cmd_list=", cmd_list
t_str = ""
for x in cmd_list:
if x <> "":
tt = ''
if x.find('bldmake') >= 0:
# set EPOCROOT && C: && cd path && bldmake xxxx
#tt = "SET EPOCROOT=%s && %s && cd %s && %s\n" % (epocroot, drive, path, x)
tt = "%s && cd %s && %s\n" % (drive, path, x)
elif x.find('abld') >= 0:
# set EPOCROOT && C: && path/abld ...
#tt = "SET EPOCROOT=%s && %s && %s\\%s\n" % (epocroot, drive, path, x)
tt = "%s && %s\\%s\n" % (drive, path, x)
t_str += tt
t_str += "\n"
f.write(t_str)
f.close()
@staticmethod
def run_script_file():
f = open('run.bat', 'r')
cmds = f.readlines()
f.close()
#print cmds
for command in cmds:
print u"command=%s" % command
#check_str_type(command)
tt = command.encode('ascii')
#check_str_type(tt)
#print u"command=%s" % tt
#p = os.popen(tt)
#print p.readlines()
p = subprocess.Popen(tt, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env={"EPOCROOT" : "\\Symbian\\9.1\\S60_3rd_MR\\", "PATH" : env_path })
stdoutdata, stderrdata = p.communicate()
print stderrdata
print u"returncode=", p.returncode
if p.returncode != 0:
print u"command failed!"
print stderrdata
return
else:
print u"command success"
@staticmethod
def print_all():
print u"----- All Service Data ------"
# @staticmethod
# def print_caller_notify():
# print u"Caller Notify:"
# for x in UtilConfigData.notify_array:
# if x[0] <> "":
# print x
# @staticmethod
# def print_caller_notify_to_str():
# str = "Caller Notify Data:\n"
# for x in UtilConfigData.notify_array:
# if x[0] <> "":
# str = str + x[0] + u" " + x[1] + u" " + x[2] + u" " + x[3]
# return str
# @staticmethod
# def print_voice_mail():
# print u"Voice Mail:"
# for x in UtilConfigData.voice_mail:
# if x[0] <> "":
# print x