summaryrefslogtreecommitdiff
path: root/bin/update-contributors
blob: 5229af3ce132fc44df53e5f25f0e91ed7d786402 (plain)
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
#!/usr/bin/env python2
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

"""
Extract contributors since the previous release from a ChangeLog
and write into a release.xml file
"""

# FIXME: automatically update the release.xml file

import sys
import os
import re
import codecs

def main():
    if len(sys.argv) < 3:
        sys.stderr.write("Please specify a ChangeLog and release.xml file")
        sys.exit(1)
    changelog = sys.argv[1]
    release = sys.argv[2]

    if not os.path.exists(changelog):
        sys.stderr.write("%s does not exist.\n" % changelog)
        sys.exit(1)

    names = []

    lines = codecs.open(changelog, "r", encoding='utf-8', errors='replace').readlines()
    relmatcher = re.compile('^=== release .* ===$')
    if relmatcher.match(lines[0]):
        del lines[0]

    datedmatcher = re.compile('^\d*-\d*-\d*\s(?:[0-9:]+ [+-]\d{4}\s)\s?(.*)\s*<.*>$')
    bymatcher = re.compile(' by: ([^<]+)\s*.*$')
    byaddyonlymatcher = re.compile(' by:[ ]*<([^>]*)')
    for line in lines:
        if relmatcher.match(line):
            break
        for matcher in [datedmatcher, bymatcher, byaddyonlymatcher]:
            match = matcher.search(line)
            if match:
                name = match.expand("\\1").rstrip()
                if name == "":
                  print("Warning: parsed null name from '%s'" % (line))
                if not name in names and name != "":
                    names.append(name)
    names.sort()

    # output
    doc = codecs.open(release, "r", encoding='utf-8').read()
    list = []
    for name in names:
        list.append("\t<person>%s</person>" % name)
    contr = "\n".join(list) + "\n"
    matcher = re.compile('(.*)<contributors>.*</contributors>\s*(.*)',
        re.DOTALL)
    match = matcher.search(doc)
    pre = match.expand('\\1') + "  <contributors>\n"
    post = "  </contributors>\n\n" + match.expand('\\2')

    target = release + ".bak"
    os.rename(release, target)
    handle = codecs.open(release, "w", encoding='utf-8')
    handle.write(pre + contr + post)
    handle.close()
main()