Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / common / gen-changelog.py
1 #!/usr/bin/env python
2
3 import sys
4 import subprocess
5 import re
6
7 # Makes a GNU-Style ChangeLog from a git repository
8 # Handles git-svn repositories also
9
10 # Arguments : same as for git log
11 release_refs={}
12
13 def process_commit(lines, files):
14     # DATE NAME
15     # BLANK LINE
16     # Subject
17     # BLANK LINE
18     # ...
19     # FILES
20     fileincommit = False
21     lines = [x.strip() for x in lines if x.strip() and not x.startswith('git-svn-id')]
22     files = [x.strip() for x in files if x.strip()]
23     for l in lines:
24         if l.startswith('* ') and ':' in l:
25             fileincommit = True
26             break
27
28     top_line = lines[0]
29     print top_line.strip()
30     print
31     if not fileincommit:
32         for f in files:
33             print '\t* %s:' % f
34     for l in lines[1:]:
35         print '\t ', l
36     print
37
38 def output_commits():
39     cmd = ['git', 'log', '--pretty=format:--START-COMMIT--%H%n%ai  %an <%ae>%n%n%s%n%b%n--END-COMMIT--',
40            '--date=short', '--name-only']
41
42     start_tag = find_start_tag()
43
44     if start_tag is None:
45         cmd.extend(sys.argv[1:])
46     else:
47         cmd.extend(["%s..HEAD" % (start_tag)])
48
49     p = subprocess.Popen(args=cmd, shell=False, stdout=subprocess.PIPE)
50     buf = []
51     files = []
52     filemode = False
53     for lin in p.stdout.readlines():
54         if lin.startswith("--START-COMMIT--"):
55             if buf != []:
56                 process_commit(buf, files)
57             hash = lin[16:].strip()
58             try:
59                 rel = release_refs[hash]
60                 print "=== release %d.%d.%d ===\n" % (int(rel[0]), int(rel[1]), int(rel[2]))
61             except:
62                 pass
63             buf = []
64             files = []
65             filemode = False
66         elif lin.startswith("--END-COMMIT--"):
67             filemode = True
68         elif filemode == True:
69             files.append(lin)
70         else:
71             buf.append(lin)
72     if buf != []:
73         process_commit(buf, files)
74
75 def get_rel_tags():
76     # Populate the release_refs dict with the tags for previous releases
77     reltagre = re.compile("^([a-z0-9]{40}) refs\/tags\/RELEASE-([0-9]+)[-_.]([0-9]+)[-_.]([0-9]+)")
78
79     cmd = ['git', 'show-ref', '--tags', '--dereference']
80     p = subprocess.Popen(args=cmd, shell=False, stdout=subprocess.PIPE)
81     for lin in p.stdout.readlines():
82        match = reltagre.search (lin)
83        if match:
84            (sha, maj, min, nano) = match.groups()
85            release_refs[sha] = (maj, min, nano)
86
87 def find_start_tag():
88     starttagre = re.compile("^([a-z0-9]{40}) refs\/tags\/CHANGELOG_START")
89     cmd = ['git', 'show-ref', '--tags']
90     p = subprocess.Popen(args=cmd, shell=False, stdout=subprocess.PIPE)
91     for lin in p.stdout.readlines():
92        match = starttagre.search (lin)
93        if match:
94            return match.group(1)
95     return None
96
97 if __name__ == "__main__":
98     get_rel_tags()
99     output_commits()