setup_osx.py 6.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
"""
Usage:
    python setup_osx.py [build | dist]
"""

from setuptools import setup
import sys, glob, os, commands, types
from os import system, unlink, symlink, getcwd, mkdir, utime
from shutil import move, copy, copytree, rmtree

###
### Globals
###

GTK_DIR="/Library/Frameworks/GTK+.framework/Versions/Current"
NAME = 'Gajim'
VERSION = '0.11'
DESCRIPTION = 'A full featured Jabber client'
AUTHOR = 'Gajim Development Team'
URL = 'http://www.gajim.org/'
DOWNLOAD_URL = 'http://www.gajim.org/downloads.php'
LICENSE = 'GPL'
PWD = getcwd()
APP_RS = "dist/Gajim.app/Contents/Resources"

GAJIM_SCRIPT = \
'#!/bin/bash \n\
export DYLD_LIBRARY_PATH=%s/lib \n\
export PATH=%s/bin:$PATH \n\
30
export PYTHONPATH=%s/lib/python2.5/site-packages:%s/lib/python2.5/site-packages/gtk-2.0 \n\
31
exec ${0}.bin \n\
32
' % (GTK_DIR, GTK_DIR, GTK_DIR, GTK_DIR)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

GAJIM_REMOTE_SCRIPT = \
'#!/bin/bash \n\
export DYLD_LIBRARY_PATH=%s/lib \n\
TOPDIR=${0%%/MacOS/gajim-remote} \n\
echo "${TOPDIR}" | grep -e "^/" \n\
[ $? -ne 0 ] && TOPDIR=`pwd`/${TOPDIR} \n\
export RESOURCEPATH=${TOPDIR}/Resources \n\
export PYTHONHOME=${RESOURCEPATH}/lib/python2.5 \n\
export PYTHONPATH=${RESOURCEPATH}/lib/python2.5/lib-dynload:${RESOURCEPATH}/lib/python2.5/site-packages.zip:${PYTHONPATH} \n\
cd ${RESOURCEPATH} \n\
exec ${TOPDIR}/MacOS/Python ${RESOURCEPATH}/gajim-remote.py $* \n\
' % GTK_DIR

###
### Functions
###

def check(ret):
	if type(ret) == types.ListType:
		if ret[0] != 0:
			raise Exception("Command failed: " + ret[1])
	elif type(ret) == types.IntType:
		if ret != 0:
			raise Exception("Command failed")
	return


def force(func):
	try:
		func()
	except:
		pass
	return


def writeScript(filename, contents):
	script = file(filename, "w+")
	script.write(contents)
	script.close()
	system("chmod +x %s" % filename)
	return


def cleanup():
	force(lambda:rmtree("build"))
	force(lambda:rmtree("dist"))

def stageInstall():
	check(system("make DATADIR=%s/build/inst LIBDIR=%s/build/inst prefix=%s/build/inst DOCDIR=%s/build/inst/share/doc install" % (PWD, PWD, PWD, PWD)))
	force(lambda:unlink("src/osx/growl/_growl.so"))
	force(lambda:unlink("src/osx/growl/_growlImage.so"))
	force(lambda:unlink("src/osx/idle.so"))
	force(lambda:unlink("src/osx/nsapp.so"))
	force(lambda:unlink("src/osx/syncmenu.so"))
	force(lambda:unlink("src/gtkspell.so"))
	symlink("%s/build/inst/lib/gajim/_growl.so" % PWD, "src/osx/growl/_growl.so")
	symlink("%s/build/inst/lib/gajim/_growlImage.so" % PWD,
		 "src/osx/growl/_growlImage.so")
	symlink("%s/build/inst/lib/gajim/idle.so" % PWD, "src/osx/idle.so")
	symlink("%s/build/inst/lib/gajim/nsapp.so" % PWD, "src/osx/nsapp.so")
	symlink("%s/build/inst/lib/gajim/syncmenu.so" % PWD, "src/osx/syncmenu.so")
	if os.path.isfile("build/inst/lib/gajim/gtkspell.so"):
		symlink("%s/build/inst/lib/gajim/gtkspell.so" % PWD, "src/gtkspell.so")
	return


