On commence à mettre les données dans l'exe.
[minwii.git] / setup_win_exe.py
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.
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 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)
61
62 if not os.path.exists(dest) :
63 self.mkpath(dest)
64
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))
70
71 for file in files :
72 s = os.path.join(path, file)
73 d = os.path.join(dest, relpath, file)
74 self.copy_file(s, d)
75 print os.path.join(reldest, relpath, file)
76 self.compiled_files.append(os.path.join(reldest, relpath, file))
77
78
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())
84 #
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)
88
89 class BuildExe:
90 def __init__(self):
91 #Name of starting .py
92 self.script = "src/minwii/start_win.py"
93
94 #Name of program
95 self.project_name = "MINWii"
96
97 #Project url
98 self.project_url = "about:none"
99
100 #Version of program
101 self.project_version = "0.0"
102
103 #License of the program
104 self.license = "MyApps License"
105
106 #Auhor of program
107 self.author_name = "Me"
108 self.author_email = "example@example.com"
109 self.copyright = "Copyright (c) 2009 Me."
110
111 #Description
112 self.project_description = "MyApps Description"
113
114 #Icon file (None will use pygame default icon)
115 self.icon_file = None
116
117 #Extra files/dirs copied to game
118 self.data_files = [('minwii/fonts',
119 glob.glob('src/minwii/fonts/*.ttf'))]
120
121 #Extra/excludes python modules
122 self.extra_modules = []
123 self.exclude_modules = []
124
125 #DLL Excludes
126 self.exclude_dll = ['']
127
128 #Zip file name (None will bundle files in exe instead of zip file)
129 self.zipfile_name = None
130
131 #Dist directory
132 self.dist_dir ='dist'
133
134
135 def run(self):
136 if os.path.isdir(self.dist_dir): #Erase previous destination dir
137 shutil.rmtree(self.dist_dir)
138
139 if os.path.isdir('build'): #Clean up build dir
140 shutil.rmtree('build')
141
142
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')
147
148
149 setup(
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,
158
159 # targets to build
160 #windows = [{
161 # 'script': self.script,
162 # 'icon_resources': [(0, self.icon_file)],
163 # 'copyright': self.copyright
164 #}],
165 console = [self.script],
166 options = {'py2exe': {#'optimize': 2,
167 'bundle_files': 1,
168 'compressed': True,
169 'excludes': self.exclude_modules,
170 'packages': self.extra_modules,
171 'dll_excludes': self.exclude_dll}
172 },
173 zipfile = self.zipfile_name,
174 data_files = self.data_files,
175 dist_dir = self.dist_dir
176 )
177
178 #if os.path.isdir('build'): #Clean up build dir
179 # shutil.rmtree('build')
180
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