forked from louisalflame/WebTraceCollector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_bank.py
145 lines (120 loc) · 4.59 KB
/
data_bank.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Module docstring
"""
from abc import ABCMeta, abstractmethod
from connecter import mysqlConnect
class DataBank():
__metaclass__ = ABCMeta
@abstractmethod
def get_types(self):
"""IMPORTANT: this is class method, override it with @classmethod!"""
pass
@abstractmethod
def get_data(self, data_type):
"""IMPORTANT: this is class method, override it with @classmethod!"""
pass
@abstractmethod
def add_item(self, data_type, value):
"""IMPORTANT: this is class method, override it with @classmethod!"""
pass
@abstractmethod
def remove_item(self, data_type, value):
"""IMPORTANT: this is class method, override it with @classmethod!"""
pass
#=============================================================================================================
# Get data set from mysqldb
#=============================================================================================================
class MysqlDataBank(DataBank):
@classmethod
def __init__(cls, host, user, password, db):
cls._connect = mysqlConnect(host, user, password, db)
@classmethod
def get_types(cls):
pass
@classmethod
def add_item(cls, data_type, value):
pass
@classmethod
def remove_item(cls, data_type, value):
pass
@classmethod
def get_websubmit(cls, web_submit_id):
url, deep, time, browser1, browser2 = cls._connect.get_submit_by_id(web_submit_id)
web_inputs = cls._connect.get_all_inputs_by_id(web_submit_id)
return url, deep, time, browser1, browser2
@classmethod
def get_data(cls, data_type, data_id):
if not ('data_'+data_type) in cls._connect.get_all_table_names():
return None
data_name = ''
columns = cls._connect.get_databank_by_column('data_'+data_type, 'name')
for column in columns:
if column and u''.join(data_id.lower().split()) == u''.join(column.lower().split()):
data_name = column
break
else :
for column in columns:
if column and u''.join(data_id.lower().split()) in u''.join(column.lower().split()):
data_name = column
break
else :
for column in columns:
if column and u''.join(column.lower().split()) in u''.join(data_id.lower().split()):
data_name = column
break
else :
return None
datas = cls._connect.get_databank_by_row('data_'+data_type, 'name', data_name )
return datas[1:]
@classmethod
def get_mutation_data_set(cls, data_type, data_id, modes):
columns = cls._connect.get_mutation_catalog()
table_name = ''
for row in columns:
if row[0] and row[1] and u''.join(data_id.lower().split()) == u''.join(row[0].lower().split()):
table_name = row[1]
break
else:
for row in columns:
if row[0] and row[1] and u''.join(data_id.lower().split()) in u''.join(row[0].lower().split()):
table_name = row[1]
break
else:
for row in columns:
if row[0] and row[1] and u''.join(row[0].lower().split()) in u''.join(data_id.lower().split()):
table_name = row[1]
break
else:
for row in columns:
if row[0] and row[1] and u''.join(data_type.lower().split()) == u''.join(row[0].lower().split()):
table_name = row[1]
break
else:
table_name = "mutation_text"
mutation_values = cls._connect.get_mutation_values(table_name, modes)
return mutation_values
class InlineDataBank(DataBank):
@classmethod
def __init__(cls, host, user, password, db):
pass
@classmethod
def get_types(cls):
pass
@classmethod
def add_item(cls, data_type, value):
pass
@classmethod
def remove_item(cls, data_type, value):
pass
@classmethod
def get_websubmit(cls, web_submit_id):
url, deep, time = cls._connect.get_submit_by_id(web_submit_id)
return url, deep, time
@classmethod
def get_data(cls, data_type, data_id):
return ['0']
@classmethod
def get_mutation_data_set(cls, data_type, data_id, modes):
return [ '***' ]