Updated de translation (Andre Klapper).
[empathy-mirror.git] / release.py
blobec6b0f9b8e271c691f7335c8b90afd121808930a
1 #!/usr/bin/env python
3 import os
4 import re
5 import urllib
6 import csv
7 import datetime
8 from string import Template
9 from optparse import OptionParser
11 username = 'xclaesse'
12 upload_server = 'master.gnome.org'
13 template = '''\
14 $name $version is now available for download from:
15 $download
17 $md5sums
19 What is it?
20 ===========
21 $about
23 You can visit the project web site:
24 $website
26 What's New?
27 ===========
28 $news
30 $footer'''
32 class Bug:
33 number = ''
34 author = ''
36 class Project:
37 def __init__(self):
38 f = open('config.h', 'r')
39 s = f.read()
40 f.close()
42 key = {}
43 key['package'] = '#define PACKAGE_NAME "'
44 key['version'] = '#define PACKAGE_VERSION "'
45 key['bugreport'] = '#define PACKAGE_BUGREPORT "'
47 for line in s.splitlines(1):
48 if line.startswith(key['package']):
49 p1 = len(key['package'])
50 p2 = line.rfind('"')
51 self.package_name = line[p1:p2]
52 elif line.startswith(key['version']):
53 p1 = len(key['version'])
54 p2 = line.rfind('"')
55 self.package_version = line[p1:p2]
56 elif line.startswith(key['bugreport']):
57 p2 = line.rfind('"')
58 p1 = line.rfind('=') + 1
59 self.package_module = line[p1:p2]
61 first = self.package_version.find('.')
62 second = self.package_version.find('.', first + 1)
63 if first == -1 or second == -1 or first == second:
64 version_dir = self.package_version
65 else:
66 version_dir = self.package_version[:second]
67 self.package_dl_url = 'http://download.gnome.org/sources/%s/%s/' % (self.package_name.lower(),
68 version_dir)
69 def exec_cmd(self,cmd):
70 return os.popen(cmd).read()
72 def get_news(self):
73 f = open ('NEWS', 'r')
74 s = f.read()
75 f.close()
76 start = s.find ('NEW in '+ self.package_version)
77 if start != -1:
78 start = s.find ('\n', start) + 1
79 start = s.find ('\n', start) + 1
80 end = s.find ('NEW in', start) - 1
81 return s[start:end].strip()
83 def get_md5sums(self):
84 md5sums = ''
86 cmd = 'md5sum %s-%s.tar.gz' % (self.package_name.lower(), self.package_version)
87 md5sums += self.exec_cmd(cmd)
89 cmd = 'md5sum %s-%s.tar.bz2' % (self.package_name.lower(), self.package_version)
90 md5sums += self.exec_cmd(cmd).strip()
92 return md5sums
94 def get_bugzilla_info(self):
95 query = 'http://bugzilla.gnome.org/browse.cgi?product=%s' % (self.package_module)
96 f = urllib.urlopen(query)
97 s = f.read()
98 f.close()
100 s1 = '<p><i>'
101 i = s.find(s1)
102 start = i + len(s1)
103 s2 = '</i></p>'
104 end = s.find(s2, i + 1)
105 description = s[start:end]
107 s1 = "GNOME SVN"
108 i = s.find(s1)
109 s1 = "href"
110 i = s.find(s1, i)
111 start = i + 6
112 s2 = '">'
113 end = s.find(s2, start)
114 project_url = s[start:end]
116 return (description, project_url)
118 def get_release_notes(self):
119 name = self.package_name
120 version = self.package_version
121 download = self.package_dl_url
122 md5sums = self.get_md5sums()
123 (about, website) = self.get_bugzilla_info()
124 news = self.get_news()
125 footer = '%s\n%s team' % (datetime.date.today().strftime('%d %B %Y'),\
126 self.package_name)
128 t = Template(template)
129 return t.substitute(locals())
131 def get_last_tag(self):
132 tags_str = self.exec_cmd('git-tag')
133 tags = tags_str.splitlines()
135 return tags[len(tags)-1]
137 def parse_commit(self, ref, author, date, message):
138 p1 = message.rfind('(')
139 p2 = message.rfind (')')
140 if len(message) - p2 <= 2:
141 author = message[p1+1:p2]
142 message = message[:p1]
144 msg = message.lower()
145 if msg.find('translation') != -1 and\
146 msg.find('updated') != -1:
147 self.translations += ' - ' + message + ' (' + author + ').\n'
148 elif message.find('#') != -1:
149 p1 = message.find('#')
150 while p1 != -1:
151 bug = Bug()
152 p2 = message.find(' ', p1)
153 bug.number = message[p1+1:p2]
154 bug.author = author
155 self.bug_commits.append(bug)
156 p1 = message.find('#', p2)
157 else:
158 self.commits += ' - ' + message + ' (' + author + ').\n'
160 def query_bug_commits(self):
161 bugs = ''
162 for bug in self.bug_commits:
163 bugs += bug.number + ','
165 # Bugzilla query to use
166 query = 'http://bugzilla.gnome.org/buglist.cgi?ctype=csv' \
167 '&bug_status=RESOLVED,CLOSED,VERIFIED' \
168 '&resolution=FIXED' \
169 '&bug_id=' + bugs.replace(',', '%2c')
171 f = urllib.urlopen(query)
172 s = f.read()
173 f.close()
175 col_bug_id = -1
176 col_description = -1
178 reader = csv.reader(s.splitlines(1))
179 header = reader.next()
180 i = 0
182 for col in header:
183 if col == 'bug_id':
184 col_bug_id = i
185 if col == 'short_short_desc':
186 col_description = i
187 i = i + 1
189 for row in reader:
190 bug_number = row[col_bug_id]
191 description = row[col_description]
193 for bug in self.bug_commits:
194 if bug.number == bug_number:
195 self.bugs += ' - Fixed #%s, %s (%s)\n' % (bug.number, description, bug.author)
196 break
198 def get_commits(self):
199 self.commits = ''
200 self.translations = ''
201 self.bugs = ''
202 self.bug_commits = []
203 last_tag = self.get_last_tag()
204 ref = None
206 changes = self.exec_cmd ("git-log " + last_tag + "..")
207 for line in changes.splitlines(1):
208 if line.startswith('commit'):
209 if ref != None:
210 self.parse_commit (ref, author, date, message)
211 p1 = line.find(' ')
212 ref = line[p1:].strip()
213 author = ''
214 date = ''
215 message = ''
216 elif line.startswith('Author:'):
217 p1 = line.find(' ')
218 p2 = line.find('<')
219 author = line[p1:p2].strip()
220 elif line.startswith('Date:'):
221 p1 = line.find(' ')
222 date = line[p1:].strip()
223 elif line.startswith(' git-svn-id:'):
224 continue
225 elif line.startswith('Merge:'):
226 continue
227 else:
228 msg = line.strip()
229 if msg == '':
230 continue
231 if message != '':
232 message += '\n'
233 message += msg
235 self.query_bug_commits ()
237 def make_tag(self):
238 new_tag = self.package_name.upper() + '_' +\
239 self.package_version.replace('.', '_')
241 url1 = self.exec_cmd('git-config svn-remote.svn.url').strip()
242 url2 = url1[:url1.rfind('/')] + '/tags/' + new_tag
243 self.exec_cmd('svn copy %s %s -m "Tagged for release %s."' % (url1, url2, self.package_version))
245 self.exec_cmd('git-tag -m "Tagged for release %s." %s' % ( self.package_version, new_tag))
247 def generate_news(self):
248 self.get_commits()
249 news = 'NEW in '+ self.package_version + '\n==============\n'
250 news += self.commits + '\nBugs fixed:\n' + self.bugs + '\nTranslations:\n' + self.translations + '\n'
252 return news
254 def write_news(self):
255 news = self.generate_news()
257 f = open ('/tmp/NEWS', 'w')
258 s = f.write(news)
259 f.close()
261 self.exec_cmd('cat NEWS >> /tmp/NEWS')
262 self.exec_cmd('mv /tmp/NEWS .')
264 def upload_tarball(self):
265 tarball = '%s-%s.tar.gz' % (self.package_name.lower(), self.package_version)
267 cmd = 'scp %s %s@%s:' % (tarball, username, upload_server)
268 self.exec_cmd(cmd)
270 cmd = 'ssh %s@%s install-module -u %s' % (username, upload_server, tarball)
271 self.exec_cmd(cmd)
273 def send_email(self):
274 notes = self.get_release_notes()
275 cmd = 'xdg-email ' \
276 ' --cc telepathy@lists.freedesktop.org' \
277 ' --subject "ANNOUNCE: Empathy %s"' \
278 ' --body "%s"' \
279 ' gnome-announce-list@gnome.org' % (self.package_version,
280 notes.replace('"', '\\"'))
281 self.exec_cmd(cmd)
283 def release(self):
284 self.make_tag()
285 self.upload_tarball()
286 self.send_email()
288 if __name__ == '__main__':
289 p = Project()
290 parser = OptionParser()
291 parser.add_option("-n", "--print-news", action="store_true",\
292 dest="print_news", help="Generate and print news")
293 parser.add_option("-p", "--print-notes", action="store_true",\
294 dest="print_notes", help="Generate and print the release notes")
295 parser.add_option("-w", "--write-news", action="store_true",\
296 dest="write_news", help="Generate and write news into the NEWS file")
297 parser.add_option("-r", "--release", action="store_true",\
298 dest="release", help="Release the tarball")
299 parser.add_option("-e", "--email", action="store_true",\
300 dest="email", help="Send the release announce email")
302 (options, args) = parser.parse_args ()
303 if (options.print_news):
304 print p.generate_news ()
305 if (options.print_notes):
306 print p.get_release_notes ()
307 if (options.write_news):
308 p.write_news ()
309 if (options.release):
310 p.release ()
311 if (options.email):
312 p.send_email ()