-
Notifications
You must be signed in to change notification settings - Fork 0
/
asf_parse.py
executable file
·143 lines (105 loc) · 3.75 KB
/
asf_parse.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
#!usr/bin/env python
from lxml import etree
import subprocess, re
import asf_db_client
def parse_svn_log(log, project_name):
split_log = log.split('------------------------------------------------------------------------\nr')
split_log = [l for l in split_log if not l.isspace() and l]
for l in split_log:
parse_svn_commit(l, project_name)
return True
def parse_svn_commit(c, project_name):
commit = {}
commit['project'] = project_name
log = c.splitlines()
log = [l for l in log if not l.startswith('\'')]
log = [l for l in log if not l.isspace() and l]
rev_user_date = log[0]
res = rev_user_date.split('|')
# res should contain at least rev num, username, and commit date
if len(res) < 3:
return False
commit['commit_id'] = res[0].strip()
commit['username'] = res[1].strip()
date_tmp = res[2].strip()
date_tmp = date_tmp[:25]
# for now, only record commits with dates in ISO 8601 with utc offset
if (len(date_tmp) != 25):
return False
commit['date'] = date_tmp
files = []
i = 2
if log[1] and 'Changed paths' in log[1]:
while i < len(log) and re.search("\s\s\s[A-Z]\s.*", log[i]):
m_file = log[i].strip()
file = {}
file['commit_id'] = commit['commit_id']
file['action'] = m_file[:1].strip()
file['name'] = m_file[2:].strip()
files.append(file)
i = i + 1
comment = ""
for j in range(i, len(log)):
comment = comment + log[j]
commit['comment'] = comment
valid_commit = asf_db_client.insert_commit(commit)
if not valid_commit:
return False
for f in files:
asf_db_client.insert_modified_file(f)
return True
def parse_git_log(log, project_name):
split_log = log.split('\'?||?')
split_log = [l for l in split_log if not l.isspace() and l]
for l in split_log:
parse_git_commit(l, project_name)
return True
def parse_git_commit(c, project_name):
commit = {}
commit['project'] = project_name
log = c.splitlines()
log = [l for l in log if not l.startswith('\'')]
log = [l for l in log if l]
hash_user_date = log[0]
res = hash_user_date.split('|')
commit['commit_id'] = res[0]
commit['username'] = res[1]
commit['date'] = res[2]
comment = log[1]
comment = comment[1:]
if comment:
commit['comment'] = comment
valid_commit = False
if "No Author" not in commit['username']:
valid_commit = asf_db_client.insert_commit(commit)
if not valid_commit:
return False
if len(log) > 2 and len(log) < 40:
for x in range (2, len(log)):
file = {}
file['commit_id'] = res[0]
file['action'] = log[x][:1]
file['name'] = log[x][2:]
asf_db_client.insert_modified_file(file)
return True
def parse_doap(doap):
tree = etree.parse('doap_files/' + doap)
root = tree.getroot()
project = {}
for child in root:
if child.tag == 'programming-languages' or child.tag == 'categories':
value = []
for grandchild in child:
value.append(grandchild.text)
else:
value = child.text
project[child.tag] = value
if 'svn' in project['repository'] or 'subversion' in project['repository']:
project['version_control'] = 'svn'
elif 'git' in project['repository']:
project['version_control'] = 'git'
else:
project['version_control'] = 'n/a'
print("Inserting {0} into database.".format(project['name']))
asf_db_client.insert_project(project)
return True