~ubuntu-branches/debian/stretch/arriero/stretch

« back to all changes in this revision

Viewing changes to scripts/new_upstream_release.py

  • Committer: Package Import Robot
  • Author(s): Margarita Manterola
  • Date: 2014-03-15 18:30:59 UTC
  • Revision ID: package-import@ubuntu.com-20140315183059-nap87isjg53t0tcf
Tags: upstream-0.5.1
ImportĀ upstreamĀ versionĀ 0.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
from collections import defaultdict
 
4
import re
 
5
import subprocess
 
6
import sys
 
7
 
 
8
COMMIT='New upstream release.'
 
9
MSG='  * New upstream release.\n'
 
10
changelog_trail = re.compile(r'^ --')
 
11
changelog_multimaint = re.compile(r'^\s*\[\s*(\b[^]]*\b)\s*\]\s*$')
 
12
changelog_empty = re.compile(r'^\s*$')
 
13
entry = re.compile(r'  \* New upstream release\.')
 
14
TRAIL = ('', 0)
 
15
 
 
16
for path in subprocess.check_output(['arriero', 'list', '-f', 'path'] +
 
17
                                    sys.argv[1:]).split('\n'):
 
18
    if not path: continue
 
19
    print path
 
20
 
 
21
    output = subprocess.check_output(['git', 'log', 'HEAD~1..HEAD',
 
22
                                      '--oneline'], cwd=path)
 
23
    last = re.sub('^[^\s]+\s+', '', output.rstrip('\n'))
 
24
    if last != COMMIT:
 
25
        continue
 
26
 
 
27
    filename = '%s/debian/changelog' % (path,)
 
28
    f = open(filename)
 
29
    lines = f.readlines()
 
30
    skip = 0
 
31
 
 
32
    first_block = []
 
33
    maintainers = defaultdict(set)
 
34
    maintainer = TRAIL
 
35
    entries = []
 
36
 
 
37
    for i, line in enumerate(lines):
 
38
        first_block.append(line)
 
39
        # print line,
 
40
 
 
41
        m = changelog_multimaint.match(line)
 
42
        if m:
 
43
            maintainer = (m.group(1), i)
 
44
        elif changelog_empty.match(line):
 
45
            maintainer = TRAIL
 
46
        else:
 
47
            maintainers[maintainer].add(i)
 
48
 
 
49
        if entry.match(line):
 
50
            entries.append((i, maintainer))
 
51
 
 
52
        if changelog_trail.match(line):
 
53
            break
 
54
    skip = len(first_block)
 
55
 
 
56
    delete = set()
 
57
    # print maintainers
 
58
    for e in entries:
 
59
        delete.add(e[0])
 
60
        if e[1] == TRAIL:
 
61
            continue
 
62
        maintainers[e[1]].remove(e[0])
 
63
        if not maintainers[e[1]]:
 
64
            i = e[1][1]
 
65
            delete.add(i)
 
66
            if i > 2 and changelog_empty.match(first_block[i - 1]):
 
67
                delete.add(i - 1)
 
68
 
 
69
    f = open(filename,'w')
 
70
    # f = sys.stdout
 
71
 
 
72
    for i, line in enumerate(first_block):
 
73
        if i == 2:
 
74
            f.write(MSG)
 
75
            if changelog_multimaint.match(line) and i not in delete:
 
76
                f.write('\n')
 
77
        if i in delete:
 
78
            continue
 
79
        f.write(line)
 
80
    for line in lines[skip:]:
 
81
        f.write(line)
 
82
    f.close()
 
83
 
 
84
    subprocess.call(['git', 'commit', '-a', '--amend', '-m',
 
85
                     'New upstream release.'], cwd=path)
 
86