Merge branch 'tube-bus-name'
[empathy.git] / release.py
index a98cbb5e61becdddb38404fea0b252b101cd77c0..60977d502a7f4a11af6ac11ecc156c31eafcc06b 100755 (executable)
@@ -6,11 +6,11 @@ import urllib
 import csv
 import datetime
 from string import Template
+from optparse import OptionParser
 
-prev_tag = 'EMPATHY_0_21_4'
 username = 'xclaesse'
-
-template = '''
+upload_server = 'master.gnome.org'
+template = '''\
 $name $version is now available for download from:
 $download
 
@@ -20,8 +20,6 @@ What is it?
 ===========
 $about
 
-Where can I find out more?
-==========================
 You can visit the project web site:
 $website
 
@@ -29,147 +27,14 @@ What's New?
 ===========
 $news
 
-$footer
-'''
-
-def exec_cmd (cmd):
-       return os.popen(cmd).read()
+$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:
-       package_name = ''
-       package_version = ''
-       package_module = ''
-       package_dl_url = ''
-       description = ''
-       url = ''
-       md5sums = ''
-       news = ''
-       translations = ''
-       new_tag = ''
-       notes = ''
-       commits = []
-
        def __init__(self):
-               self.get_package_info()
-               self.get_new_tag()
-               self.get_bugzilla_info()
-               self.get_md5sums()
-               self.get_news()
-               self.get_commits()
-               self.get_notes()
-
-       def make_tag(self):
-               url1 = exec_cmd('git-config svn-remote.svn.url').strip()
-               url2 = url1[:url1.rfind('/')] + '/tags/' + self.new_tag
-
-               exec_cmd('svn copy %s %s -m "Tagged for release %s."' % (url1, url2, self.package_version))
-               exec_cmd('git-tag -m "Tagged for release %s." %s' % ( self.package_version, self.new_tag))
-
-       def make_news(self):
-               bugs = ''
-               translations = ''
-               others = ''
-               for co in self.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 + '\n' + bugs + '\nTranslations:\n' + translations + '\n'
-
-               f = open ('/tmp/NEWS', 'w')
-               s = f.write(news)
-               f.close()
-
-               exec_cmd('cat NEWS >> /tmp/NEWS')
-               exec_cmd('mv /tmp/NEWS .')
-
-       def upload_tarball(self):
-               # This is the tarball we are going to upload
-               tarball = '%s-%s.tar.gz' % (package_name.lower(), package_version)
-                
-               cmd = 'scp %s %s@%s:' % (tarball, username, upload_server)
-               exec_cmd(cmd)
-                
-               cmd = 'ssh %s@%s install-module %s' % (username, upload_server, tarball)
-               exec_cmd(cmd)
-
-       def get_new_tag(self):
-               self.new_tag = self.package_name.upper() + '_' +\
-                              self.package_version.replace('.', '_')
-
-       def get_notes(self):
-               name = self.package_name
-               version = self.package_version
-               download = self.package_dl_url
-               md5sums = self.md5sums
-               about = self.description
-               website = self.url
-               news = self.news
-               footer = '%s\n%s team' % (datetime.date.today().strftime('%d %B %Y'),\
-                                         self.package_name)
-
-               t = Template(template)
-               self.notes = text = t.substitute(locals())
-
-       def get_news(self):
-               f = open ('NEWS', 'r')
-               s = f.read()
-               f.close()
-               start = s.find ('NEW in '+ self.package_version)
-               if start != -1:
-                       start = s.find ('\n', start) + 1
-                       start = s.find ('\n', start) + 1
-                       end = s.find ('NEW in', start) - 1
-                       self.news = s[start:end]
-
-       def get_md5sums(self):
-               cmd = 'md5sum %s-%s.tar.gz' % (self.package_name.lower(), self.package_version)
-               self.md5sums += exec_cmd(cmd)
-
-               cmd = 'md5sum %s-%s.tar.bz2' % (self.package_name.lower(), self.package_version)
-               self.md5sums += exec_cmd(cmd)
-
-       def get_package_info(self):
                f = open('config.h', 'r')
                s = f.read()
                f.close()
@@ -201,6 +66,30 @@ class Project:
                        version_dir = self.package_version[:second]
                self.package_dl_url = 'http://download.gnome.org/sources/%s/%s/' % (self.package_name.lower(), 
                                                                                    version_dir)
+       def exec_cmd(self,cmd):
+               return os.popen(cmd).read()
+
+       def get_news(self):
+               f = open ('NEWS', 'r')
+               s = f.read()
+               f.close()
+               start = s.find ('NEW in '+ self.package_version)
+               if start != -1:
+                       start = s.find ('\n', start) + 1
+                       start = s.find ('\n', start) + 1
+                       end = s.find ('NEW in', start) - 1
+                       return s[start:end].strip()
+
+       def get_md5sums(self):
+               md5sums = ''
+
+               cmd = 'md5sum %s-%s.tar.gz' % (self.package_name.lower(), self.package_version)
+               md5sums += self.exec_cmd(cmd)
+
+               cmd = 'md5sum %s-%s.tar.bz2' % (self.package_name.lower(), self.package_version)
+               md5sums += self.exec_cmd(cmd).strip()
+
+               return md5sums
 
        def get_bugzilla_info(self):
                query = 'http://bugzilla.gnome.org/browse.cgi?product=%s' % (self.package_module)
@@ -213,7 +102,7 @@ class Project:
                start = i + len(s1)
                s2 = '</i></p>'
                end = s.find(s2, i + 1)
-               self.description = s[start:end]
+               description = s[start:end]
 
                s1 = "GNOME SVN"
                i = s.find(s1)
@@ -222,48 +111,61 @@ class Project:
                start = i + 6
                s2 = '">'
                end = s.find(s2, start)
-               self.url = s[start:end]
+               project_url = s[start:end]
+
+               return (description, project_url)
+
+       def get_release_notes(self):
+               name = self.package_name
+               version = self.package_version
+               download = self.package_dl_url
+               md5sums = self.get_md5sums()
+               (about, website) = self.get_bugzilla_info()
+               news = self.get_news()
+               footer = '%s\n%s team' % (datetime.date.today().strftime('%d %B %Y'),\
+                                         self.package_name)
+
+               t = Template(template)
+               return t.substitute(locals())
        
-       def get_commits(self):
+       def get_last_tag(self):
+               tags_str = self.exec_cmd('git tag')
+               tags = tags_str.splitlines()
+
+               return tags[len(tags)-1]
+
+       def parse_commit(self, ref, author, date, message):
+               p1 = message.rfind('(')
+               p2 = message.rfind (')')
+               if len(message) - p2 <= 2 and \
+                  message[p1+1:].find('#') == -1:
+                       author = message[p1+1:p2]
+                       message = message[:p1]
+
+               msg = message.lower()
+               if msg.find('translation') != -1 and \
+                  (msg.find('added') != -1 or \
+                   msg.find('updated') != -1):
+                       self.translations += ' - ' + message + ' (' + author + ').\n' 
+               elif message.find('#') != -1:
+                       p1 = message.find('#')
+                       while p1 != -1:
+                               bug = Bug()
+                               p2 = p1 + 1
+                               while p2 < len (message) and \
+                                     message[p2].isdigit():
+                                       p2 = p2 + 1
+                               bug.number = message[p1+1:p2]
+                               bug.author = author
+                               self.bug_commits.append(bug)
+                               p1 = message.find('#', p2)
+               else:
+                       self.commits += ' - ' + message + ' (' + author + ').\n'
+
+       def query_bug_commits(self):
                bugs = ''
-               co = None
-               changes = 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()
-                               self.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
+               for bug in self.bug_commits:
+                       bugs += bug.number + ','
 
                # Bugzilla query to use
                query = 'http://bugzilla.gnome.org/buglist.cgi?ctype=csv' \
@@ -293,9 +195,138 @@ class Project:
                        bug_number = row[col_bug_id]
                        description = row[col_description]
 
-                       for co in self.commits:
-                               if co.bug == bug_number:
-                                       co.summary = 'Fixed #%s, %s (%s)' % (co.bug, description, co.author)
+                       for bug in self.bug_commits:
+                               if bug.number == bug_number:
+                                       self.bugs += ' - Fixed #%s, %s (%s)\n' % (bug.number, description, bug.author)
                                        break
 
-p = Project()
+       def get_commits(self):
+               self.commits = ''
+               self.translations = ''
+               self.bugs = ''
+               self.bug_commits = []
+               last_tag = self.get_last_tag()
+               ref = None
+
+               changes = self.exec_cmd ("git log " + last_tag + "..")
+               for line in changes.splitlines(1):
+                       if line.startswith('commit'):
+                               if ref != None:
+                                       self.parse_commit (ref, author, date, message)
+                               p1 = line.find(' ')
+                               ref = line[p1:].strip()
+                               author = ''
+                               date = ''
+                               message = ''
+                       elif line.startswith('Author:'):
+                               p1 = line.find(' ')
+                               p2 = line.find('<')
+                               author = line[p1:p2].strip()
+                       elif line.startswith('Date:'):
+                               p1 = line.find(' ')
+                               date = line[p1:].strip()
+                       elif line.startswith('    git-svn-id:'):
+                               continue
+                       elif line.startswith('    Signed-off-by:'):
+                               continue
+                       elif line.startswith('    From:'):
+                               continue
+                       elif line.startswith('Merge:'):
+                               continue
+                       else:
+                               msg = line.strip()
+                               if msg == '':
+                                       continue
+                               if message != '':
+                                       message += '\n'
+                               message += msg
+
+               if len (self.bug_commits) > 0:
+                       self.query_bug_commits ()
+
+       def make_tag(self):
+               new_tag = self.package_name.upper() + '_' +\
+                         self.package_version.replace('.', '_')
+
+               info = self.exec_cmd('git svn info | grep URL')
+               url1 = info[info.find(" "):].strip()
+               
+               end = url1.find("empathy")
+               end = url1.find("/", end)
+               url2 = url1[:end] + '/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))
+
+       def generate_news(self):
+               self.get_commits()
+               news = 'NEW in '+ self.package_version + '\n==============\n'
+               if self.commits != '':
+                       news += self.commits + '\n'
+               if self.bugs != '':
+                       news += 'Bugs fixed:\n' + self.bugs + '\n'
+               if self.translations != '':
+                       news += 'Translations:\n' + self.translations + '\n'
+
+               return news
+
+       def write_news(self):
+               news = self.generate_news()
+
+               f = open ('/tmp/NEWS', 'w')
+               s = f.write(news)
+               f.close()
+
+               self.exec_cmd('cat NEWS >> /tmp/NEWS')
+               self.exec_cmd('mv /tmp/NEWS .')
+
+       def upload_tarball(self):
+               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 -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)
+
+       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 ()
+