9 from string
import Template
10 from optparse
import OptionParser
12 last_tag_patern
= 'EMPATHY_2_27*'
14 upload_server
= 'master.gnome.org'
16 $name $version is now available for download from:
25 You can visit the project web site:
40 f
= open('config.h', 'r')
45 key
['package'] = '#define PACKAGE_NAME "'
46 key
['version'] = '#define PACKAGE_VERSION "'
47 key
['bugreport'] = '#define PACKAGE_BUGREPORT "'
49 for line
in s
.splitlines(1):
50 if line
.startswith(key
['package']):
51 p1
= len(key
['package'])
53 self
.package_name
= line
[p1
:p2
]
54 elif line
.startswith(key
['version']):
55 p1
= len(key
['version'])
57 self
.package_version
= line
[p1
:p2
]
58 elif line
.startswith(key
['bugreport']):
60 p1
= line
.rfind('=') + 1
61 self
.package_module
= line
[p1
:p2
]
63 first
= self
.package_version
.find('.')
64 second
= self
.package_version
.find('.', first
+ 1)
65 if first
== -1 or second
== -1 or first
== second
:
66 version_dir
= self
.package_version
68 version_dir
= self
.package_version
[:second
]
69 self
.package_dl_url
= 'http://download.gnome.org/sources/%s/%s/' % (self
.package_name
.lower(),
71 tags_str
= self
.exec_cmd('git tag -l %s' % (last_tag_patern
))
72 tags
= tags_str
.splitlines()
73 self
.last_tag
= tags
[len(tags
)-1]
75 def exec_cmd(self
,cmd
):
76 return os
.popen(cmd
).read()
79 f
= open ('NEWS', 'r')
82 start
= s
.find ('NEW in '+ self
.package_version
)
84 start
= s
.find ('\n', start
) + 1
85 start
= s
.find ('\n', start
) + 1
86 end
= s
.find ('NEW in', start
) - 1
87 return s
[start
:end
].strip()
89 def get_md5sums(self
):
92 cmd
= 'md5sum %s-%s.tar.gz' % (self
.package_name
.lower(), self
.package_version
)
93 md5sums
+= self
.exec_cmd(cmd
)
95 cmd
= 'md5sum %s-%s.tar.bz2' % (self
.package_name
.lower(), self
.package_version
)
96 md5sums
+= self
.exec_cmd(cmd
).strip()
100 def get_bugzilla_info(self
):
101 query
= 'http://bugzilla.gnome.org/browse.cgi?product=%s' % (self
.package_module
)
102 f
= urllib
.urlopen(query
)
110 end
= s
.find(s2
, i
+ 1)
111 description
= s
[start
:end
]
119 end
= s
.find(s2
, start
)
120 project_url
= s
[start
:end
]
122 return (description
, project_url
)
124 def get_release_notes(self
):
125 name
= self
.package_name
126 version
= self
.package_version
127 download
= self
.package_dl_url
128 md5sums
= self
.get_md5sums()
129 (about
, website
) = self
.get_bugzilla_info()
130 news
= self
.get_news()
131 footer
= '%s\n%s team' % (datetime
.date
.today().strftime('%d %B %Y'),\
134 t
= Template(template
)
135 return t
.substitute(locals())
137 def get_translations(self
, cmd
, format
):
139 files_str
= self
.exec_cmd(cmd
)
140 files
= files_str
.splitlines()
142 f
= line
[line
.rfind(' '):]
143 lang
= f
[f
.rfind('/')+1:f
.rfind('.')]
144 commit_str
= self
.exec_cmd("git log %s.. %s" % (self
.last_tag
, f
))
149 for line
in commit_str
.splitlines():
150 if line
.startswith('Author:'):
153 author
= line
[p1
:p2
].strip()
155 if authors
.find(author
) != -1:
161 translations
+= format
% (lang
, authors
)
164 def get_bug_author(self
, bug_number
):
165 cmd
= 'git log %s.. | grep -B 20 -E "(bug %s|#%s)"' \
166 ' | tac | grep ^Author: | head -1' \
167 % (self
.last_tag
, bug_number
, bug_number
)
168 line
= self
.exec_cmd (cmd
)
172 return line
[p1
:p2
].strip()
175 commit_str
= self
.exec_cmd('git show %s' % (self
.last_tag
))
176 for line
in commit_str
.splitlines():
177 if line
.startswith('Date:'):
178 time_str
= line
[5:line
.rfind('+')].strip()
179 t
= time
.strptime(time_str
)
180 last_tag_date
= time
.strftime('%Y-%m-%d', t
)
183 query
= 'http://bugzilla.gnome.org/buglist.cgi?' \
184 'ctype=csv&product=empathy&' \
185 'bug_status=RESOLVED,CLOSED,VERIFIED&resolution=FIXED&' \
186 'chfieldfrom=%s&chfieldto=Now' % (last_tag_date
)
187 f
= urllib
.urlopen(query
)
194 reader
= csv
.reader(s
.splitlines(1))
195 header
= reader
.next()
201 if col
== 'short_short_desc':
207 bug_number
= row
[col_bug_id
]
208 description
= row
[col_description
]
209 author
= self
.get_bug_author(bug_number
)
210 bugs
+= ' - Fixed #%s, %s' % (bug_number
, description
)
212 bugs
+= ' (%s)' % (author
)
216 def generate_news(self
):
217 translations
= self
.get_translations("ls -l po/*.po", \
218 " - Updated %s Translation (%s)\n")
219 help_translations
= self
.get_translations("ls -l help/*/*.po", \
220 " - Updated %s Documentation translation (%s)\n")
221 bugs
= self
.get_bugs()
223 news
= 'NEW in '+ self
.package_version
+ '\n==============\n'
225 news
+= 'Bugs fixed:\n' + bugs
+ '\n'
226 if translations
!= '':
227 news
+= 'Translations:\n' + translations
+ '\n'
228 if help_translations
!= '':
229 news
+= 'Documentation translations:\n' + \
230 help_translations
+ '\n'
234 def write_news(self
):
235 news
= self
.generate_news()
237 f
= open ('/tmp/NEWS', 'w')
241 self
.exec_cmd('cat NEWS >> /tmp/NEWS')
242 self
.exec_cmd('mv /tmp/NEWS .')
245 new_tag
= self
.package_name
.upper() + '_' +\
246 self
.package_version
.replace('.', '_')
247 self
.exec_cmd('git tag -m "Tagged for release %s." %s' % ( self
.package_version
, new_tag
))
249 def upload_tarball(self
):
250 tarball
= '%s-%s.tar.gz' % (self
.package_name
.lower(), self
.package_version
)
252 cmd
= 'scp %s %s@%s:' % (tarball
, username
, upload_server
)
255 cmd
= 'ssh %s@%s install-module -u %s' % (username
, upload_server
, tarball
)
258 def send_email(self
):
259 notes
= self
.get_release_notes()
261 ' --cc telepathy@lists.freedesktop.org' \
262 ' --subject "ANNOUNCE: Empathy %s"' \
264 ' gnome-announce-list@gnome.org' % (self
.package_version
,
265 notes
.replace('"', '\\"'))
270 self
.upload_tarball()
273 if __name__
== '__main__':
275 parser
= OptionParser()
276 parser
.add_option("-n", "--print-news", action
="store_true",\
277 dest
="print_news", help="Generate and print news")
278 parser
.add_option("-p", "--print-notes", action
="store_true",\
279 dest
="print_notes", help="Generate and print the release notes")
280 parser
.add_option("-w", "--write-news", action
="store_true",\
281 dest
="write_news", help="Generate and write news into the NEWS file")
282 parser
.add_option("-r", "--release", action
="store_true",\
283 dest
="release", help="Release the tarball")
284 parser
.add_option("-e", "--email", action
="store_true",\
285 dest
="email", help="Send the release announce email")
287 (options
, args
) = parser
.parse_args ()
288 if (options
.print_news
):
289 print p
.generate_news ()
290 if (options
.print_notes
):
291 print p
.get_release_notes ()
292 if (options
.write_news
):
294 if (options
.release
):