Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame^] | 1 | """Tag the sandbox for release, make source and doc tarballs. |
| 2 | |
| 3 | Requires Python 2.6 |
| 4 | |
| 5 | Example of invocation (use to test the script): |
| 6 | python makerelease.py --force --retag 0.5.0 0.6.0-dev |
| 7 | |
| 8 | Example of invocation when doing a release: |
| 9 | python makerelease.py 0.5.0 0.6.0-dev |
| 10 | """ |
| 11 | import os.path |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import doxybuild |
| 15 | import subprocess |
| 16 | import xml.etree.ElementTree as ElementTree |
| 17 | |
| 18 | SVN_ROOT = 'https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/' |
| 19 | SVN_TAG_ROOT = SVN_ROOT + 'tags/jsoncpp' |
| 20 | |
| 21 | def set_version( version ): |
| 22 | with open('version','wb') as f: |
| 23 | f.write( version.strip() ) |
| 24 | |
| 25 | class SVNError(Exception): |
| 26 | pass |
| 27 | |
| 28 | def svn_command( command, *args ): |
| 29 | cmd = ['svn', '--non-interactive', command] + list(args) |
| 30 | print 'Running:', ' '.join( cmd ) |
| 31 | process = subprocess.Popen( cmd, |
| 32 | stdout=subprocess.PIPE, |
| 33 | stderr=subprocess.STDOUT ) |
| 34 | stdout = process.communicate()[0] |
| 35 | if process.returncode: |
| 36 | error = SVNError( 'SVN command failed:\n' + stdout ) |
| 37 | error.returncode = process.returncode |
| 38 | raise error |
| 39 | return stdout |
| 40 | |
| 41 | def check_no_pending_commit(): |
| 42 | """Checks that there is no pending commit in the sandbox.""" |
| 43 | stdout = svn_command( 'status', '--xml' ) |
| 44 | etree = ElementTree.fromstring( stdout ) |
| 45 | msg = [] |
| 46 | for entry in etree.getiterator( 'entry' ): |
| 47 | path = entry.get('path') |
| 48 | status = entry.find('wc-status').get('item') |
| 49 | if status != 'unversioned': |
| 50 | msg.append( 'File "%s" has pending change (status="%s")' % (path, status) ) |
| 51 | if msg: |
| 52 | msg.insert(0, 'Pending change to commit found in sandbox. Commit them first!' ) |
| 53 | return '\n'.join( msg ) |
| 54 | |
| 55 | def svn_join_url( base_url, suffix ): |
| 56 | if not base_url.endswith('/'): |
| 57 | base_url += '/' |
| 58 | if suffix.startswith('/'): |
| 59 | suffix = suffix[1:] |
| 60 | return base_url + suffix |
| 61 | |
| 62 | def svn_check_if_tag_exist( tag_url ): |
| 63 | """Checks if a tag exist. |
| 64 | Returns: True if the tag exist, False otherwise. |
| 65 | """ |
| 66 | try: |
| 67 | list_stdout = svn_command( 'list', tag_url ) |
| 68 | except SVNError, e: |
| 69 | if e.returncode != 1 or not str(e).find('tag_url'): |
| 70 | raise e |
| 71 | # otherwise ignore error, meaning tag does not exist |
| 72 | return False |
| 73 | return True |
| 74 | |
| 75 | def svn_tag_sandbox( tag_url, message ): |
| 76 | """Makes a tag based on the sandbox revisions. |
| 77 | """ |
| 78 | svn_command( 'copy', '-m', message, '.', tag_url ) |
| 79 | |
| 80 | def svn_remove_tag( tag_url, message ): |
| 81 | """Removes an existing tag. |
| 82 | """ |
| 83 | svn_command( 'delete', '-m', message, tag_url ) |
| 84 | |
| 85 | def main(): |
| 86 | usage = """%prog release_version next_dev_version |
| 87 | Update 'version' file to release_version and commit. |
| 88 | Generates the document tarball. |
| 89 | Tags the sandbox revision with release_version. |
| 90 | Update 'version' file to next_dev_version and commit. |
| 91 | |
| 92 | Performs an svn export of tag release version, and build a source tarball. |
| 93 | |
| 94 | Must be started in the project top directory. |
| 95 | """ |
| 96 | from optparse import OptionParser |
| 97 | parser = OptionParser(usage=usage) |
| 98 | parser.allow_interspersed_args = False |
| 99 | parser.add_option('--dot', dest="dot_path", action='store', default=doxybuild.find_program('dot'), |
| 100 | help="""Path to GraphViz dot tool. Must be full qualified path. [Default: %default]""") |
| 101 | parser.add_option('--doxygen', dest="doxygen_path", action='store', default=doxybuild.find_program('doxygen'), |
| 102 | help="""Path to Doxygen tool. [Default: %default]""") |
| 103 | parser.add_option('--force', dest="ignore_pending_commit", action='store_true', default=False, |
| 104 | help="""Ignore pending commit. [Default: %default]""") |
| 105 | parser.add_option('--retag', dest="retag_release", action='store_true', default=False, |
| 106 | help="""Overwrite release existing tag if it exist. [Default: %default]""") |
| 107 | parser.enable_interspersed_args() |
| 108 | options, args = parser.parse_args() |
| 109 | |
| 110 | if len(args) < 1: |
| 111 | parser.error( 'release_version missing on command-line.' ) |
| 112 | release_version = args[0] |
| 113 | |
| 114 | if options.ignore_pending_commit: |
| 115 | msg = '' |
| 116 | else: |
| 117 | msg = check_no_pending_commit() |
| 118 | if not msg: |
| 119 | print 'Setting version to', release_version |
| 120 | set_version( release_version ) |
| 121 | tag_url = svn_join_url( SVN_TAG_ROOT, release_version ) |
| 122 | if svn_check_if_tag_exist( tag_url ): |
| 123 | if options.retag_release: |
| 124 | svn_remove_tag( tag_url, 'Overwriting previous tag' ) |
| 125 | else: |
| 126 | print 'Aborting, tag %s already exist. Use --retag to overwrite it!' % tag_url |
| 127 | sys.exit( 1 ) |
| 128 | svn_tag_sandbox( tag_url, 'Release ' + release_version ) |
| 129 | print 'Generated doxygen document...' |
| 130 | doxybuild.build_doc( options, make_release=True ) |
| 131 | #@todo: |
| 132 | # svn export |
| 133 | # source tarball |
| 134 | # decompress source tarball |
| 135 | # ?compile & run & check |
| 136 | # ?upload documentation |
| 137 | else: |
| 138 | sys.stderr.write( msg + '\n' ) |
| 139 | |
| 140 | if __name__ == '__main__': |
| 141 | main() |