-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
executable file
·89 lines (82 loc) · 3.49 KB
/
file.py
File metadata and controls
executable file
·89 lines (82 loc) · 3.49 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
#!/usr/bin/env python3
#coding: utf-8
from util import Util
import re
import datetime
import dbaccess
class File():
def __init__(self):
self.file_id=""
self.file_name=""
self.file_path=""
self.file_creator=""
self.file_create_date=""
self.file_project_id=""
@staticmethod
def collect_file_list(branch,latest_commit_id):
file_list=[]
local_file_list=[]
exist_file_list=File.get_file_list(branch.branch_project_id)
if (branch.branch_last_commit_id and not branch.branch_last_commit_id.isspace()):
local_file_change_list = Util.getpipeoutput(['git log --numstat %s --pretty=format:"%%at|^%%aN|^%%H|^%%s|^MARK" %s' % (" -m", branch.branch_last_commit_id+".."+latest_commit_id)]).split('\n')
else:
local_file_change_list = Util.getpipeoutput(['git log --numstat %s --pretty=format:"%%at|^%%aN|^%%H|^%%s|^MARK" %s' % (" -m", Util.getlogrange('HEAD'))]).split('\n')
for item in local_file_change_list:
if len(item) == 0:
continue
if re.search("MARK", item) == None:
change = item.split()
if len(change) == 3:
is_have=0
for item in local_file_list:
if item==change[2]:
is_have=1
break
if is_have==0:
local_file_list.append(change[2])
for item in local_file_list:
count=0
is_have=0
for file in exist_file_list:
if item.strip()==file.file_path.strip():
is_have=1
break
if is_have==0:
file=File()
filepaths=item.split("/")
file.file_name=filepaths[len(filepaths)-1]
file.file_path=item
file.file_create_date=datetime.date.today().strftime("%Y-%m-%d")
file.file_project_id=branch.branch_project_id
file_list.append(file)
File.insert_new_file_list(file_list)
return local_file_change_list
@staticmethod
def get_file_list(project_id):
file_list=[]
dal=dbaccess.DBAccess()
str_filter="where git_file_project_id="+str(project_id)
sql="""select git_file_id, git_file_name, git_file_path, git_file_creator,git_file_create_date, git_file_project_id
from git_file str_filter;"""
sql=sql.replace("str_filter",str_filter)
data_list=dal.execute_read_sql(sql)
#print(sql)
for item in data_list:
fileobj=File()
fileobj.file_id=item[0]
fileobj.file_name=item[1]
fileobj.file_path=item[2]
fileobj.file_creator=item[3]
fileobj.file_create_date=item[4]
fileobj.file_project_id=item[5]
file_list.append(fileobj)
return file_list
@staticmethod
def insert_new_file_list(file_list):
dal=dbaccess.DBAccess()
sql=""
if len(file_list)>0:
for item in file_list:
str_parameters="'"+item.file_name+"','"+item.file_path+"','"+item.file_creator+"','"+item.file_create_date+"','"+str(item.file_project_id)+"'"
sql+="insert into git_file(git_file_name, git_file_path, git_file_creator,git_file_create_date, git_file_project_id) values (%s);\r\n" % (''.join(str_parameters))
dal.execute_write_sql(sql)