import urllib
import csv
import datetime
+import time
from string import Template
+from optparse import OptionParser
-prev_tag = 'EMPATHY_0_21_4'
-username = 'xclaesse'
+last_tag_patern = 'EMPATHY_2_27*'
upload_server = 'master.gnome.org'
template = '''\
$name $version is now available for download from:
$footer'''
-class Commit:
- ref = ''
+class Bug:
+ number = ''
author = ''
- date = ''
- message = ''
- bug = ''
- summary = ''
- translation = False
-
- def parse(self):
- if self.message[len(self.message) - 1] == ')':
- p1 = self.message.rfind('(')
- self.author = self.message[p1+1:len(self.message) - 1]
- self.message = self.message[:p1]
-
- p1 = self.message.find('#')
- p2 = self.message.find(' ', p1)
- if p1 != -1:
- self.bug = self.message[p1+1:p2]
-
- message = self.message.lower()
- if message.find('translation') != -1 and\
- message.find('updated') != -1:
- self.translation = True
- exp = '.*pdated(?P<name>.*).ranslation.*'
- lang_re = re.compile(exp, re.S | re.M)
- match = lang_re.match(self.message)
- if match:
- lang = match.group('name').strip()
- self.summary = "Updated " + lang + " Translation"
- else:
- self.summary = self.message
- self.summary += ' (' + self.author + ').'
-
- return self.bug
class Project:
def __init__(self):
version_dir = self.package_version[:second]
self.package_dl_url = 'http://download.gnome.org/sources/%s/%s/' % (self.package_name.lower(),
version_dir)
+ tags_str = self.exec_cmd('git tag -l %s' % (last_tag_patern))
+ tags = tags_str.splitlines()
+ self.last_tag = tags[len(tags)-1]
+
def exec_cmd(self,cmd):
return os.popen(cmd).read()
end = s.find(s2, i + 1)
description = s[start:end]
- s1 = "GNOME SVN"
+ s1 = "homepage"
i = s.find(s1)
s1 = "href"
- i = s.find(s1, i)
+ i = s.rfind(s1, 0, i)
start = i + 6
s2 = '">'
end = s.find(s2, start)
t = Template(template)
return t.substitute(locals())
- def get_commits(self):
- bugs = ''
- co = None
- commits = []
-
- changes = self.exec_cmd ("git-log " + prev_tag + "..")
- for line in changes.splitlines(1):
- if line.startswith('commit'):
- if co != None:
- bug = co.parse()
- if bug:
- if bugs != '':
- bugs += ','
- bugs += bug
-
- co = Commit()
- commits.append(co)
- p1 = line.find(' ')
- co.ref = line[p1:].strip()
- elif line.startswith('Author:'):
- p1 = line.find(' ')
- p2 = line.find('<')
- co.author = line[p1:p2].strip()
- elif line.startswith('Date:'):
- p1 = line.find(' ')
- co.date = line[p1:].strip()
- elif line.startswith(' git-svn-id:'):
- continue
- elif line.startswith('Merge:'):
- continue
- else:
- msg = line.strip()
- if msg == '':
- continue
- if msg.startswith('*'):
- p1 = msg.find(':')
- msg = msg[p1 + 1:].strip()
- elif msg.startswith('2007-') or msg.startswith('2008-'):
- continue
- if co.message != '':
- co.message += '\n'
- co.message += msg
-
- # Bugzilla query to use
- query = 'http://bugzilla.gnome.org/buglist.cgi?ctype=csv' \
- '&bug_status=RESOLVED,CLOSED,VERIFIED' \
- '&resolution=FIXED' \
- '&bug_id=' + bugs.replace(',', '%2c')
-
+ def get_translations(self, cmd, format):
+ translations = ''
+ files_str = self.exec_cmd(cmd)
+ files = files_str.splitlines()
+ for line in files:
+ f = line[line.rfind(' '):]
+ lang = f[f.rfind('/')+1:f.rfind('.')]
+ commit_str = self.exec_cmd("git log %s.. %s" % (self.last_tag, f))
+ if commit_str == '':
+ continue
+
+ authors = ''
+ for line in commit_str.splitlines():
+ if line.startswith('Author:'):
+ p1 = line.find(' ')
+ p2 = line.find('<')
+ author = line[p1:p2].strip()
+
+ if authors.find(author) != -1:
+ continue
+ if authors != '':
+ authors += ", "
+ authors += author
+
+ translations += format % (lang, authors)
+ return translations
+
+ def get_bug_author(self, bug_number):
+ cmd = 'git log %s.. | grep -B 20 -E "(bug %s|#%s)"' \
+ ' | tac | grep ^Author: | head -1' \
+ % (self.last_tag, bug_number, bug_number)
+ line = self.exec_cmd (cmd)
+ p1 = line.find(" ")
+ p2 = line.find("<")
+
+ return line[p1:p2].strip()
+
+ def get_bugs(self):
+ commit_str = self.exec_cmd('git show %s' % (self.last_tag))
+ for line in commit_str.splitlines():
+ if line.startswith('Date:'):
+ time_str = line[5:line.rfind('+')].strip()
+ t = time.strptime(time_str)
+ last_tag_date = time.strftime('%Y-%m-%d', t)
+ break
+
+ query = 'http://bugzilla.gnome.org/buglist.cgi?' \
+ 'ctype=csv&product=empathy&' \
+ 'bug_status=RESOLVED,CLOSED,VERIFIED&resolution=FIXED&' \
+ 'chfieldfrom=%s&chfieldto=Now' % (last_tag_date)
f = urllib.urlopen(query)
s = f.read()
f.close()
col_description = i
i = i + 1
+ bugs = ''
for row in reader:
bug_number = row[col_bug_id]
description = row[col_description]
-
- for co in commits:
- if co.bug == bug_number:
- co.summary = 'Fixed #%s, %s (%s)' % (co.bug, description, co.author)
- break
- return commits
-
- def make_tag(self):
- new_tag = self.package_name.upper() + '_' +\
- self.package_version.replace('.', '_')
-
- url1 = self.exec_cmd('git-config svn-remote.svn.url').strip()
- url2 = url1[:url1.rfind('/')] + '/tags/' + new_tag
- self.exec_cmd('svn copy %s %s -m "Tagged for release %s."' % (url1, url2, self.package_version))
-
- self.exec_cmd('git-tag -m "Tagged for release %s." %s' % ( self.package_version, new_tag))
+ author = self.get_bug_author(bug_number)
+ bugs += ' - Fixed #%s, %s' % (bug_number, description)
+ if author != '':
+ bugs += ' (%s)' % (author)
+ bugs += '\n'
+ return bugs
+
+ def generate_news(self):
+ translations = self.get_translations("ls -l po/*.po", \
+ " - Updated %s Translation (%s)\n")
+ help_translations = self.get_translations("ls -l help/*/*.po", \
+ " - Updated %s Documentation translation (%s)\n")
+ bugs = self.get_bugs()
+
+ news = 'NEW in '+ self.package_version + '\n==============\n'
+ if bugs != '':
+ news += 'Bugs fixed:\n' + bugs + '\n'
+ if translations != '':
+ news += 'Translations:\n' + translations + '\n'
+ if help_translations != '':
+ news += 'Documentation translations:\n' + \
+ help_translations + '\n'
+
+ return news
def write_news(self):
- bugs = ''
- translations = ''
- others = ''
- commits = self.get_commits()
- for co in commits:
- if co.summary == '':
- others += '- ' + co.message + '\n'
- elif co.translation == False:
- bugs += '- ' + co.summary + '\n'
- else :
- translations += '- ' + co.summary + '\n'
-
- news = 'NEW in '+ self.package_version + '\n==============\n'
- news += others + '\nBugs fixed:\n' + bugs + '\nTranslations:\n' + translations + '\n'
+ news = self.generate_news()
f = open ('/tmp/NEWS', 'w')
s = f.write(news)
self.exec_cmd('cat NEWS >> /tmp/NEWS')
self.exec_cmd('mv /tmp/NEWS .')
+ def make_tag(self):
+ new_tag = self.package_name.upper() + '_' +\
+ self.package_version.replace('.', '_')
+ self.exec_cmd('git tag -m "Tagged for release %s." %s' % ( self.package_version, new_tag))
+
+ def _get_username(self):
+ username = os.environ.get('GNOME_ACCOUNT_NAME')
+ if username is not None:
+ return username
+
+ return os.getlogin()
+
+
def upload_tarball(self):
+ username = self._get_username()
tarball = '%s-%s.tar.gz' % (self.package_name.lower(), self.package_version)
-
+
cmd = 'scp %s %s@%s:' % (tarball, username, upload_server)
self.exec_cmd(cmd)
-
- cmd = 'ssh %s@%s install-module %s' % (username, upload_server, tarball)
+
+ cmd = 'ssh %s@%s install-module -u %s' % (username, upload_server, tarball)
+ self.exec_cmd(cmd)
+
+ def send_email(self):
+ notes = self.get_release_notes()
+ cmd = 'xdg-email ' \
+ ' --cc telepathy@lists.freedesktop.org' \
+ ' --subject "ANNOUNCE: Empathy %s"' \
+ ' --body "%s"' \
+ ' gnome-announce-list@gnome.org' % (self.package_version,
+ notes.replace('"', '\\"'))
self.exec_cmd(cmd)
-project = Project()
-project.write_news()
+ def release(self):
+ self.make_tag()
+ self.upload_tarball()
+ self.send_email()
+
+if __name__ == '__main__':
+ p = Project()
+ parser = OptionParser()
+ parser.add_option("-n", "--print-news", action="store_true",\
+ dest="print_news", help="Generate and print news")
+ parser.add_option("-p", "--print-notes", action="store_true",\
+ dest="print_notes", help="Generate and print the release notes")
+ parser.add_option("-w", "--write-news", action="store_true",\
+ dest="write_news", help="Generate and write news into the NEWS file")
+ parser.add_option("-r", "--release", action="store_true",\
+ dest="release", help="Release the tarball")
+ parser.add_option("-e", "--email", action="store_true",\
+ dest="email", help="Send the release announce email")
+
+ (options, args) = parser.parse_args ()
+ if (options.print_news):
+ print p.generate_news ()
+ if (options.print_notes):
+ print p.get_release_notes ()
+ if (options.write_news):
+ p.write_news ()
+ if (options.release):
+ p.release ()
+ if (options.email):
+ p.send_email ()
+