PageRenderTime 213ms CodeModel.GetById 141ms app.highlight 7ms RepoModel.GetById 63ms app.codeStats 0ms

/tools/build_release.py

http://crunchy.googlecode.com/
Python | 123 lines | 104 code | 12 blank | 7 comment | 14 complexity | a92302e177f2d2d2a123820514f3f1d4 MD5 | raw file
  1#!/usr/bin/env python
  2# encoding: utf-8
  3"""
  4build_release.py
  5
  6Created by Johannes Woolard on 2008-04-14.
  7"""
  8
  9import sys
 10from subprocess import call
 11
 12import pysvn
 13
 14help_message = '''build_release.py
 15Usage: python build_release version targets
 16
 17targets should be a space separated list. If no target is given, then the source will be downloaded
 18but no targets will be built. The following targets are currently supported:
 19 * zip
 20 * tar.gz
 21
 22Run this from an empty directory - it will download the appropriate release version from
 23http://crunchy.googlecode.com/svn/tags/'version' (where version is the version given as
 24an argument to te command).
 25
 26IMPORTANT: Always run this from an empty directory.
 27
 28Final release files will end up in the curent working directory.
 29
 30This script relies on pysvn from http://pysvn.tigris.org/
 31'''
 32
 33
 34def main(argv=None):
 35    if argv is None:
 36        argv = sys.argv
 37    if len(argv) < 2:
 38        sys.stderr.write(help_message)
 39        return 2
 40    version = argv[1]
 41    print "Creating dist packages for Crunchy, version %s" % version
 42    
 43    print "Exporting dist from http://crunchy.googlecode.com/svn/tags/%s" % version
 44    client = pysvn.Client()
 45    revision = client.export("http://crunchy.googlecode.com/svn/tags/%s" % version, 
 46                                "./crunchy-%s"%version)
 47    print "Successfully exported revision %s from http://crunchy.googlecode.com/svn/tags/%s" % \
 48                                (revision.number, version)
 49    
 50    if "zip" in argv:
 51        create_zip(version)
 52    
 53    if "tar.gz" in argv:
 54        create_targz(version)
 55    
 56    #this doesn't work yet :(
 57    if "mac" in argv:
 58        build_mac_app(version)
 59        
 60    if "deb" in argv:
 61        print "deb file creation not currently supported"
 62        
 63    if "rpm" in argv:
 64        print "rpm file creation not currently supported"
 65        
 66    if "py2exe" in argv:
 67        print "py2exe not currently supported"
 68        
 69    if "nsis" in argv:
 70        print "nsis not currently supported"
 71        
 72    if "msi" in argv:
 73        print "msi file creation not currently supported"
 74    
 75    return 0
 76
 77def create_zip(version):
 78    print "Creating crunchy-%s.zip" % version
 79    retcode = call(["/usr/bin/zip", "-q", "-r", "crunchy-%s.zip" % version, "crunchy-%s" % version])
 80    if retcode == 0:
 81        print "zip file succesfully created"
 82    else:
 83        raise "zip returned error code %s" % retcode
 84
 85def create_targz(version):
 86    print "Creating crunchy-%s.tar.gz" % version
 87    retcode = call(["/usr/bin/tar", "-czf", "crunchy-%s.tar.gz" % version, "crunchy-%s/" % version])
 88    if retcode == 0:
 89        print "tar.gz file succesfully created"
 90    else:
 91        raise "tar returned error code %s" % retcode
 92        
 93def build_mac_app(version):
 94    print "Creating setup.py for OSX .app"
 95    f = open("setup.py", 'w')
 96    f.write("""
 97from setuptools import setup
 98
 99APP = ['crunchy-%s/crunchy.py']
100DATA_FILES = ['crunchy-%s/translations',
101 'crunchy-%s/server_root',
102 'crunchy-%s/LICENSE.txt',
103 'crunchy-%s/src/plugins']
104OPTIONS = {'argv_emulation': True}
105
106setup(
107    app=APP,
108    data_files=DATA_FILES,
109    options={'py2app': OPTIONS},
110    setup_requires=['py2app'],
111)
112    """ % (version, version, version, version, version))
113    f.close()
114    print "Created setup.py, running py2app"
115    retcode = call(["/usr/bin/python", "setup.py", "py2app", "-s"])
116    if retcode == 0:
117        print ".app file succesfully created - you will have to put it into a .dmg manually"
118    else:
119        raise ("py2app returned error code %s" % retcode)
120    
121    
122if __name__ == "__main__":
123    sys.exit(main())