forked from plone/buildout.coredev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unifyChangelogs.py
100 lines (83 loc) · 3.69 KB
/
unifyChangelogs.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
#!/usr/bin/env python
# -*- coding: ascii -*-
import urllib
from distutils.version import StrictVersion
from docutils.core import publish_doctree
import sys
def pullVersions(versionsFile):
try:
from ordereddict import OrderedDict
packageVersions = OrderedDict()
except ImportError:
packageVersions = {}
for line in versionsFile:
line = line.strip().replace(" ","")
if line and not (line.startswith('#') or line.startswith('[')):
try:
package, version = line.split("=")
version = StrictVersion(version)
except ValueError:
pass
else:
packageVersions[package] = version
return packageVersions
def pullSources(sourcesFile):
sources = {}
for line in sourcesFile:
line = line.strip().replace(" ","")
for t in ['svn','git']:
line = line.replace("=%s" % t,";;")
if line and not (line.startswith('#') or line.startswith('[')):
try:
package, location = line.split(";;")
sources[package] = location
except ValueError:
print line
return sources
def main(argv):
priorVersionNumber = sys.argv[1]
currentVersionNumber = sys.argv[2]
priorVersionsFile = urllib.urlopen('http://dist.plone.org/release/%s/versions.cfg' % priorVersionNumber)
priorVersions = pullVersions(priorVersionsFile)
currentVersionsFile = urllib.urlopen('http://dist.plone.org/release/%s/versions.cfg' % currentVersionNumber)
currentVersions = pullVersions(currentVersionsFile)
sourcesFile = open("sources.cfg", "r")
sources = pullSources(sourcesFile)
outputStr = ""
for package, version in currentVersions.iteritems():
if package in priorVersions:
priorVersion = priorVersions[package]
if version > priorVersion:
packageChange = u"%s: %s %s %s" % (package, priorVersion, u"\u2192", version)
outputStr += u"\n" + packageChange + u"\n" + u"-"*len(packageChange) + "\n"
if package in sources:
source = sources[package]
for structure in ["/CHANGES.txt", "/docs/CHANGES.txt", "/docs/HISTORY.txt", "raw/master/CHANGES.txt"]:
response = urllib.urlopen("%s/%s" % (source, structure))
if response.code == 200:
break
logtext = response.read()
tree = publish_doctree(logtext)
def isValidVersionSection(x):
if x.tagname == "section":
try:
logVersion = StrictVersion(x['names'][0].split()[0])
except ValueError:
pass
else:
return logVersion > priorVersion and logVersion <= version
return False
foundSections = tree.traverse(condition=isValidVersionSection)
if foundSections:
outputStr += u"\n"
for s in foundSections:
s.children[-1]
childlist = s.children[-1]
bullet = "- "
for child in childlist.children:
text = child.astext()
text = text.replace("\n","\n" + " "*len(bullet))
outputStr += bullet + text + u"\n"
print outputStr
if __name__ == "__main__":
main(sys.argv[1:])