Bizarrerie Windows : il n'arrive pas à virer un fichier immédiatement après lui avoir...
[minwii.git] / setup_win_exe.py
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.
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 def findMinwiiDir() :
48 import minwii
49 return os.path.dirname(minwii.__file__)
50
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')
59
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()))
65
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)
70
71 if not os.path.exists(dest) :
72 self.mkpath(dest)
73
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))
79
80 for file in files :
81 s = os.path.join(path, file)
82 d = os.path.join(dest, relpath, file)
83 self.copy_file(s, d)
84 print os.path.join(reldest, relpath, file)
85 self.compiled_files.append(os.path.join(reldest, relpath, file))
86
87
88 class BuildExe:
89 def __init__(self):
90 #Name of starting .py
91 #self.script = "src/minwii/runminwii.py"
92
93 #Name of program
94 self.project_name = "MINWii"
95
96 #Project url
97 self.project_url = "about:none"
98
99 #Version of program
100 self.project_version = "1.0"
101
102 #License of the program
103 self.license = "GPL"
104
105 #Auhor of program
106 self.author_name = "Samuel Benveniste"
107 self.author_email = "samuel.benveniste@gmail.com"
108 self.copyright = "Copyright 2010 MINES-ParisTech"
109
110 #Description
111 self.project_description = "Musicothérapie Interractive avec la Wiimote"
112
113 #Icon file (None will use pygame default icon)
114 self.icon_file = 'minwii.ico'
115
116 self.data_files = []
117
118 #Extra/excludes python modules
119 self.extra_modules = []
120 self.exclude_modules = []
121
122 #DLL Excludes
123 self.exclude_dll = ['']
124
125 #Zip file name (None will bundle files in exe instead of zip file)
126 self.zipfile_name = 'minwii_lib.zip'
127
128 #Dist directory
129 self.dist_dir ='dist'
130
131
132 def run(self):
133 if os.path.isdir(self.dist_dir): #Erase previous destination dir
134 shutil.rmtree(self.dist_dir)
135
136 if os.path.isdir('build'): #Clean up build dir
137 shutil.rmtree('build')
138
139
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')
144
145
146 setup(
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,
155
156 # targets to build
157 windows = [{
158 'script': "src/minwii/runminwii.py",
159 'icon_resources': [(0, self.icon_file)],
160 'copyright': self.copyright
161 },
162 {
163 'script' : "src/minwii/logapp.py",
164 'icon_resources': [(0, 'logapp.ico')],
165 'copyright' : self.copyright
166 }
167 ],
168 #console = ["src/minwii/logapp.py"],
169 options = {'py2exe': {'optimize': 2,
170 'bundle_files': 3,
171 #'compressed': True,
172 #'excludes': self.exclude_modules,
173 #'packages': self.extra_modules,
174 #'dll_excludes': self.exclude_dll,
175 'skip_archive' : True
176 }
177 },
178 zipfile = self.zipfile_name,
179 data_files = self.data_files,
180 dist_dir = self.dist_dir
181 )
182
183 #if os.path.isdir('build'): #Clean up build dir
184 # shutil.rmtree('build')
185
186 if __name__ == '__main__':
187 if operator.lt(len(sys.argv), 2):
188 sys.argv.append('py2exe')
189 BuildExe().run() #Run generation
190 #raw_input("Press any key to continue") #Pause to let user see that things ends