4c42bf55061abc0c0e000a9a8dfcd0c15c7ead12
1 # -*- coding: utf-8 -*-
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')
48 class MinWii2exe(py2exe
.build_exe
.py2exe
) :
49 def copy_extensions(self
, extensions
) :
50 py2exe
.build_exe
.py2exe
.copy_extensions(self
, extensions
)
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')
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()))
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
)
68 if not os
.path
.exists(dest
) :
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
))
78 s
= os
.path
.join(path
, file)
79 d
= os
.path
.join(dest
, relpath
, file)
81 print os
.path
.join(reldest
, relpath
, file)
82 self
.compiled_files
.append(os
.path
.join(reldest
, relpath
, file))
85 #class pygame2exe(py2exe.build_exe.py2exe): #This hack make sure that pygame default font is copied: no need to modify code for specifying default font
86 # def copy_extensions(self, extensions):
87 # #Get pygame default font
88 # pygamedir = os.path.split(pygame.base.__file__)[0]
89 # pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font())
91 # #Add font to list of extension to be copied
92 # extensions.append(Module("pygame.font", pygame_default_font))
93 # py2exe.build_exe.py2exe.copy_extensions(self, extensions)
98 self
.script
= "src/minwii/start_win.py"
101 self
.project_name
= "MINWii"
104 self
.project_url
= "about:none"
107 self
.project_version
= "0.0"
109 #License of the program
113 self
.author_name
= "Samuel Benveniste"
114 self
.author_email
= "samuel.benveniste@gmail.com"
115 self
.copyright
= "Copyright 2010 MINES-ParisTech"
118 self
.project_description
= "Musicothérapie Interractive avec la Wii"
120 #Icon file (None will use pygame default icon)
121 self
.icon_file
= None
123 #Extra files/dirs copied to game
124 #self.data_files = [('minwii/fonts',
125 # glob.glob('src/minwii/fonts/*.ttf'))]
127 #Extra/excludes python modules
128 self
.extra_modules
= []
129 self
.exclude_modules
= []
132 self
.exclude_dll
= ['']
134 #Zip file name (None will bundle files in exe instead of zip file)
135 self
.zipfile_name
= 'minwii_lib.zip'
138 self
.dist_dir
='dist'
142 if os
.path
.isdir(self
.dist_dir
): #Erase previous destination dir
143 shutil
.rmtree(self
.dist_dir
)
145 if os
.path
.isdir('build'): #Clean up build dir
146 shutil
.rmtree('build')
149 #Use the default pygame icon, if none given
150 if self
.icon_file
== None:
151 path
= os
.path
.split(pygame
.__file
__)[0]
152 self
.icon_file
= os
.path
.join(path
, 'pygame.ico')
156 cmdclass
= {'py2exe': MinWii2exe
},
157 version
= self
.project_version
,
158 description
= self
.project_description
,
159 name
= self
.project_name
,
160 url
= self
.project_url
,
161 author
= self
.author_name
,
162 author_email
= self
.author_email
,
163 license
= self
.license
,
167 'script': self
.script
,
168 'icon_resources': [(0, self
.icon_file
)],
169 'copyright': self
.copyright
171 #console = [self.script],
172 options
= {'py2exe': {#'optimize': 2,
175 #'excludes': self.exclude_modules,
176 #'packages': self.extra_modules,
177 #'dll_excludes': self.exclude_dll,
178 'skip_archive' : True}
180 zipfile
= self
.zipfile_name
,
181 data_files
= self
.data_files
,
182 dist_dir
= self
.dist_dir
185 #if os.path.isdir('build'): #Clean up build dir
186 # shutil.rmtree('build')
188 if __name__
== '__main__':
189 if operator
.lt(len(sys
.argv
), 2):
190 sys
.argv
.append('py2exe')
191 BuildExe().run() #Run generation
192 #raw_input("Press any key to continue") #Pause to let user see that things ends