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
|
#!/usr/bin/python
from RepSys import Error, config
from RepSys.svn import SVN
import tempfile
import shutil
import time
import os
def svn2rpm(pkgdirurl, rev=None, size=None):
concat = config.get("log", "concat", "").split()
svn = SVN()
log = svn.log(os.path.join(pkgdirurl, "current"), start=rev)
if (size is not None):
log = log[:size]
rpmlog = []
lastauthor = None
for logentry in log:
entryheader = []
if lastauthor != logentry.author or \
not (logentry.author in concat or "*" in concat):
entryheader.append(time.strftime("* %a %b %d %Y ", logentry.date))
entryheader.append(config.get("users", logentry.author,
logentry.author))
entryheader.append("\n")
entryheader.append(time.strftime("+ %Y-%m-%d %H:%M:%S",
logentry.date))
entryheader.append(" (%d)" % logentry.revision)
if lastauthor:
rpmlog.append("")
lastauthor = logentry.author
entrylines = []
first = 1
for line in logentry.lines:
if line:
line = line.replace("%", "%%")
if first:
first = 0
if entryheader:
rpmlog.append("".join(entryheader))
line = line.lstrip()
if line[0] != "-":
nextline = "- " + line
else:
nextline = line
elif line[0] != " " and line[0] != "-":
nextline = " " + line
else:
nextline = line
if nextline not in entrylines:
rpmlog.append(nextline)
entrylines.append(nextline)
return "\n".join(rpmlog)+"\n"
def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None):
file = open(specfile)
lines = file.readlines()
file.close()
newlines = []
found = 0
# Strip old changelogs
for line in lines:
if line.startswith("%changelog"):
found = 1
elif not found:
newlines.append(line)
elif line.startswith("%"):
found = 0
newlines.append(line)
# Create new changelog
newlines.append("\n\n%changelog\n")
newlines.append(svn2rpm(pkgdirurl, rev, size))
# Merge old changelog, if available
oldurl = config.get("log", "oldurl")
if oldurl:
svn = SVN()
tmpdir = tempfile.mktemp()
try:
pkgname = os.path.basename(pkgdirurl)
pkgoldurl = os.path.join(oldurl, pkgname)
if svn.ls(pkgoldurl, noerror=1):
svn.checkout(pkgoldurl, tmpdir, rev=rev)
logfile = os.path.join(tmpdir, "log")
if os.path.isfile(logfile):
file = open(logfile)
newlines.append("\n")
newlines.append(file.read())
file.close()
finally:
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
# Write new specfile
file = open(specfile, "w")
file.writelines(newlines)
file.close()
# vim:et:ts=4:sw=4
|