2
# Usage: release.py VERSION. Creates a new compiz release and bumps VERSION
5
# Copyright (c) Sam Spilsbury <smspillaz@gmail.com>
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.
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.
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
23
import bzrlib.workingtree
24
import bzrlib.errors as errors
25
from launchpadlib.launchpad import Launchpad
29
print ("release.py VERSION")
30
print ("Make a release and bump version to VERSION")
33
if len(sys.argv) != 2:
36
if not "release.py" in os.listdir ("."):
37
print ("Working directory must contain this script")
43
editor = os.environ["EDITOR"]
45
print ("EDITOR must be set")
49
print ("EDITOR must be set")
53
compiz_branch = bzrlib.branch.Branch.open ("..")
54
compiz_branch.lock_read ()
55
tags = compiz_branch.tags.get_tag_dict ().items ()
57
most_recent_revision = 0
59
# Find the last tagged revision
60
for tag, revid in tags:
62
revision = compiz_branch.revision_id_to_dotted_revno (revid)[0]
64
if int (revision) > most_recent_revision:
65
most_recent_revision = revision
66
except (errors.NoSuchRevision,
67
errors.GhostRevisionsHaveNoRevno,
68
errors.UnsupportedOperation):
71
repo = compiz_branch.repository
72
release_revisions = []
74
# Find all revisions since that one
75
for revision_id in repo.get_revisions (repo.all_revision_ids ()):
77
revno = compiz_branch.revision_id_to_dotted_revno (revision_id.revision_id)[0]
79
if revno > most_recent_revision:
80
release_revisions.append (revision_id)
82
except (errors.NoSuchRevision,
83
errors.GhostRevisionsHaveNoRevno,
84
errors.UnsupportedOperation):
87
# Find all fixed bugs in those revisions
90
for rev in release_revisions:
91
for bug in rev.iter_bugs():
92
bugs.append (bug[0][27:])
96
# Connect to launchpad
97
lp = Launchpad.login_anonymously ("Compiz Release Script", "production")
99
# Create a pretty looking formatted list of bugs
104
bugTitle = lpBug.title
106
bugTitleWords = bugTitle.split (" ")
107
maximumLineLength = 65
108
currentLineLength = 0
112
for word in bugTitleWords:
113
wordLength = len (word) + 1
114
if wordLength + currentLineLength > maximumLineLength:
115
lineParts.append ("")
117
currentLineLength = 0
118
elif currentLineLength != 0:
119
lineParts[line] += " "
121
currentLineLength += wordLength
122
lineParts[line] += (word)
124
bugs_formatted.append ((bug, lineParts))
126
# Pretty-print the bugs
127
bugs_formatted_msg = ""
129
for bug, lines in bugs_formatted:
130
whitespace = " " * (12 - len (bug))
131
bugs_formatted_msg += whitespace + bug + " - " + lines[0] + "\n"
134
for i in range (1, len (lines)):
135
whitespace = " " * 15
136
bugs_formatted_msg += whitespace + lines[i] + "\n"
139
version_file = open ("../VERSION", "r")
140
version = version_file.readlines ()[0][:-1]
141
version_file.close ()
144
date = datetime.datetime.now ()
145
date_formatted = str(date.year) + "-" + str(date.month) + "-" + str(date.day)
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
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 ()
161
os.system (editor + " .release-script-" + version)
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 ()
169
for i in range (0, len (news_prepend_lines)):
170
news_prepend_lines[i] = news_prepend_lines[i].decode ("utf8")
172
news_prepend_lines.append ("\n")
174
for line in news_lines:
175
news_prepend_lines.append (line.decode ("utf8"))
179
for line in news_prepend_lines:
183
news_prepend_file.close ()
184
news_file = open ("../NEWS", "w")
185
news_file.write (news.encode ("utf8"))
189
compiz_tree = bzrlib.workingtree.WorkingTree.open ("..")
190
compiz_tree.commit ("Release version " + version)
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 ()
199
version_file = open ("../VERSION", "w")
200
version_file.write (sys.argv[1] + "\n")
201
version_file.close ()
204
compiz_tree = bzrlib.workingtree.WorkingTree.open ("..")
205
compiz_tree.commit ("Bump VERSION to " + sys.argv[1])