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 def copyDataFiles(self
, src
, dest
) :
58 src
= src
.replace('/', os
.path
.sep
)
59 reldest
= dest
.replace('/', os
.path
.sep
)
60 dest
= os
.path
.join(self
.collect_dir
, reldest
)
62 if not os
.path
.exists(dest
) :
65 for path
, dirs
, files
in os
.walk(src
) :
66 if '.svn' in path
: continue
67 relpath
= path
[len(src
)+1:]
68 if not os
.path
.exists(os
.path
.join(dest
, relpath
)) :
69 self
.mkpath(os
.path
.join(dest
, relpath
))
72 s
= os
.path
.join(path
, file)
73 d
= os
.path
.join(dest
, relpath
, file)
75 print os
.path
.join(reldest
, relpath
, file)
76 self
.compiled_files
.append(os
.path
.join(reldest
, relpath
, file))
79 #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
80 # def copy_extensions(self, extensions):
81 # #Get pygame default font
82 # pygamedir = os.path.split(pygame.base.__file__)[0]
83 # pygame_default_font = os.path.join(pygamedir, pygame.font.get_default_font())
85 # #Add font to list of extension to be copied
86 # extensions.append(Module("pygame.font", pygame_default_font))
87 # py2exe.build_exe.py2exe.copy_extensions(self, extensions)
92 self
.script
= "src/minwii/start_win.py"
95 self
.project_name
= "MINWii"
98 self
.project_url
= "about:none"
101 self
.project_version
= "0.0"
103 #License of the program
104 self
.license
= "MyApps License"
107 self
.author_name
= "Me"
108 self
.author_email
= "example@example.com"
109 self
.copyright
= "Copyright (c) 2009 Me."
112 self
.project_description
= "MyApps Description"
114 #Icon file (None will use pygame default icon)
115 self
.icon_file
= None
117 #Extra files/dirs copied to game
118 self
.data_files
= [('minwii/fonts',
119 glob
.glob('src/minwii/fonts/*.ttf'))]
121 #Extra/excludes python modules
122 self
.extra_modules
= []
123 self
.exclude_modules
= []
126 self
.exclude_dll
= ['']
128 #Zip file name (None will bundle files in exe instead of zip file)
129 self
.zipfile_name
= None
132 self
.dist_dir
='dist'
136 if os
.path
.isdir(self
.dist_dir
): #Erase previous destination dir
137 shutil
.rmtree(self
.dist_dir
)
139 if os
.path
.isdir('build'): #Clean up build dir
140 shutil
.rmtree('build')
143 #Use the default pygame icon, if none given
144 if self
.icon_file
== None:
145 path
= os
.path
.split(pygame
.__file
__)[0]
146 self
.icon_file
= os
.path
.join(path
, 'pygame.ico')
150 cmdclass
= {'py2exe': MinWii2exe
},
151 version
= self
.project_version
,
152 description
= self
.project_description
,
153 name
= self
.project_name
,
154 url
= self
.project_url
,
155 author
= self
.author_name
,
156 author_email
= self
.author_email
,
157 license
= self
.license
,
161 # 'script': self.script,
162 # 'icon_resources': [(0, self.icon_file)],
163 # 'copyright': self.copyright
165 console
= [self
.script
],
166 options
= {'py2exe': {#'optimize': 2,
169 'excludes': self
.exclude_modules
,
170 'packages': self
.extra_modules
,
171 'dll_excludes': self
.exclude_dll
}
173 zipfile
= self
.zipfile_name
,
174 data_files
= self
.data_files
,
175 dist_dir
= self
.dist_dir
178 #if os.path.isdir('build'): #Clean up build dir
179 # shutil.rmtree('build')
181 if __name__
== '__main__':
182 if operator
.lt(len(sys
.argv
), 2):
183 sys
.argv
.append('py2exe')
184 BuildExe().run() #Run generation
185 #raw_input("Press any key to continue") #Pause to let user see that things ends