| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | """ |
|---|
| 23 | Usage: |
|---|
| 24 | python setup_osx.py [build | dist] |
|---|
| 25 | """ |
|---|
| 26 | |
|---|
| 27 | from setuptools import setup |
|---|
| 28 | import sys, glob, os, commands, types |
|---|
| 29 | from os import system, unlink, symlink, getcwd, mkdir, utime |
|---|
| 30 | from shutil import move, copy, copytree, rmtree |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | GTK_DIR="/Library/Frameworks/GTK+.framework/Versions/Current" |
|---|
| 37 | NAME = 'Gajim' |
|---|
| 38 | VERSION = '0.12-alpha1' |
|---|
| 39 | DESCRIPTION = 'A full featured Jabber client' |
|---|
| 40 | AUTHOR = 'Gajim Development Team' |
|---|
| 41 | URL = 'http://www.gajim.org/' |
|---|
| 42 | DOWNLOAD_URL = 'http://www.gajim.org/downloads.php' |
|---|
| 43 | LICENSE = 'GPL' |
|---|
| 44 | PWD = getcwd() |
|---|
| 45 | APP_RS = "dist/Gajim.app/Contents/Resources" |
|---|
| 46 | |
|---|
| 47 | GAJIM_SCRIPT = \ |
|---|
| 48 | '#!/bin/bash \n\ |
|---|
| 49 | export DYLD_LIBRARY_PATH=%s/lib \n\ |
|---|
| 50 | 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 | GAJIM_REMOTE_SCRIPT = \ |
|---|
| 56 | '#!/bin/bash \n\ |
|---|
| 57 | export DYLD_LIBRARY_PATH=%s/lib \n\ |
|---|
| 58 | TOPDIR=${0%%/MacOS/gajim-remote} \n\ |
|---|
| 59 | echo "${TOPDIR}" | grep -e "^/" \n\ |
|---|
| 60 | [ $? -ne 0 ] && TOPDIR=`pwd`/${TOPDIR} \n\ |
|---|
| 61 | export RESOURCEPATH=${TOPDIR}/Resources \n\ |
|---|
| 62 | export PYTHONHOME=${RESOURCEPATH}/lib/python2.5 \n\ |
|---|
| 63 | export PYTHONPATH=${RESOURCEPATH}/lib/python2.5/lib-dynload:${RESOURCEPATH}/lib/python2.5/site-packages.zip:${PYTHONPATH} \n\ |
|---|
| 64 | cd ${RESOURCEPATH} \n\ |
|---|
| 65 | exec ${TOPDIR}/MacOS/Python ${RESOURCEPATH}/gajim-remote.py $* \n\ |
|---|
| 66 | ' % GTK_DIR |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | def check(ret): |
|---|
| 73 | if type(ret) == types.ListType: |
|---|
| 74 | if ret[0] != 0: |
|---|
| 75 | raise Exception("Command failed: " + ret[1]) |
|---|
| 76 | elif type(ret) == types.IntType: |
|---|
| 77 | if ret != 0: |
|---|
| 78 | raise Exception("Command failed") |
|---|
| 79 | return |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | def force(func): |
|---|
| 83 | try: |
|---|
| 84 | func() |
|---|
| 85 | except: |
|---|
| 86 | pass |
|---|
| 87 | return |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | def writeScript(filename, contents): |
|---|
| 91 | script = file(filename, "w+") |
|---|
| 92 | script.write(contents) |
|---|
| 93 | script.close() |
|---|
| 94 | system("chmod +x %s" % filename) |
|---|
| 95 | return |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | def cleanup(): |
|---|
| 99 | force(lambda:rmtree("build")) |
|---|
| 100 | force(lambda:rmtree("dist")) |
|---|
| 101 | |
|---|
| 102 | def stageInstall(): |
|---|
| 103 | 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))) |
|---|
| 104 | force(lambda:unlink("src/osx/growl/_growl.so")) |
|---|
| 105 | force(lambda:unlink("src/osx/growl/_growlImage.so")) |
|---|
| 106 | force(lambda:unlink("src/osx/idle.so")) |
|---|
| 107 | force(lambda:unlink("src/osx/nsapp.so")) |
|---|
| 108 | force(lambda:unlink("src/osx/syncmenu.so")) |
|---|
| 109 | force(lambda:unlink("src/gtkspell.so")) |
|---|
| 110 | symlink("%s/build/inst/lib/gajim/_growl.so" % PWD, "src/osx/growl/_growl.so") |
|---|
| 111 | symlink("%s/build/inst/lib/gajim/_growlImage.so" % PWD, |
|---|
| 112 | "src/osx/growl/_growlImage.so") |
|---|
| 113 | symlink("%s/build/inst/lib/gajim/idle.so" % PWD, "src/osx/idle.so") |
|---|
| 114 | symlink("%s/build/inst/lib/gajim/nsapp.so" % PWD, "src/osx/nsapp.so") |
|---|
| 115 | symlink("%s/build/inst/lib/gajim/syncmenu.so" % PWD, "src/osx/syncmenu.so") |
|---|
| 116 | if os.path.isfile("build/inst/lib/gajim/gtkspell.so"): |
|---|
| 117 | symlink("%s/build/inst/lib/gajim/gtkspell.so" % PWD, "src/gtkspell.so") |
|---|
| 118 | return |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | def buildApp(): |
|---|
| 122 | sys.path.append('src') |
|---|
| 123 | sys.path.append(GTK_DIR + "/lib/python2.5/site-packages") |
|---|
| 124 | sys.path.append(GTK_DIR + "/lib/python2.5/site-packages/gtk-2.0") |
|---|
| 125 | OPTIONS = {'argv_emulation':True, |
|---|
| 126 | 'excludes':'docutils,Crypto,dbus,OpenSSL,cairo,gtk,gobject,atk,pangocairo', |
|---|
| 127 | 'iconfile':'data/pixmaps/gajim.icns', |
|---|
| 128 | 'includes':'osx,ConfigParser,compiler,UserString,history_manager', |
|---|
| 129 | 'plist':{'LSMinimumSystemVersion':'10.4.0', |
|---|
| 130 | 'NSHumanReadableCopyright':'GNU General Public License', |
|---|
| 131 | 'CFBundleIdentifier':'org.gajim', |
|---|
| 132 | 'NSMainNibFile':'Gajim', |
|---|
| 133 | }, |
|---|
| 134 | } |
|---|
| 135 | setup( |
|---|
| 136 | name = NAME, version = VERSION, description = DESCRIPTION, |
|---|
| 137 | author = AUTHOR, url = URL, download_url = DOWNLOAD_URL, |
|---|
| 138 | license = LICENSE, |
|---|
| 139 | app=['src/gajim.py'], |
|---|
| 140 | data_files=['data/nibs/Gajim.nib'], |
|---|
| 141 | options={'py2app': OPTIONS}, |
|---|
| 142 | setup_requires=['py2app'], |
|---|
| 143 | ) |
|---|
| 144 | return |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | def setupPrep(): |
|---|
| 148 | copy("src/osx/prep_py2app.py", APP_RS) |
|---|
| 149 | move("dist/Gajim.app/Contents/Resources/__boot__.py", |
|---|
| 150 | "dist/Gajim.app/Contents/Resources/__boot__.py.org") |
|---|
| 151 | new = file("dist/Gajim.app/Contents/Resources/__boot__.py", "w+") |
|---|
| 152 | org = file("dist/Gajim.app/Contents/Resources/__boot__.py.org") |
|---|
| 153 | for line in org: |
|---|
| 154 | new.write(line) |
|---|
| 155 | if (('site.addsitedir' in line) and ('Python' in line)): |
|---|
| 156 | new.write(" import prep_py2app\n") |
|---|
| 157 | new.close() |
|---|
| 158 | org.close() |
|---|
| 159 | unlink("dist/Gajim.app/Contents/Resources/__boot__.py.org") |
|---|
| 160 | return |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | def finishApp(): |
|---|
| 164 | |
|---|
| 165 | copytree("build/inst/share/gajim/data", APP_RS + "/data") |
|---|
| 166 | copy("data/pixmaps/gajim.icns", APP_RS + "/data/pixmaps") |
|---|
| 167 | copytree("build/inst/share/locale", APP_RS + "/locale") |
|---|
| 168 | copytree("build/inst/share/man", APP_RS + "/man") |
|---|
| 169 | force(lambda:unlink("dist/Gajim.app/Contents/data")) |
|---|
| 170 | symlink("Resources/data", "dist/Gajim.app/Contents/data") |
|---|
| 171 | copy("src/gajim-remote.py", "dist/Gajim.app/Contents/Resources") |
|---|
| 172 | |
|---|
| 173 | move("dist/Gajim.app/Contents/Frameworks/Python.framework", |
|---|
| 174 | "dist/Gajim.app/Contents/Python.framework") |
|---|
| 175 | rmtree("dist/Gajim.app/Contents/Frameworks") |
|---|
| 176 | mkdir("dist/Gajim.app/Contents/Frameworks") |
|---|
| 177 | move("dist/Gajim.app/Contents/Python.framework", |
|---|
| 178 | "dist/Gajim.app/Contents/Frameworks/Python.framework") |
|---|
| 179 | |
|---|
| 180 | move("dist/Gajim.app/Contents/MacOS/Gajim", |
|---|
| 181 | "dist/Gajim.app/Contents/MacOS/Gajim.bin") |
|---|
| 182 | writeScript("dist/Gajim.app/Contents/MacOS/Gajim", GAJIM_SCRIPT) |
|---|
| 183 | setupPrep() |
|---|
| 184 | |
|---|
| 185 | writeScript("dist/Gajim.app/Contents/MacOS/gajim-remote", |
|---|
| 186 | GAJIM_REMOTE_SCRIPT) |
|---|
| 187 | |
|---|
| 188 | utime("dist/Gajim.app", None) |
|---|
| 189 | return |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | def distApp(): |
|---|
| 193 | force(lambda:rmtree("dist/Gajim")) |
|---|
| 194 | force(lambda:rmtree("dist/Gajim.tar.bz2")) |
|---|
| 195 | mkdir("dist/Gajim") |
|---|
| 196 | check(system("tar -cf - -C dist Gajim.app | tar -xf - -C dist/Gajim")) |
|---|
| 197 | copy("README.osx", "dist/Gajim/README") |
|---|
| 198 | copy("TODO.osx", "dist/Gajim/TODO") |
|---|
| 199 | check(system("tar -C dist -jcf dist/Gajim-OSX-`date | awk '{printf(\"%s-%s-%s\", $6, $2, $3);}'`.tar.bz2 Gajim")) |
|---|
| 200 | rmtree("dist/Gajim") |
|---|
| 201 | return |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | if ((len(sys.argv) != 2) or ((sys.argv[1] != "build") and |
|---|
| 209 | (sys.argv[1] != "dist"))): |
|---|
| 210 | print "usage: python setup_osx.py [build]" |
|---|
| 211 | print " or: python setup_osx.py [dist]" |
|---|
| 212 | sys.exit(1) |
|---|
| 213 | elif sys.argv[1] == "build": |
|---|
| 214 | sys.argv[1] = "py2app" |
|---|
| 215 | sys.argv.append('--use-pythonpath') |
|---|
| 216 | cleanup() |
|---|
| 217 | stageInstall() |
|---|
| 218 | buildApp() |
|---|
| 219 | finishApp() |
|---|
| 220 | elif sys.argv[1] == "dist": |
|---|
| 221 | distApp() |
|---|
| 222 | |
|---|
| 223 | |
|---|