-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalysis.py
111 lines (75 loc) · 2.87 KB
/
analysis.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
import os,glob
import difflib
import argparse
import sys
import logging
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)
#Save info about queue data name and source name
class Queue():
def __init__(self,queue_name,src_name):
#logger.warning("[%s] [%s]" %(queue_name,src_name))
self.queue_name = queue_name
self.name = get_fname(queue_name) #use for show on page
self.data = self.get_data(queue_name,src_name)
self.child = []
def get_data(self,src_name,queue_name):
logger.info("[%s] [%s]" %(src_name,queue_name))
ret = ''
#src = src_name.split('src:')[1][:6]
src_data = fread(src_name)
queue_data = fread(queue_name)
d = difflib.Differ()
l = list(d.compare(src_data, queue_data))
for i in l:
if i.startswith(' '):
ret += i[2:]
if i.startswith('- '):
ret += mark_red(i[2:])
return ret
class Analysis():
def __init__(self,all_file,queue_name):
self.all_file = all_file
self.queue_name = queue_name
self.src_list = []
def get_source_name(self,queue_id):
logger.info("get parent of %s ", queue_id)
if len(queue_id) == 6:
queue_name = get_name_from_id(self.all_file,queue_id)
else:
queue_name = queue_id
return get_name_from_id(self.all_file,queue_name.split('src:')[1][:6])
def get_queue_tree(self):
#incase source name is id
if len(self.queue_name) == 6:
self.queue_name = get_name_from_id(self.all_file,self.queue_name)
logger.info('Got source file %s ' % self.queue_name)
ret = [ Queue(self.queue_name,self.get_source_name(self.queue_name))]
ret = []
queue_name = self.queue_name
while True:
if get_id_from_name(queue_name) == '000000':
#logger.info("Add last")
ret.append(Queue(get_name_from_id(self.all_file,'000000'),queue_name))
break
parent_id = queue_name.split('src:')[1][:6]
logger.info("PR id %s",parent_id)
parent_name = get_name_from_id(self.all_file,parent_id)
logger.info("Add %s",parent_name)
ret.append(Queue(queue_name,self.get_source_name(queue_name)))
queue_name = parent_name
return ret
def fread(fname):
with open(fname,'r') as f:
data = f.read()
return data
def get_fname(flink):
return flink.split('/')[-1] if flink else None
def mark_red(data):
return '<font color="red">' + data + '</font>'
def get_name_from_id(all_file,name):
for fname in all_file:
if 'id:' + name in fname:
return fname
def get_id_from_name(fname):
return fname.split('id:')[1][:6]