Utilisation du format .ico historique.
[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 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 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())
90 #
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)
94
95 class BuildExe:
96 def __init__(self):
97 #Name of starting .py
98 self.script = "src/minwii/start_win.py"
99
100 #Name of program
101 self.project_name = "MINWii"
102
103 #Project url
104 self.project_url = "about:none"
105
106 #Version of program
107 self.project_version = "0.0"
108
109 #License of the program
110 self.license = "GPL"
111
112 #Auhor of program
113 self.author_name = "Samuel Benveniste"
114 self.author_email = "samuel.benveniste@gmail.com"
115 self.copyright = "Copyright 2010 MINES-ParisTech"
116
117 #Description
118 self.project_description = "Musicothérapie Interractive avec la Wii"
119
120 #Icon file (None will use pygame default icon)
121 self.icon_file = None
122
123 #Extra files/dirs copied to game
124 #self.data_files = [('minwii/fonts',
125 # glob.glob('src/minwii/fonts/*.ttf'))]
126
127 #Extra/excludes python modules
128 self.extra_modules = []
129 self.exclude_modules = []
130
131 #DLL Excludes
132 self.exclude_dll = ['']
133
134 #Zip file name (None will bundle files in exe instead of zip file)
135 self.zipfile_name = 'minwii_lib.zip'
136
137 #Dist directory
138 self.dist_dir ='dist'
139
140
141 def run(self):
142 if os.path.isdir(self.dist_dir): #Erase previous destination dir
143 shutil.rmtree(self.dist_dir)
144
145 if os.path.isdir('build'): #Clean up build dir
146 shutil.rmtree('build')
147
148
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')
153
154
155 setup(
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,
164
165 # targets to build
166 windows = [{
167 'script': self.script,
168 'icon_resources': [(0, self.icon_file)],
169 'copyright': self.copyright
170 }],
171 #console = [self.script],
172 options = {'py2exe': {#'optimize': 2,
173 #'bundle_files': 1,
174 #'compressed': True,
175 #'excludes': self.exclude_modules,
176 #'packages': self.extra_modules,
177 #'dll_excludes': self.exclude_dll,
178 'skip_archive' : True}
179 },
180 zipfile = self.zipfile_name,
181 data_files = self.data_files,
182 dist_dir = self.dist_dir
183 )
184
185 #if os.path.isdir('build'): #Clean up build dir
186 # shutil.rmtree('build')
187
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