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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2007-2010 Team XBMC
# http://www.xbmc.org
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XBMC; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
import re, os, sys
def usage ():
print " Changelog.py [option]"
print " -h : display this message"
print " -r <REV> : get log messages up until REV"
print " -d <DIR> : place Changelog.txt in DIR"
sys.exit()
header = "*************************************************************************************************************\n" \
"*************************************************************************************************************\n" \
" XBMC CHANGELOG\n" \
"*************************************************************************************************************\n" \
"*************************************************************************************************************" \
"\nDate Rev Message\n" \
"=============================================================================================================\n"
xmlre = re.compile("^<logentry.*?revision=\"([0-9]{4,})\".*?<date>([0-9]{4}-[0-9]{2}-[0-9]{2})T.*?<msg>(.*?)</msg>.*?</logentry>$", re.MULTILINE | re.DOTALL)
txtre = re.compile("([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{4,5}) {1,2}(.*)")
old = None
lastrev = 8638
rev = 1000000
dir = "."
nargs = len(sys.argv)
args = sys.argv
i = 1
while i < nargs:
if args[i] == "-r":
i += 1
try:
rev = int(sys.argv[i])
except:
rev=1000000
elif args[i] == "-d":
i+=1
dir = args[i].replace(' ', '\ ')
elif args[i] == "-h" or args[i] == "--help":
usage()
i+=1
# print dir
# print rev
try:
old = open("%s/Changelog.txt" % (dir))
except:
old = None
if old != None:
olddoc = old.read()
old.close()
oldmsgs = txtre.findall(olddoc)
del olddoc
if len(oldmsgs) > 0:
lastrev = int(oldmsgs[0][1])
try:
output = open("%s/Changelog.txt" % (dir),"w")
except:
print "Can't open %s/Changelog.txt for writing." % (dir)
sys.exit()
output.write(header)
if rev <= lastrev:
for msg in oldmsgs:
if int(msg[1]) <= rev:
s = "%-11.11s %-5.5s %s\n" % (msg[0], msg[1], msg[2])
output.write(s)
sys.exit()
svncmd = "svn log --xml -r %s:HEAD" % (lastrev)
newlog = os.popen(svncmd)
newlogdoc = newlog.read()
newlog.close()
newmsgs = xmlre.findall(newlogdoc)
newmsgs.reverse()
for msg in newmsgs:
s = "%-11.11s %-5.5s %s\n" % (msg[1], msg[0], msg[2].replace('\n',''))
output.write(s)
skip = 0
if old != None:
for msg in oldmsgs:
if skip == 1:
s = "%-11.11s %-5.5s %s\n" % (msg[0], msg[1], msg[2])
output.write(s)
else:
skip = 1
output.close()
|