All pastes #290363 Raw Edit

Untitled

public python v1 · immutable
#290363 ·published 2006-12-23 23:05 UTC
rendered paste body
#! /usr/bin/env python# encoding: utf-8# Thomas Keller, 2006 APPNAME='guitone'VERSION='0.5'srcdir = '.'blddir = '_build_'# path to an *.icns file created with the Icon Composer appiconsfile = 'guitone/res/osx/guitone.icns'# array of languages (ISO 639 code) for a localized application menulanguages = (['de'])import osimport sysimport shutilimport Paramsimport Runnerimport UtilsUtils.waf_version(mini="1.0.0", maxi="1.4.9")app_info = '''<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"><plist version="0.9"><dict>	<key>CFBundlePackageType</key>	<string>APPL</string>	<key>CFBundleGetInfoString</key>	<string>Created by waf</string>	<key>CFBundleSignature</key>	<string>????</string>	<key>NOTE</key>	<string>Do not change this file, it will be overwritten by waf.</string>'''app_info_foot = '''</dict></plist>'''locversion = '''<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"    "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0">    <dict>        <key>LprojCompatibleVersion</key>        <string>123</string>        <key>LprojLocale</key>        <string>%s</string>        <key>LprojRevisionLevel</key>        <string>1</string>        <key>LprojVersion</key>        <string>123</string>    </dict></plist>'''def build(bld):	bld.add_subdirs("guitone")def configure(conf):    Runner.set_exec("noredir")    conf.check_tool('g++ Qt4')def set_options(opt):    opt.tool_options('Qt4')    opt.add_option('--exe', action='store_true', default=False, help='execute the application')    if sys.platform == "darwin":        opt.add_option('--bundle', action='store_true', default=False, help='create a MacOS X application bundle')def shutdown():    global APPNAME,blddir,app_info,app_info_foot,iconsfile,locversion,languages        app_bundle = blddir + '/default/bundle/' + APPNAME + '.app'    prog_bin   = blddir + '/default/' + APPNAME + '/' + APPNAME        if Params.g_options.exe:        if sys.platform == "darwin" and os.path.exists(app_bundle):            os.popen('open "' + app_bundle + '"')        else:            os.popen(prog_bin)        if Params.g_options.bundle:        try:            # remove any old application bundle            if os.path.exists(app_bundle):                shutil.rmtree(app_bundle)                        os.makedirs(app_bundle + '/Contents/MacOS')                        # create the semi-useful PkgInfo file            f = file(app_bundle + '/Contents/PkgInfo', 'w')            f.write('APPL????')            f.close()                        # copy the binary in position            shutil.copy(prog_bin, app_bundle + '/Contents/MacOS/' + os.path.basename(prog_bin))            # write Info.plist            f = file(os.path.join(app_bundle, "Contents", "Info.plist"), "w")            f.write(app_info)            f.write("\t<key>CFBundleExecutable</key>\n\t<string>%s</string>\n" % os.path.basename(prog_bin))            # if there is an icon file, add it to the bundle            if iconsfile != "":                f.write("\t<key>CFBundleIconFile</key>\n\t<string>%s</string>\n" % os.path.basename(iconsfile))                os.makedirs(app_bundle + '/Contents/Resources')                shutil.copy(iconsfile, app_bundle + '/Contents/Resources')            f.write(app_info_foot)            f.close()                        # write locversion.plist files for each given language            for lang in languages:                langdir = app_bundle + '/Contents/Resources/' + lang + '.lproj'                os.makedirs(langdir)                f = file(os.path.join(langdir, "locversion.plist"), "w")                f.write(locversion % lang)                f.close()         except IOError, arg:            print "IOError", arg