instrumentation: add next-share/
[cs-p2p-next.git] / instrumentation / next-share / BaseLib / Player / Build / Mac / setuptriblermac.py
1 # ---------------
2 # This script builds build/SwarmPlayer.app
3 #
4 # Meant to be called from Tribler/Player/Build/Mac/Makefile
5 # ---------------
6
7 import py2app
8 from distutils.util import get_platform
9 import sys,os,platform,shutil
10 from setuptools import setup
11
12 from BaseLib.__init__ import LIBRARYNAME
13
14 # modules to include into bundle
15 includeModules=["encodings.hex_codec","encodings.utf_8","encodings.latin_1","xml.sax", "email.iterators"]
16
17 # ----- some basic checks
18
19 if __debug__:
20     print "WARNING: Non optimised python bytecode (.pyc) will be produced. Run with -OO instead to produce and bundle .pyo files."
21
22 if sys.platform != "darwin":
23     print "WARNING: You do not seem to be running Mac OS/X." 
24
25 # ----- import and verify wxPython
26
27 import wxversion
28
29 wxversion.select('2.8-unicode')
30
31 import wx
32
33 v = wx.__version__
34
35 if v < "2.6":
36     print "WARNING: You need wxPython 2.6 or higher but are using %s." % v
37
38 if v < "2.8.4.2":
39     print "WARNING: wxPython before 2.8.4.2 could crash when loading non-present fonts. You are using %s." % v
40
41 # ----- import and verify M2Crypto
42
43 import M2Crypto
44 import M2Crypto.m2
45 if "ec_init" not in M2Crypto.m2.__dict__:
46     print "WARNING: Could not import specialistic M2Crypto (imported %s)" % M2Crypto.__file__
47
48 # ----- import VLC
49
50 #import vlc
51
52 #vlc = vlc.MediaControl(["--plugin-path",os.getcwd()+"/macbinaries/vlc_plugins"])
53
54 # =================
55 # build SwarmPlayer.app
56 # =================
57
58 from plistlib import Plist
59
60 def includedir( srcpath, dstpath = None ):
61     """ Recursive directory listing, filtering out svn files. """
62
63     total = []
64
65     cwd = os.getcwd()
66     os.chdir( srcpath )
67
68     if dstpath is None:
69         dstpath = srcpath
70
71     for root,dirs,files in os.walk( "." ):
72         if '.svn' in dirs:
73             dirs.remove('.svn')
74
75         for f in files:
76             total.append( (root,f) )
77
78     os.chdir( cwd )
79
80     # format: (targetdir,[file])
81     # so for us, (dstpath/filedir,[srcpath/filedir/filename])
82     return [("%s/%s" % (dstpath,root),["%s/%s/%s" % (srcpath,root,f)]) for root,f in total]
83
84 def filterincludes( l, f ):
85     """ Return includes which pass filter f. """
86
87     return [(x,y) for (x,y) in l if f(y[0])]
88
89 # ----- build the app bundle
90 mainfile = os.path.join(LIBRARYNAME,'Player','swarmplayer.py')
91
92 setup(
93     setup_requires=['py2app'],
94     name='SwarmPlayer',
95     app=[mainfile],
96     options={ 'py2app': {
97         'argv_emulation': True,
98         'includes': includeModules,
99         'excludes': ["Tkinter","Tkconstants","tcl"],
100         'iconfile': LIBRARYNAME+'/Player/Build/Mac/tribler.icns',
101         'plist': Plist.fromFile(LIBRARYNAME+'/Player/Build/Mac/Info.plist'),
102         'optimize': 2*int(not __debug__),
103         'resources':
104             [(LIBRARYNAME+"/Lang", [LIBRARYNAME+"/Lang/english.lang"]),
105              LIBRARYNAME+"/binary-LICENSE.txt", 
106              LIBRARYNAME+"/readme.txt",
107              LIBRARYNAME+"/Images/SwarmPlayerIcon.ico",
108              LIBRARYNAME+"/Player/Build/Mac/TriblerDoc.icns",
109            ]
110            # add images
111            + includedir( LIBRARYNAME+"/Images" )
112
113            # add VLC plugins
114            + includedir( "macbinaries/vlc_plugins" )
115
116            # add ffmpeg binary
117            + ["macbinaries/ffmpeg"]
118             ,
119     } }
120 )