root/trunk/setup_osx.py

Revision 10247, 7.0 kB (checked in by roidelapluie, 3 weeks ago)
  • Big headers review
  • Remove some licencing problems
  • To do: same for images
  • See #4200
Line 
1## setup_osx.py
2##
3## Copyright (C) 2007 James Newton <redshodan AT gmail.com>
4## Copyright (C) 2007-2008 Yann Leboulanger <asterix AT lagaule.org>
5## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
6##
7## This file is part of Gajim.
8##
9## Gajim is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published
11## by the Free Software Foundation; version 3 only.
12##
13## Gajim is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
20##
21
22"""
23Usage:
24    python setup_osx.py [build | dist]
25"""
26
27from setuptools import setup
28import sys, glob, os, commands, types
29from os import system, unlink, symlink, getcwd, mkdir, utime
30from shutil import move, copy, copytree, rmtree
31
32###
33### Globals
34###
35
36GTK_DIR="/Library/Frameworks/GTK+.framework/Versions/Current"
37NAME = 'Gajim'
38VERSION = '0.12-alpha1'
39DESCRIPTION = 'A full featured Jabber client'
40AUTHOR = 'Gajim Development Team'
41URL = 'http://www.gajim.org/'
42DOWNLOAD_URL = 'http://www.gajim.org/downloads.php'
43LICENSE = 'GPL'
44PWD = getcwd()
45APP_RS = "dist/Gajim.app/Contents/Resources"
46
47GAJIM_SCRIPT = \
48'#!/bin/bash \n\
49export DYLD_LIBRARY_PATH=%s/lib \n\
50export PATH=%s/bin:$PATH \n\
51export PYTHONPATH=%s/lib/python2.5/site-packages:%s/lib/python2.5/site-packages/gtk-2.0 \n\
52exec ${0}.bin \n\
53' % (GTK_DIR, GTK_DIR, GTK_DIR, GTK_DIR)
54
55GAJIM_REMOTE_SCRIPT = \
56'#!/bin/bash \n\
57export DYLD_LIBRARY_PATH=%s/lib \n\
58TOPDIR=${0%%/MacOS/gajim-remote} \n\
59echo "${TOPDIR}" | grep -e "^/" \n\
60[ $? -ne 0 ] && TOPDIR=`pwd`/${TOPDIR} \n\
61export RESOURCEPATH=${TOPDIR}/Resources \n\
62export PYTHONHOME=${RESOURCEPATH}/lib/python2.5 \n\
63export PYTHONPATH=${RESOURCEPATH}/lib/python2.5/lib-dynload:${RESOURCEPATH}/lib/python2.5/site-packages.zip:${PYTHONPATH} \n\
64cd ${RESOURCEPATH} \n\
65exec ${TOPDIR}/MacOS/Python ${RESOURCEPATH}/gajim-remote.py $* \n\
66' % GTK_DIR
67
68###
69### Functions
70###
71
72def 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
82def force(func):
83        try:
84                func()
85        except:
86                pass
87        return
88
89
90def 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
98def cleanup():
99        force(lambda:rmtree("build"))
100        force(lambda:rmtree("dist"))
101
102def 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
121def 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
147def 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
163def finishApp():
164        # setup gajim dirs
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        # Nuke libs that are in the framework
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        # Adjust the running of the app
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        # Setup the gajim-remote script
185        writeScript("dist/Gajim.app/Contents/MacOS/gajim-remote",
186                                GAJIM_REMOTE_SCRIPT)
187        # Touch the top dir so Finder knows to update its idea of this bundle
188        utime("dist/Gajim.app", None)
189        return
190
191
192def 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### Start
207###
208if ((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)
213elif sys.argv[1] == "build":
214        sys.argv[1] = "py2app"
215        sys.argv.append('--use-pythonpath')
216        cleanup()
217        stageInstall()
218        buildApp()
219        finishApp()
220elif sys.argv[1] == "dist":
221        distApp()
222
223# vim: se ts=3:
Note: See TracBrowser for help on using the browser.