-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_log.py~
More file actions
executable file
·40 lines (34 loc) · 1.05 KB
/
insert_log.py~
File metadata and controls
executable file
·40 lines (34 loc) · 1.05 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
#!/usr/bin/python
#usage ./insert_log "file_name" "vcs"
import sys
from mongoDB import mongoDB
header=['vcs','repo','n_peo','n_cmt','b_time','e_time','log_loc','src_loc', 'span']
dict_vcs={'svn':'svn_info', 'git':'git_info', 'hg':'hg_info', 'bazaar':'baz_info'}
db = mongoDB('datashare')
def readData():
in_file = open(sys.argv[1])
ret = []
for line in in_file:
item = {}
line = line.strip('\n')
sp = line.split(';')
sp[2] = int(sp[2])
sp[3] = int(sp[3])
sp[4] = int(sp[4])
sp[5] = int(sp[5])
for i in range(0, len(sp)):
item[header[i]] = sp[i]
ret.append(item)
return ret
def insertDB(vcs, data):
if vcs not in dict_vcs.keys():
usage.__call__()
else:
collection = dict_vcs[vcs]
for i in range(0, len(data)):
db.insert(collection, data[i])
def usage():
print "usage:"
print sys.argv[2] + ' svn|git|hg|bazaar'
data = readData()
insertDB(sys.argv[2], data)