def buildApp():
	sys.path.append('src')
	sys.path.append(GTK_DIR + "/lib/python2.5/site-packages")
	sys.path.append(GTK_DIR + "/lib/python2.5/site-packages/gtk-2.0")
	OPTIONS = {'argv_emulation':True,
			   'excludes':'docutils,Crypto,dbus,OpenSSL,cairo,gtk,gobject,atk,pangocairo',
			   'iconfile':'data/pixmaps/gajim.icns',
			   'includes':'osx,ConfigParser,compiler,UserString,history_manager',
			   'plist':{'LSMinimumSystemVersion':'10.4.0',
						'NSHumanReadableCopyright':'GNU General Public License',
						'CFBundleIdentifier':'org.gajim',
						'NSMainNibFile':'Gajim',
						},
			   }
	setup(
		name = NAME, version = VERSION, description = DESCRIPTION,
		author = AUTHOR, url = URL, download_url = DOWNLOAD_URL,
		license = LICENSE,
		app=['src/gajim.py'],
		data_files=['data/nibs/Gajim.nib'],
		options={'py2app': OPTIONS},
		setup_requires=['py2app'],
		)
	return


126 127 128 129 130 131 132 133 134 135 136 137 138
def setupPrep():
	copy("src/osx/prep_py2app.py", APP_RS)
	move("dist/Gajim.app/Contents/Resources/__boot__.py",
		 "dist/Gajim.app/Contents/Resources/__boot__.py.org")
	new = file("dist/Gajim.app/Contents/Resources/__boot__.py", "w+")
	org = file("dist/Gajim.app/Contents/Resources/__boot__.py.org")
	for line in org:
		new.write(line)
		if (('site.addsitedir' in line) and ('Python' in line)):
			new.write("    import prep_py2app\n")
	new.close()
	org.close()
	unlink("dist/Gajim.app/Contents/Resources/__boot__.py.org")
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
	return


def finishApp():
	# setup gajim dirs
	copytree("build/inst/share/gajim/data", APP_RS + "/data")
	copy("data/pixmaps/gajim.icns", APP_RS + "/data/pixmaps")
	copytree("build/inst/locale", APP_RS + "/locale")
	copytree("build/inst/share/man", APP_RS + "/man")
	force(lambda:unlink("dist/Gajim.app/Contents/data"))
	symlink("Resources/data", "dist/Gajim.app/Contents/data")
	copy("src/gajim-remote.py", "dist/Gajim.app/Contents/Resources")
	# Nuke libs that are in the framework
	move("dist/Gajim.app/Contents/Frameworks/Python.framework",
		 "dist/Gajim.app/Contents/Python.framework")
	rmtree("dist/Gajim.app/Contents/Frameworks")
	mkdir("dist/Gajim.app/Contents/Frameworks")
	move("dist/Gajim.app/Contents/Python.framework",
		 "dist/Gajim.app/Contents/Frameworks/Python.framework")
	# Adjust the running of the app
	move("dist/Gajim.app/Contents/MacOS/Gajim",
		 "dist/Gajim.app/Contents/MacOS/Gajim.bin")
	writeScript("dist/Gajim.app/Contents/MacOS/Gajim", GAJIM_SCRIPT)
162
	setupPrep()
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	# Setup the gajim-remote script
	writeScript("dist/Gajim.app/Contents/MacOS/gajim-remote",
				GAJIM_REMOTE_SCRIPT)
	# Touch the top dir so Finder knows to update its idea of this bundle
	utime("dist/Gajim.app", None)
	return


def distApp():
	force(lambda:rmtree("dist/Gajim"))
	force(lambda:rmtree("dist/Gajim.tar.bz2"))
	mkdir("dist/Gajim")
	check(system("tar -cf - -C dist Gajim.app | tar -xf - -C dist/Gajim"))
	copy("README.osx", "dist/Gajim/README")
	copy("TODO.osx", "dist/Gajim/TODO")
	check(system("tar -C dist -jcf dist/Gajim-OSX-`date | awk '{printf(\"%s-%s-%s\", $6, $2, $3);}'`.tar.bz2 Gajim"))
	rmtree("dist/Gajim")
	return



###
### Start
###
if ((len(sys.argv) != 2) or ((sys.argv[1] != "build") and
	(sys.argv[1] != "dist"))):
	print "usage: python setup_osx.py [build]"
	print "   or: python setup_osx.py [dist]"
	sys.exit(1)
elif sys.argv[1] == "build":
	sys.argv[1] = "py2app"
194
	sys.argv.append('--use-pythonpath')
195 196 197 198 199 200
	cleanup()
	stageInstall()
	buildApp()
	finishApp()
elif sys.argv[1] == "dist":
	distApp()