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.
5 # Run the build process by entering 'pygame2exe.py' or
6 # 'python pygame2exe.py' in a console prompt.
8 # To build exe, python, pygame, and py2exe have to be installed. After
9 # building exe none of this libraries are needed.
12 from distutils
.core
import setup
14 from modulefinder
import Module
16 import sys
, os
, shutil
18 except ImportError, message
:
19 raise SystemExit, "Unable to load module. %s" % message
22 origIsSystemDLL
= py2exe
.build_exe
.isSystemDLL
23 def isSystemDLL(pathname
):
24 if os
.path
.basename(pathname
).lower() in ["sdl_ttf.dll"]:
26 return origIsSystemDLL(pathname
)
27 py2exe
.build_exe
.isSystemDLL
= isSystemDLL
29 def findPguThemesDir() :
31 theme_file
= pgu
.gui
.theme
.__file
__
33 dnames
.append(os
.path
.join(os
.path
.dirname(theme_file
),"..","..","data","themes"))
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"))
43 if os
.path
.isdir(dname
):
45 raise IOError('pgu themes folder not found')
49 return os
.path
.dirname(minwii
.__file
__)
51 class MinWii2exe(py2exe
.build_exe
.py2exe
) :
52 def copy_extensions(self
, extensions
) :
53 py2exe
.build_exe
.py2exe
.copy_extensions(self
, extensions
)
54 minwiiDir
= findMinwiiDir()
55 self
.copyDataFiles(os
.path
.join(minwiiDir
, 'fonts'), 'minwii/fonts')
56 self
.copyDataFiles(os
.path
.join(minwiiDir
, 'soundfonts'), 'minwii/soundfonts')
57 self
.copyDataFiles(os
.path
.join(minwiiDir
, 'widgets', 'data'), 'minwii/widgets/data')
58 self
.copyDataFiles(findPguThemesDir(), 'data/themes')
60 pygamedir
= os
.path
.dirname(pygame
.base
.__file
__)
61 pygame_default_font
= os
.path
.join(pygamedir
, pygame
.font
.get_default_font())
62 dest
= os
.path
.join(self
.collect_dir
, 'pygame', pygame
.font
.get_default_font())
63 self
.copy_file(pygame_default_font
, dest
)
64 self
.compiled_files
.append(os
.path
.join('pygame', pygame
.font
.get_default_font()))
66 def copyDataFiles(self
, src
, dest
) :
67 src
= src
.replace('/', os
.path
.sep
)
68 reldest
= dest
.replace('/', os
.path
.sep
)
69 dest
= os
.path
.join(self
.collect_dir
, reldest
)
71 if not os
.path
.exists(dest
) :
74 for path
, dirs
, files
in os
.walk(src
) :
75 if '.svn' in path
: continue
76 relpath
= path
[len(src
)+1:]
77 if not os
.path
.exists(os
.path
.join(dest
, relpath
)) :
78 self
.mkpath(os
.path
.join(dest
, relpath
))
81 s
= os
.path
.join(path
, file)
82 d
= os
.path
.join(dest
, relpath
, file)
84 print os
.path
.join(reldest
, relpath
, file)
85 self
.compiled_files
.append(os
.path
.join(reldest
, relpath
, file))
91 self
.script
= "src/minwii/runminwii.py"
94 self
.project_name
= "MINWii"
97 self
.project_url
= "about:none"
100 self
.project_version
= "1.0"
102 #License of the program
106 self
.author_name
= "Samuel Benveniste"
107 self
.author_email
= "samuel.benveniste@gmail.com"
108 self
.copyright
= "Copyright 2010 MINES-ParisTech"
111 self
.project_description
= "Musicothérapie Interractive avec la Wiimote"
113 #Icon file (None will use pygame default icon)
114 self
.icon_file
= 'minwii.ico'
118 #Extra/excludes python modules
119 self
.extra_modules
= []
120 self
.exclude_modules
= []
123 self
.exclude_dll
= ['']
125 #Zip file name (None will bundle files in exe instead of zip file)
126 self
.zipfile_name
= 'minwii_lib.zip'
129 self
.dist_dir
='dist'
133 if os
.path
.isdir(self
.dist_dir
): #Erase previous destination dir
134 shutil
.rmtree(self
.dist_dir
)
136 if os
.path
.isdir('build'): #Clean up build dir
137 shutil
.rmtree('build')
140 #Use the default pygame icon, if none given
141 if self
.icon_file
== None:
142 path
= os
.path
.split(pygame
.__file
__)[0]
143 self
.icon_file
= os
.path
.join(path
, 'pygame.ico')
147 cmdclass
= {'py2exe': MinWii2exe
},
148 version
= self
.project_version
,
149 description
= self
.project_description
,
150 name
= self
.project_name
,
151 url
= self
.project_url
,
152 author
= self
.author_name
,
153 author_email
= self
.author_email
,
154 license
= self
.license
,
158 'script': self
.script
,
159 'icon_resources': [(0, self
.icon_file
)],
160 'copyright': self
.copyright
162 #console = [self.script],
163 options
= {'py2exe': {'optimize': 2,
166 #'excludes': self.exclude_modules,
167 #'packages': self.extra_modules,
168 #'dll_excludes': self.exclude_dll,
169 'skip_archive' : True
172 zipfile
= self
.zipfile_name
,
173 data_files
= self
.data_files
,
174 dist_dir
= self
.dist_dir
177 #if os.path.isdir('build'): #Clean up build dir
178 # shutil.rmtree('build')
180 if __name__
== '__main__':
181 if operator
.lt(len(sys
.argv
), 2):
182 sys
.argv
.append('py2exe')
183 BuildExe().run() #Run generation
184 #raw_input("Press any key to continue") #Pause to let user see that things ends