-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsvn2changelog
executable file
·149 lines (117 loc) · 3.53 KB
/
svn2changelog
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
146
147
148
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Simple parser to convert svn log to a ChangeLog file
#
# Copyright 2009, Onur Küçük <[email protected]>
#
import sys
import urllib2
import subprocess
# write where your accounts file is
accountsFile = "http://svn.pardus.org.tr/uludag/trunk/common/accounts"
def loadFile(_file):
try:
f = file(_file)
data = f.read()
f.close()
except IOError:
print " !!! Failed to open %s !!!" % _file
sys.exit(1)
return data.split("\n")
def getSvnLog(svnargs=""):
try:
a = subprocess.Popen("svn log %s" % svnargs, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if a.wait() > 0:
print "Error from Subversion !"
print a.communicate()[1]
sys.exit(1)
else:
return a.communicate()[0].split("\n")
except OSError, e:
print " !!! Error running svn command !!!"
print e
sys.exit(1)
def parseAccounts():
acc = {}
data = urllib2.urlopen(accountsFile).read().strip().split("\n")
data = filter(lambda x: not (x.startswith("#") or x == ""), data)
for i in data:
nick, realName, email = i.split(":")[0:3]
acc[nick] = [realName, email]
return acc
def parseHeader(_data):
changedate = None
changer = None
if " | " in _data:
changearray = _data.split(" | ")
changer = changearray[1]
changedate = changearray[2].split(" ")[0]
return changedate, changer
def parseSections(_data):
sections = {}
currentsection = ""
getsection = False
emptyline = False
for line in _data:
if line == "-" * 72:
# start of a new section found"
getsection = True
continue
elif getsection:
# header found"
date, owner = parseHeader(line)
if owner:
try:
svnname, svnmail = svnaccount[owner]
except KeyError:
svnname, svnmail = owner, "nomail"
currentsection = "%s %s <%s>" % (date, svnname, svnmail)
if not currentsection in sections:
sections[currentsection] = ""
getsection = False
else:
# EOF
break
else:
# starting raw data"
if line.strip() == "":
emptyline = True
else:
if emptyline:
sections[currentsection] += " * %s\n" % line.lstrip()
emptyline = False
else:
sections[currentsection] += " %s\n" % line.lstrip()
return sections
def printHistory(data):
timeline = data.keys()
timeline.sort(reverse=True)
for i in timeline:
print i
print data[i]
def usage():
prg = sys.argv[0]
print "Simple svn to ChangeLog parser"
print ""
print "%s [fromfile <svnlogfile>] [SVN OPTIONS]" % prg
print ""
if __name__ == "__main__":
logFile = ""
svnargs = ""
if "usage" in sys.argv or "help" in sys.argv:
usage()
sys.exit(0)
elif len(sys.argv) > 2 and sys.argv[1] == "fromfile":
logFile = sys.argv[2]
else:
if len(sys.argv) > 1:
for i in sys.argv[1:]:
svnargs += "%s " % i
if logFile:
allData = loadFile(logFile)
else:
allData = getSvnLog(svnargs)
svnaccount = parseAccounts()
history = parseSections(allData)
printHistory(history)