My favorites | Sign in
Project Logo
                
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
116
117
118
119
120
121
122
123
124
125
126
127
128
# RunMeToCreatePackage.py
# Version 0.2
# 2007/04/11
#
# This program was created by Clint (HanClinto) Herron for the April 2007 PyWeek competition.
# J-1 merged it with Pyweek's Skellington's setup.py script to make it handle subdirectories correctly.
# The data is now handled separately from py2exe.
#
# It packages up basic games created with the Skellington app as EXE files.
# It requires that py2exe be installed on your system.
# Simply run this script, and it will take care of the rest.
#
# This source program is released into the public domain

from distutils.core import setup
import py2exe
import sys
import glob
import shutil
import os

# utility for adding subdirectories
def add_files(dest,generator):
for dirpath, dirnames, filenames in generator:
for name in 'CVS', '.svn':
if name in dirnames:
dirnames.remove(name)

for name in filenames + dirnames:
if '~' in name: continue
suffix = os.path.splitext(name)[1]
if suffix in ('.pyc', '.pyo'): continue
if name[0] == '.': continue
filename = os.path.join(dirpath, name)
dest.append(filename)

# define what is our data
data = []
add_files(data,os.walk(os.path.join("..","data")))

#data.extend(glob.glob('*'))

print "ATTENTION: THIS SCRIPT MUST BE RUN FROM WITHIN THE LIB DIRECTORY" # If someone would like to change this fact, I'm open to suggestions for the best way to do it.
print ""
print "INTRODUCTION:"
print "This program packages up basic games created with the Skellington framework."
print "It works on my machine for my game,"
print "but I can't guarantee that it will work on yours for yours."
print "Py2exe generally does a great job of automatically packaging dependencies,"
print "but I can't guarantee you won't need to tweak with all of this."
print "Still, I hope this give you a good push in the right direction.\n"

# First step is to create a temporary launcher file, similar to the run_game.py file, that has the name of the EXE that they wish to create. This is a workaround to a problem where EXEs created with py2exe cannot be renamed to anything other than that which they were originally created with (or else they won't run properly). I don't know of the proper py2exe option to fix this.

program_listing = "#This is an automatically generated file that can be deleted\nimport main\nmain.main()" # The basics needed to run a game packaged with the skellington
filename = 'gvp.py' # The name of the temporary launcher script to create

filename = raw_input("What is the name of the executable that you wish to create (example: BubbleKong.exe or Slacker.exe) ? ")
package_name = filename.replace(".exe", "") # Remove .exe from the end of the file (if it was added at all)
filename = package_name + ".py" # Add .py to the end so that we can create this as a script file

print "\nCreating our launcher script file '" + filename + "'\n"

FILE = open(filename,"w")
FILE.write(program_listing)
FILE.close()

# Now that we have our script file, we add command line arguments to execute py2exe with the proper bundle options
sys.argv.append("py2exe")
sys.argv.append("--bundle")
sys.argv.append("2")

con_win_choice = 0
print "Do you want to build (1) an app with a visible console, or (2) a Windows app with no visible console?"

while (con_win_choice < 1 or con_win_choice > 2):
con_win_choice = input("Please enter either 1 or 2: ")

if (con_win_choice == 1): # If they chose a console...
setup(
console=[filename],
zipfile=None,
dist_dir=package_name,
#data_files=[ ("data", data),
# (".", glob.glob("../README.txt"))]
)
else: # If they chose to create a Windows app...
setup(
windows=[
{
"script": filename,
"icon_resources": [(1, "py.ico")]
}
],
zipfile=None,
dist_dir=package_name,
#data_files=[ ("data", data,)
# (".", glob.glob("../README.txt"))]
)

# recursively make a bunch of folders
def make_dirs(dname_):
parts = list(os.path.split(dname_))
dname = None
while len(parts):
if dname == None:
dname = parts.pop(0)
else:
dname = os.path.join(dname,parts.pop(0))
if not os.path.isdir(dname):
os.mkdir(dname)

# copy data into the binaries
dest = os.path.join('dist','data')

for fname in data:
dname = os.path.join(dest,os.path.dirname(fname))
make_dirs(dname)
if not os.path.isdir(fname):
shutil.copy(fname,dname)


print "\n\nThe game has now been built."
print "If there were any errors, they will be in the listing above."
print "Assuming you followed the basic Skellington model,"
print "your game and everything it needs will now be in the /lib/dist directory."
print "Rename the dist directory to be what you want, then zip it up, and publish it."
print "Enjoy!"
Show details Hide details

Change log

r181 by jmickelin on Jul 26, 2008   Diff
Cleaned up directory structure,
simplifying multiple
project on the same server. Only put
pyweek games here,
please.
Go to: 
Project members, sign in to write a code review

Older revisions

r178 by jmickelin on Apr 26, 2008   Diff
Incorporated HanClinto's auto-exe to
main branch, and
modified it to support subdirectories.
A Windows binary
can now be created by running
...
All revisions of this file

File info

Size: 5329 bytes, 128 lines
Hosted by Google Code