86702fc855659f7770f2fc47ce0e7d9f68feaee5
[minwii.git] / setup_win_exe.py
1 # -*- coding: iso-8859-1 -*-
2 # This will create a dist directory containing the executable file, all the data
3 # directories. All Libraries will be bundled in executable file.
4 #
5 # Run the build process by entering 'pygame2exe.py' or
6 # 'python pygame2exe.py' in a console prompt.
7 #
8 # To build exe, python, pygame, and py2exe have to be installed. After
9 # building exe none of this libraries are needed.
10
11 try:
12 from distutils.core import setup
13 import py2exe, pygame
14 from modulefinder import Module
15 import glob, fnmatch
16 import sys, os, shutil
17 import operator
18 except ImportError, message:
19 raise SystemExit, "Unable to load module. %s" % message
20
21
22 origIsSystemDLL = py2exe.build_exe.isSystemDLL
23 def isSystemDLL(pathname):
24 if os.path.basename(pathname).lower() in ["sdl_ttf.dll"]:
25 return 0
26 return origIsSystemDLL(pathname)
27 py2exe.build_exe.isSystemDLL = isSystemDLL
28
29 def findPguThemesDir() :
30 import pgu.gui.theme
31 theme_file = pgu.gui.theme.__file__
32 dnames = []
33 dnames.append(os.path.join(os.path.dirname(theme_file),"..","..","data","themes"))
34
35 #if the package is installed, and the package is installed
36 #in /usr/lib/python2.3/site-packages/pgu/
37 #or c:\python23\lib\site-packages\pgu\
38 #the data is in ... lib/../share/ ...
39 dnames.append(os.path.join(os.path.dirname(theme_file),"..","..","..","..","share","pgu","themes"))
40 dnames.append(os.path.join(os.path.dirname(theme_file),"..","..","..","..","..","share","pgu","themes"))
41 dnames.append(os.path.join(os.path.dirname(theme_file),"..","..","share","pgu","themes"))
42 for dname in dnames:
43 if os.path.isdir(dname):
44 return dname
45 raise IOError('pgu themes folder not found')
46
47
48 class MinWii2exe(py2exe.build_exe.py2exe) :
49 def copy_extensions(self, extensions) :
50 py2exe.build_exe.py2exe.copy_extensions(self, extensions)
51
52 self.copyDataFiles('src/minwii/fonts', 'minwii/fonts')
53 self.copyDataFiles('src/minwii/soundfonts', 'minwii/soundfonts')
54 self.copyDataFiles('src/minwii/widgets/data', 'minwii/widgets/data')
55 self.copyDataFiles(findPguThemesDir(), 'data/themes')
56
57 pygamedir = os.path.dirname(pygame.base.__file__)
58 pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font())
59 dest = os.path.join(self.collect_dir, 'pygame', pygame.font.get_default_font())
60 self.copy_file(pygame_default_font, dest)
61 self.compiled_files.append(os.path.join('pygame', pygame.font.get_default_font()))
62
63 def copyDataFiles(self, src, dest) :
64 src = src.replace('/', os.path.sep)
65 reldest = dest.replace('/', os.path.sep)
66 dest = os.path.join(self.collect_dir, reldest)
67
68 if not os.path.exists(dest) :
69 self.mkpath(dest)
70
71 for path, dirs, files in os.walk(src) :
72 if '.svn' in path : continue
73 relpath = path[len(src)+1:]
74 if not os.path.exists(os.path.join(dest, relpath)) :
75 self.mkpath(os.path.join(dest, relpath))
76
77 for file in files :
78 s = os.path.join(path, file)
79 d = os.path.join(dest, relpath, file)
80 self.copy_file(s, d)
81 print os.path.join(reldest, relpath, file)
82 self.compiled_files.append(os.path.join(reldest, relpath, file))
83
84
85 class BuildExe:
86 def __init__(self):
87 #Name of starting .py
88 self.script = "src/minwii/minwii_fullscreen.py"
89
90 #Name of program
91 self.project_name = "MINWii"
92
93 #Project url
94 self.project_url = "about:none"
95
96 #Version of program
97 self.project_version = "1.0"
98
99 #License of the program
100 self.license = "GPL"
101
102 #Auhor of program
103 self.author_name = "Samuel Benveniste"
104 self.author_email = "samuel.benveniste@gmail.com"
105 self.copyright = "Copyright 2010 MINES-ParisTech"
106
107 #Description
108 self.project_description = "Musicothérapie Interractive avec la Wiimote"
109
110 #Icon file (None will use pygame default icon)
111 self.icon_file = 'minwii.ico'
112
113 self.data_files = []
114
115 #Extra/excludes python modules
116 self.extra_modules = []
117 self.exclude_modules = []
118
119 #DLL Excludes
120 self.exclude_dll = ['']
121
122 #Zip file name (None will bundle files in exe instead of zip file)
123 self.zipfile_name = 'minwii_lib.zip'
124
125 #Dist directory
126 self.dist_dir ='dist'
127
128
129 def run(self):
130 if os.path.isdir(self.dist_dir): #Erase previous destination dir
131 shutil.rmtree(self.dist_dir)
132
133 if os.path.isdir('build'): #Clean up build dir
134 shutil.rmtree('build')
135
136
137 #Use the default pygame icon, if none given
138 if self.icon_file == None:
139 path = os.path.split(pygame.__file__)[0]
140 self.icon_file = os.path.join(path, 'pygame.ico')
141
142
143 setup(
144 cmdclass = {'py2exe': MinWii2exe},
145 version = self.project_version,
146 description = self.project_description,
147 name = self.project_name,
148 url = self.project_url,
149 author = self.author_name,
150 author_email = self.author_email,
151 license = self.license,
152
153 # targets to build
154 windows = [{
155 'script': self.script,
156 'icon_resources': [(0, self.icon_file)],
157 'copyright': self.copyright
158 }],
159 #console = [self.script],
160 options = {'py2exe': {'optimize': 2,
161 'bundle_files': 3,
162 #'compressed': True,
163 #'excludes': self.exclude_modules,
164 #'packages': self.extra_modules,
165 #'dll_excludes': self.exclude_dll,
166 'skip_archive' : True
167 }
168 },
169 zipfile = self.zipfile_name,
170 data_files = self.data_files,
171 dist_dir = self.dist_dir
172 )
173
174 #if os.path.isdir('build'): #Clean up build dir
175 # shutil.rmtree('build')
176
177 if __name__ == '__main__':
178 if operator.lt(len(sys.argv), 2):
179 sys.argv.append('py2exe')
180 BuildExe().run() #Run generation
181 #raw_input("Press any key to continue") #Pause to let user see that things ends