setup_osx.py 6.95 KB
Newer Older
roidelapluie's avatar
roidelapluie committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
## setup_osx.py
##
## Copyright (C) 2007 James Newton <redshodan AT gmail.com>
## Copyright (C) 2007-2008 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
##
## This file is part of Gajim.
##
## Gajim is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 only.
##
## Gajim is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
"""
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'
Yann Leboulanger's avatar
Yann Leboulanger committed
38
VERSION = '0.12.1'
39 40 41 42 43 44 45 46 47 48 49 50
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\
51
export PYTHONPATH=%s/lib/python2.5/site-packages:%s/lib/python2.5/site-packages/gtk-2.0 \n\
52
exec ${0}.bin \n\
53
' % (GTK_DIR, GTK_DIR, GTK_DIR, GTK_DIR)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

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):
73
	if isinstance(ret, list):
74 75
		if ret[0] != 0:
			raise Exception("Command failed: " + ret[1])
76
	elif isinstance(ret, int):
77 78 79 80 81 82 83 84
		if ret != 0:
			raise Exception("Command failed")
	return


def force(func):
	try:
		func()
85
	except Exception:
86 87 88 89 90
		pass
	return


def writeScript(filename, contents):
91
	script = open(filename, "w+")
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
	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


147 148 149 150
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")
151 152
	new = open("dist/Gajim.app/Contents/Resources/__boot__.py", "w+")
	org = open("dist/Gajim.app/Contents/Resources/__boot__.py.org")
153 154 155 156 157 158 159
	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")
160 161 162 163 164 165 166
	return


def finishApp():
	# setup gajim dirs
	copytree("build/inst/share/gajim/data", APP_RS + "/data")
	copy("data/pixmaps/gajim.icns", APP_RS + "/data/pixmaps")
167
	copytree("build/inst/share/locale", APP_RS + "/locale")
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
	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)
183
	setupPrep()
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
	# 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"
215
	sys.argv.append('--use-pythonpath')
216 217 218 219 220 221
	cleanup()
	stageInstall()
	buildApp()
	finishApp()
elif sys.argv[1] == "dist":
	distApp()
222

223
# vim: se ts=3: