-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertUtils.py
More file actions
124 lines (99 loc) · 3.96 KB
/
insertUtils.py
File metadata and controls
124 lines (99 loc) · 3.96 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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
from random import Random
import pymysql
import Common
def random_str(randomlength=8):
str = ''
chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
length = len(chars) - 1
random = Random()
for i in range(randomlength):
str += chars[random.randint(0,length)]
return str
# insert data to table
def insert(id,user_county,phone_type,sdk_version,android_id,bug_type,bug_detail,bug_count,bug_status,remark,bug_time,app_name,time):
# get db obj
db = pymysql.connect("localhost","root","root","bugDB")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print("To prepare insert")
sql = "INSERT INTO bugInfo VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"%(id,user_county,phone_type,sdk_version,android_id,bug_type,bug_detail,bug_count,bug_status,remark,bug_time,app_name,time)
try:
cursor.execute(sql)
db.commit()
print('insert successed')
except Exception as e:
db.rollback()
print('insert failed',e)
print(bug_detail)
db.close()
# insert data to table
def insertAll(id,user_county,phone_type,sdk_version,android_id,bug_type,bug_detail,bug_count,bug_status,remark,bug_time,app_name,time):
# get db obj
db = pymysql.connect("localhost","root","root","bugDB")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print("To prepare insert")
sql = "INSERT INTO allBug VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"%(id,user_county,phone_type,sdk_version,android_id,bug_type,bug_detail,bug_count,bug_status,remark,bug_time,app_name,time)
try:
cursor.execute(sql)
db.commit()
print('insert successed')
except Exception as e:
db.rollback()
print('insert failed',e)
print(bug_detail)
db.close()
def parse_file(path,package,type,time):
try:
files = os.listdir(path)
count = 0
print(type)
for file in files:
strName = file+""
res = strName.split('_')
countryId = res[0]
phoneType = res[1]
sdkVersion = res[2]
deviceId = res[3]
bugTime = res[4].split('.')[0]
count += 1
bug_type = " "
print("deal ....countryId = %s sdkVersion = %s phoneType = %s"%(countryId,sdkVersion,phoneType))
if not os.path.isdir(file):
f = open(path+"/"+file)
iter_f = iter(f);
bug_detail = " \n"
for line in iter_f:
bug_detail = bug_detail + line
if type == "all":
bug_detail = bug_detail.replace("\'",'')
insertAll(random_str(),countryId,phoneType,sdkVersion,deviceId,bug_type,bug_detail,'','unfix','',bugTime,package,time)
else:
if 'yiba' in bug_detail:
bug_detail=bug_detail.replace("\'",'')
insert(random_str(),countryId,phoneType,sdkVersion,deviceId,bug_type,bug_detail,'','unfix','',bugTime,package,time)
print(count)
except Exception as e:
print("has an exception= %s"%e)
def read_config(type,insert_time):
try:
path = "appNames.txt"
iter_f = iter(open(path))
for line in iter_f:
print("name = %s"%line)
name = line.strip('\n')
path = "/root/bugManageSystem/%s"%Common.generateFileName(name,insert_time)
parse_file(path,name,type,insert_time)
print(line)
except Exception as e:
print("has an exception= %s"%e)
def mysql_insert(insertTime):
read_config("",insertTime)
def insert_to_db(insertTime,packageName):
path = "/root/bugManageSystem/%s"%Common.generateFileName(packageName,insertTime)
parse_file(path,packageName,"",insertTime)