~bryanfritt/compiz/compiz-ezoom_More-Specific-Zooms_1201061

« back to all changes in this revision

Viewing changes to scripts/release.py

Add a simple script for making releases.

Approved by MC Return, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/env/python
 
2
# Usage: release.py VERSION. Creates a new compiz release and bumps VERSION
 
3
# to the next release
 
4
#
 
5
# Copyright (c) Sam Spilsbury <smspillaz@gmail.com>
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 2 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
20
import sys
 
21
import os
 
22
import bzrlib.branch
 
23
import bzrlib.workingtree
 
24
import bzrlib.errors as errors
 
25
from launchpadlib.launchpad import Launchpad
 
26
import datetime
 
27
 
 
28
def usage ():
 
29
    print ("release.py VERSION")
 
30
    print ("Make a release and bump version to VERSION")
 
31
    sys.exit (1)
 
32
 
 
33
if len(sys.argv) != 2:
 
34
    usage ()
 
35
 
 
36
if not "release.py" in os.listdir ("."):
 
37
    print ("Working directory must contain this script")
 
38
    sys.exit (1)
 
39
 
 
40
editor = ""
 
41
 
 
42
try:
 
43
    editor = os.environ["EDITOR"]
 
44
except KeyError:
 
45
    print ("EDITOR must be set")
 
46
    sys.exit (1)
 
47
 
 
48
if len (editor) == 0:
 
49
    print ("EDITOR must be set")
 
50
    sys.exit (1)
 
51
 
 
52
bzrlib.initialize ()
 
53
compiz_branch = bzrlib.branch.Branch.open ("..")
 
54
compiz_branch.lock_read ()
 
55
tags = compiz_branch.tags.get_tag_dict ().items ()
 
56
 
 
57
most_recent_revision = 0
 
58
 
 
59
# Find the last tagged revision
 
60
for tag, revid in tags:
 
61
    try:
 
62
        revision = compiz_branch.revision_id_to_dotted_revno (revid)[0]
 
63
 
 
64
        if int (revision) > most_recent_revision:
 
65
            most_recent_revision = revision
 
66
    except (errors.NoSuchRevision,
 
67
            errors.GhostRevisionsHaveNoRevno,
 
68
            errors.UnsupportedOperation):
 
69
        pass
 
70
 
 
71
repo = compiz_branch.repository
 
72
release_revisions = []
 
73
 
 
74
# Find all revisions since that one
 
75
for revision_id in repo.get_revisions (repo.all_revision_ids ()):
 
76
    try:
 
77
        revno = compiz_branch.revision_id_to_dotted_revno (revision_id.revision_id)[0]
 
78
 
 
79
        if revno > most_recent_revision:
 
80
            release_revisions.append (revision_id)
 
81
 
 
82
    except (errors.NoSuchRevision,
 
83
            errors.GhostRevisionsHaveNoRevno,
 
84
            errors.UnsupportedOperation):
 
85
        pass
 
86
 
 
87
# Find all fixed bugs in those revisions
 
88
bugs = []
 
89
 
 
90
for rev in release_revisions:
 
91
    for bug in rev.iter_bugs():
 
92
        bugs.append (bug[0][27:])
 
93
 
 
94
bugs = sorted (bugs)
 
95
 
 
96
# Connect to launchpad
 
97
lp = Launchpad.login_anonymously ("Compiz Release Script", "production")
 
98
 
 
99
# Create a pretty looking formatted list of bugs
 
100
bugs_formatted = []
 
101
 
 
102
for bug in bugs:
 
103
    lpBug = lp.bugs[bug]
 
104
    bugTitle = lpBug.title
 
105
 
 
106
    bugTitleWords = bugTitle.split (" ")
 
107
    maximumLineLength = 65
 
108
    currentLineLength = 0
 
109
    line = 0
 
110
    lineParts = [""]
 
111
 
 
112
    for word in bugTitleWords:
 
113
        wordLength = len (word) + 1
 
