-
Notifications
You must be signed in to change notification settings - Fork 0
/
PySetup.py
115 lines (95 loc) · 3.71 KB
/
PySetup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /usr/bin/env python
# Some of this script is from Pete Shinners pygame2exe script.
# (data copying and pygame icon code)
# import modules
from distutils.core import setup
import sys, os, shutil, pygame
import py2exe
#########################
### Variables to edit ###
#########################
script = "snakegame.py" # Starting .py or .pyw script
dest_file = "snakegame" # Final name of .exe file
dest_folder = "snakegame" # Final folder to contain the executable, data files, etc.
icon_file = "" # Icon file. Leave blank for the pygame icon.
extra_data = ['img'] # Extra data to copy to the final folder
extra_modules = [] # Extra modules to be included in the .exe (leave empty if no extra modules)
dll_excludes = [] # excluded dlls ["w9xpopen.exe", "msvcr71.dll"]
pygamedir = os.path.split(pygame.base.__file__)[0]
extra_data.append(os.path.join(pygamedir, 'freesansbold.ttf'))
extra_data.append(os.path.join(pygamedir, 'SDL.dll'))
extra_data.append(os.path.join(pygamedir, 'SDL_ttf.dll'))
extra_data.append(os.path.join(pygamedir, 'libfreetype-6.dll'))
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
if os.path.basename(pathname).lower() in ["sdl_ttf.dll"]:
return 0
return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
#Libraries to exclude from the EXE (use to cut down the final EXE filesize.)
lib_excludes = ["Tkinter", "tcl", "OpenGL", "Numeric", "numpy", "wxPython", "pyglet"]
# Stuff to show who made it, etc.
copyright = "Copyright (C) 20XX"
author = "Your Name Here"
company = None
version = "X.X"
###################################################################
### Do not edit below here, unless you just want to experiment. ###
###################################################################
# Run the script if no commands are supplied
if len(sys.argv) == 1:
sys.argv.append("py2exe")
sys.argv.append("-q")
# Use the pygame icon if there's no icon designated
if icon_file is '':
path = os.path.split(pygame.__file__)[0]
icon_file = '' + os.path.join(path, 'pygame.ico')
# Copy extra data files
def installfile(name):
dst = os.path.join(dest_folder)
print 'copying', name, '->', dst
if os.path.isdir(name):
dst = os.path.join(dst, name)
if os.path.isdir(dst):
shutil.rmtree(dst)
shutil.copytree(name, dst)
elif os.path.isfile(name):
shutil.copy(name, dst)
else:
print 'Warning, %s not found' % name
##############################
### Distutils setup script ###
##############################
# Set some variables for the exe
class Target:
def __init__(self, **kw):
self.__dict__.update(kw)
self.version = version
self.company_name = company
self.author = author
self.copyright = copyright
self.name = dest_file
# Set some more variables for the exe
target = Target(
script = script,
icon_resources = [(1, icon_file)],
dest_base = dest_file,
extra_modules = extra_modules
)
# Run the setup script!
setup(
options = {"py2exe": {"compressed": 1,
"optimize": 2,
"bundle_files": 1,
"dll_excludes": dll_excludes,
"dist_dir": dest_folder,
"excludes": lib_excludes}},
zipfile = None,
windows = [target],
)
# install extra data files
print '\n' # Just a space to make it look nicer :)
for d in extra_data:
installfile(d)
# If everything went okay, this should come up.
raw_input('\n\n\nConversion successful! Press enter to exit')