114
        if wordLength + currentLineLength > maximumLineLength:
 
115
            lineParts.append ("")
 
116
            line = line + 1
 
117
            currentLineLength = 0
 
118
        elif currentLineLength != 0:
 
119
            lineParts[line] += " "
 
120
 
 
121
        currentLineLength += wordLength
 
122
        lineParts[line] += (word)
 
123
 
 
124
    bugs_formatted.append ((bug, lineParts))
 
125
 
 
126
# Pretty-print the bugs
 
127
bugs_formatted_msg = ""
 
128
 
 
129
for bug, lines in bugs_formatted:
 
130
    whitespace = " " * (12 - len (bug))
 
131
    bugs_formatted_msg += whitespace + bug + " - " + lines[0] + "\n"
 
132
 
 
133
    if len (lines) > 1:
 
134
        for i in range (1, len (lines)):
 
135
            whitespace = " " * 15
 
136
            bugs_formatted_msg += whitespace + lines[i] + "\n"
 
137
 
 
138
# Get the version
 
139
version_file = open ("../VERSION", "r")
 
140
version = version_file.readlines ()[0][:-1]
 
141
version_file.close ()
 
142
 
 
143
# Get the date
 
144
date = datetime.datetime.now ()
 
145
date_formatted = str(date.year) + "-" + str(date.month) + "-" + str(date.day)
 
146
 
 
147
# Create release message
 
148
release_msg = "Release " + version + " (" + date_formatted + " NAME <EMAIL>)\n"
 
149
release_msg += "=" * 77 + "\n\n"
 
150
release_msg += "Highlights\n\n"
 
151
release_msg += "Bugs Fixed (https://launchpad.net/compiz/+milestone/" + version + ")\n\n"
 
152
release_msg += bugs_formatted_msg
 
153
 
 
154
print release_msg
 
155
 
 
156
# Edit release message
 
157
news_update_file = open (".release-script-" + version, "w+")
 
158
news_update_file.write (release_msg.encode ("utf8"))
 
159
news_update_file.close ()
 
160
 
 
161
os.system (editor + " .release-script-" + version)
 
162
 
 
163
# Open NEWS
 
164
news_file = open ("../NEWS", "r")
 
165
news_lines = news_file.readlines ()
 
166
news_prepend_file = open (".release-script-" + version, "r")
 
167
news_prepend_lines = news_prepend_file.readlines ()
 
168
 
 
169
for i in range (0, len (news_prepend_lines)):
 
170
    news_prepend_lines[i] = news_prepend_lines[i].decode ("utf8")
 
171
 
 
172
news_prepend_lines.append ("\n")
 
173
 
 
174
for line in news_lines:
 
175
    news_prepend_lines.append (line.decode ("utf8"))
 
176
 
 
177
news = ""
 
178
 
 
179
for line in news_prepend_lines:
 
180
    news += line
 
181
 
 
182
news_file.close ()
 
183
news_prepend_file.close ()
 
184
news_file = open ("../NEWS", "w")
 
185
news_file.write (news.encode ("utf8"))
 
186
news_file.close ()
 
187
 
 
188
# Commit
 
189
compiz_tree = bzrlib.workingtree.WorkingTree.open ("..")
 
190
compiz_tree.commit ("Release version " + version)
 
191
 
 
192
# Create a tag
 
193
compiz_branch.unlock ()
 
194
compiz_branch.lock_write ()
 
195
compiz_branch.tags.set_tag ("v" + version, compiz_branch.last_revision ())
 
196
compiz_branch.unlock ()
 
197
 
 
198
# Update version
 
199
version_file = open ("../VERSION", "w")
 
200
version_file.write (sys.argv[1] + "\n")
 
201
version_file.close ()
 
202
 
 
203
# Commit
 
204
compiz_tree = bzrlib.workingtree.WorkingTree.open ("..")
 
205
compiz_tree.commit ("Bump VERSION to " + sys.argv[1])