mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-19 05:06:25 -04:00
Removed carriage returns
This commit is contained in:
parent
61639a1ef9
commit
3fd05b7521
@ -1,253 +1,253 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# packpanda - this is a tool that packages up a panda game into a
|
# packpanda - this is a tool that packages up a panda game into a
|
||||||
# convenient, easily-downloaded windows executable. Packpanda relies on
|
# convenient, easily-downloaded windows executable. Packpanda relies on
|
||||||
# NSIS, the netscape scriptable install system, to do the hard work.
|
# NSIS, the netscape scriptable install system, to do the hard work.
|
||||||
#
|
#
|
||||||
# This is intentionally a very simplistic game-packer with very
|
# This is intentionally a very simplistic game-packer with very
|
||||||
# limited options. The goal is simplicity, not feature richness.
|
# limited options. The goal is simplicity, not feature richness.
|
||||||
# There are dozens of complex, powerful packaging tools already out
|
# There are dozens of complex, powerful packaging tools already out
|
||||||
# there. This one is for people who just want to do it quick and
|
# there. This one is for people who just want to do it quick and
|
||||||
# easy.
|
# easy.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import sys,os,getopt,string,shutil,py_compile
|
import sys,os,getopt,string,shutil,py_compile
|
||||||
|
|
||||||
OPTIONLIST = [
|
OPTIONLIST = [
|
||||||
("game", 1, "Name of directory containing game"),
|
("game", 1, "Name of directory containing game"),
|
||||||
("version", 1, "Version number to add to game name"),
|
("version", 1, "Version number to add to game name"),
|
||||||
("rmdir", 2, "Delete all directories with given name"),
|
("rmdir", 2, "Delete all directories with given name"),
|
||||||
("rmext", 2, "Delete all files with given extension"),
|
("rmext", 2, "Delete all files with given extension"),
|
||||||
("fast", 0, "Use fast compression instead of good compression"),
|
("fast", 0, "Use fast compression instead of good compression"),
|
||||||
("bam", 0, "Generate BAM files"),
|
("bam", 0, "Generate BAM files"),
|
||||||
("pyc", 0, "Generate PYC files"),
|
("pyc", 0, "Generate PYC files"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def ParseFailure():
|
def ParseFailure():
|
||||||
print ""
|
print ""
|
||||||
print "packpanda usage:"
|
print "packpanda usage:"
|
||||||
print ""
|
print ""
|
||||||
for (opt, hasval, explanation) in OPTIONLIST:
|
for (opt, hasval, explanation) in OPTIONLIST:
|
||||||
if (hasval):
|
if (hasval):
|
||||||
print " --%-10s %s"%(opt+" x",explanation)
|
print " --%-10s %s"%(opt+" x",explanation)
|
||||||
else:
|
else:
|
||||||
print " --%-10s %s"%(opt+" ",explanation)
|
print " --%-10s %s"%(opt+" ",explanation)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def ParseOptions(args):
|
def ParseOptions(args):
|
||||||
try:
|
try:
|
||||||
options = {}
|
options = {}
|
||||||
longopts = []
|
longopts = []
|
||||||
for (opt, hasval, explanation) in OPTIONLIST:
|
for (opt, hasval, explanation) in OPTIONLIST:
|
||||||
if (hasval==2):
|
if (hasval==2):
|
||||||
longopts.append(opt+"=")
|
longopts.append(opt+"=")
|
||||||
options[opt] = []
|
options[opt] = []
|
||||||
elif (hasval==1):
|
elif (hasval==1):
|
||||||
longopts.append(opt+"=")
|
longopts.append(opt+"=")
|
||||||
options[opt] = ""
|
options[opt] = ""
|
||||||
else:
|
else:
|
||||||
longopts.append(opt)
|
longopts.append(opt)
|
||||||
options[opt] = 0
|
options[opt] = 0
|
||||||
opts, extras = getopt.getopt(args, "", longopts)
|
opts, extras = getopt.getopt(args, "", longopts)
|
||||||
for option,value in opts:
|
for option,value in opts:
|
||||||
for (opt, hasval, explanation) in OPTIONLIST:
|
for (opt, hasval, explanation) in OPTIONLIST:
|
||||||
if (option == "--"+opt):
|
if (option == "--"+opt):
|
||||||
if (hasval==2): options[opt].append(value)
|
if (hasval==2): options[opt].append(value)
|
||||||
elif (hasval==1): options[opt] = value
|
elif (hasval==1): options[opt] = value
|
||||||
else: options[opt] = 1
|
else: options[opt] = 1
|
||||||
return options
|
return options
|
||||||
except: ParseFailure();
|
except: ParseFailure();
|
||||||
|
|
||||||
OPTIONS = ParseOptions(sys.argv[1:])
|
OPTIONS = ParseOptions(sys.argv[1:])
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Locate the relevant trees.
|
# Locate the relevant trees.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
PANDA=None
|
PANDA=None
|
||||||
for dir in sys.path:
|
for dir in sys.path:
|
||||||
if os.path.exists(os.path.join(dir,"direct")) and os.path.exists(os.path.join(dir,"pandac")) and os.path.exists(os.path.join(dir,"python")):
|
if os.path.exists(os.path.join(dir,"direct")) and os.path.exists(os.path.join(dir,"pandac")) and os.path.exists(os.path.join(dir,"python")):
|
||||||
PANDA=os.path.abspath(dir)
|
PANDA=os.path.abspath(dir)
|
||||||
if (PANDA is None):
|
if (PANDA is None):
|
||||||
sys.exit("Cannot locate the panda root directory in the python path (cannot locate directory containing direct and pandac).")
|
sys.exit("Cannot locate the panda root directory in the python path (cannot locate directory containing direct and pandac).")
|
||||||
|
|
||||||
if (os.path.exists(os.path.join("PANDA","..","makepanda","makepanda.py"))) and (os.path.exists(os.path.join("PANDA","..","thirdparty","win-nsis","makensis.exe"))):
|
if (os.path.exists(os.path.join("PANDA","..","makepanda","makepanda.py"))) and (os.path.exists(os.path.join("PANDA","..","thirdparty","win-nsis","makensis.exe"))):
|
||||||
PSOURCE=os.path.abspath(os.path.join(PANDA,".."))
|
PSOURCE=os.path.abspath(os.path.join(PANDA,".."))
|
||||||
NSIS=os.path.abspath(os.path.join(PANDA,"..","thirdparty","win-nsis"))
|
NSIS=os.path.abspath(os.path.join(PANDA,"..","thirdparty","win-nsis"))
|
||||||
else:
|
else:
|
||||||
PSOURCE=PANDA
|
PSOURCE=PANDA
|
||||||
NSIS=os.path.join(PANDA,"nsis")
|
NSIS=os.path.join(PANDA,"nsis")
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Identify the main parts of the game: GAME, NAME, MAIN, ICON, BITMAP, etc
|
# Identify the main parts of the game: GAME, NAME, MAIN, ICON, BITMAP, etc
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
VER=OPTIONS["version"]
|
VER=OPTIONS["version"]
|
||||||
GAME=OPTIONS["game"]
|
GAME=OPTIONS["game"]
|
||||||
if (GAME==""):
|
if (GAME==""):
|
||||||
print "You must specify the --game option."
|
print "You must specify the --game option."
|
||||||
ParseFailure()
|
ParseFailure()
|
||||||
GAME=os.path.abspath(GAME)
|
GAME=os.path.abspath(GAME)
|
||||||
NAME=os.path.basename(GAME)
|
NAME=os.path.basename(GAME)
|
||||||
SMDIRECTORY=os.path.basename(GAME)
|
SMDIRECTORY=os.path.basename(GAME)
|
||||||
if (VER!=""): SMDIRECTORY=SMDIRECTORY+" "+VER
|
if (VER!=""): SMDIRECTORY=SMDIRECTORY+" "+VER
|
||||||
ICON=os.path.join(GAME,NAME+".ico")
|
ICON=os.path.join(GAME,NAME+".ico")
|
||||||
BITMAP=os.path.join(GAME,NAME+".bmp")
|
BITMAP=os.path.join(GAME,NAME+".bmp")
|
||||||
LICENSE=os.path.join(GAME,"LICENSE.TXT")
|
LICENSE=os.path.join(GAME,"LICENSE.TXT")
|
||||||
OUTFILE=os.path.basename(GAME)
|
OUTFILE=os.path.basename(GAME)
|
||||||
if (VER!=""): OUTFILE=OUTFILE+"-"+VER
|
if (VER!=""): OUTFILE=OUTFILE+"-"+VER
|
||||||
OUTFILE=os.path.abspath(OUTFILE+".exe")
|
OUTFILE=os.path.abspath(OUTFILE+".exe")
|
||||||
INSTALLDIR='C:\\'+os.path.basename(GAME)
|
INSTALLDIR='C:\\'+os.path.basename(GAME)
|
||||||
if (VER!=""): INSTALLDIR=INSTALLDIR+"-"+VER
|
if (VER!=""): INSTALLDIR=INSTALLDIR+"-"+VER
|
||||||
COMPRESS="lzma"
|
COMPRESS="lzma"
|
||||||
if (OPTIONS["fast"]): COMPRESS="zlib"
|
if (OPTIONS["fast"]): COMPRESS="zlib"
|
||||||
if (OPTIONS["pyc"]): MAIN=NAME+".pyc"
|
if (OPTIONS["pyc"]): MAIN=NAME+".pyc"
|
||||||
else: MAIN=NAME+".py"
|
else: MAIN=NAME+".py"
|
||||||
|
|
||||||
def PrintFileStatus(label, file):
|
def PrintFileStatus(label, file):
|
||||||
if (os.path.exists(file)):
|
if (os.path.exists(file)):
|
||||||
print "%-15s: %s"%(label,file)
|
print "%-15s: %s"%(label,file)
|
||||||
else:
|
else:
|
||||||
print "%-15s: %s (MISSING)"%(label,file)
|
print "%-15s: %s (MISSING)"%(label,file)
|
||||||
|
|
||||||
PrintFileStatus("Game",GAME)
|
PrintFileStatus("Game",GAME)
|
||||||
print "%-15s: %s"%("Name",NAME)
|
print "%-15s: %s"%("Name",NAME)
|
||||||
print "%-15s: %s"%("Start Menu",SMDIRECTORY)
|
print "%-15s: %s"%("Start Menu",SMDIRECTORY)
|
||||||
PrintFileStatus("Main",os.path.join(GAME,MAIN))
|
PrintFileStatus("Main",os.path.join(GAME,MAIN))
|
||||||
PrintFileStatus("Icon",ICON)
|
PrintFileStatus("Icon",ICON)
|
||||||
PrintFileStatus("Bitmap",BITMAP)
|
PrintFileStatus("Bitmap",BITMAP)
|
||||||
PrintFileStatus("License",LICENSE)
|
PrintFileStatus("License",LICENSE)
|
||||||
print "%-15s: %s"%("Output",OUTFILE)
|
print "%-15s: %s"%("Output",OUTFILE)
|
||||||
print "%-15s: %s"%("Install Dir",INSTALLDIR)
|
print "%-15s: %s"%("Install Dir",INSTALLDIR)
|
||||||
|
|
||||||
if (os.path.isdir(GAME)==0):
|
if (os.path.isdir(GAME)==0):
|
||||||
sys.exit("Difficulty reading "+GAME+". Cannot continue.")
|
sys.exit("Difficulty reading "+GAME+". Cannot continue.")
|
||||||
|
|
||||||
if (os.path.isfile(os.path.join(GAME,NAME+".py"))==0):
|
if (os.path.isfile(os.path.join(GAME,NAME+".py"))==0):
|
||||||
sys.exit("Difficulty reading "+NAME+".py. Cannot continue.")
|
sys.exit("Difficulty reading "+NAME+".py. Cannot continue.")
|
||||||
|
|
||||||
if (os.path.isfile(LICENSE)==0):
|
if (os.path.isfile(LICENSE)==0):
|
||||||
LICENSE=os.path.join(PANDA,"LICENSE")
|
LICENSE=os.path.join(PANDA,"LICENSE")
|
||||||
|
|
||||||
if (os.path.isfile(BITMAP)==0):
|
if (os.path.isfile(BITMAP)==0):
|
||||||
BITMAP=os.path.join(NSIS,"Contrib","Modern UI","Graphics","Wizard","nsis.bmp")
|
BITMAP=os.path.join(NSIS,"Contrib","Modern UI","Graphics","Wizard","nsis.bmp")
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copy the game to a temporary directory, so we can modify it safely.
|
# Copy the game to a temporary directory, so we can modify it safely.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
TMPDIR=os.path.abspath("packpanda-TMP")
|
TMPDIR=os.path.abspath("packpanda-TMP")
|
||||||
print ""
|
print ""
|
||||||
print "Copying the game to "+TMPDIR+"..."
|
print "Copying the game to "+TMPDIR+"..."
|
||||||
if (os.path.exists(TMPDIR)):
|
if (os.path.exists(TMPDIR)):
|
||||||
try: shutil.rmtree(TMPDIR)
|
try: shutil.rmtree(TMPDIR)
|
||||||
except: sys.exit("Cannot delete "+TMPDIR)
|
except: sys.exit("Cannot delete "+TMPDIR)
|
||||||
try: shutil.copytree(GAME, TMPDIR)
|
try: shutil.copytree(GAME, TMPDIR)
|
||||||
except: sys.exit("Cannot copy game to "+TMPDIR)
|
except: sys.exit("Cannot copy game to "+TMPDIR)
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Compile all py files, convert all egg files.
|
# Compile all py files, convert all egg files.
|
||||||
#
|
#
|
||||||
# We do this as a sanity check, even if the user
|
# We do this as a sanity check, even if the user
|
||||||
# hasn't requested that his files be compiled.
|
# hasn't requested that his files be compiled.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
EGG2BAM=os.path.join(PANDA,"bin","egg2bam.exe")
|
EGG2BAM=os.path.join(PANDA,"bin","egg2bam.exe")
|
||||||
|
|
||||||
def egg2bam(file):
|
def egg2bam(file):
|
||||||
bam = file[:-4]+'.bam'
|
bam = file[:-4]+'.bam'
|
||||||
present = os.path.exists(bam)
|
present = os.path.exists(bam)
|
||||||
if (present): bam = "packpanda-TMP.bam";
|
if (present): bam = "packpanda-TMP.bam";
|
||||||
cmd = 'egg2bam -noabs -ps rel -pd . "'+file+'" -o "'+bam+'"'
|
cmd = 'egg2bam -noabs -ps rel -pd . "'+file+'" -o "'+bam+'"'
|
||||||
print "Executing: "+cmd
|
print "Executing: "+cmd
|
||||||
res = os.spawnl(os.P_WAIT, EGG2BAM, cmd)
|
res = os.spawnl(os.P_WAIT, EGG2BAM, cmd)
|
||||||
if (res != 0): sys.exit("Problem in egg file: "+file)
|
if (res != 0): sys.exit("Problem in egg file: "+file)
|
||||||
if (present) or (OPTIONS["bam"]==0):
|
if (present) or (OPTIONS["bam"]==0):
|
||||||
os.unlink(bam)
|
os.unlink(bam)
|
||||||
|
|
||||||
def py2pyc(file):
|
def py2pyc(file):
|
||||||
print "Compiling python "+file
|
print "Compiling python "+file
|
||||||
pyc = file[:-3]+'.pyc'
|
pyc = file[:-3]+'.pyc'
|
||||||
pyo = file[:-3]+'.pyo'
|
pyo = file[:-3]+'.pyo'
|
||||||
if (os.path.exists(pyc)): os.unlink(pyc)
|
if (os.path.exists(pyc)): os.unlink(pyc)
|
||||||
if (os.path.exists(pyo)): os.unlink(pyo)
|
if (os.path.exists(pyo)): os.unlink(pyo)
|
||||||
try: py_compile.compile(file)
|
try: py_compile.compile(file)
|
||||||
except: sys.exit("Cannot compile "+file)
|
except: sys.exit("Cannot compile "+file)
|
||||||
if (OPTIONS["pyc"]==0):
|
if (OPTIONS["pyc"]==0):
|
||||||
if (os.path.exists(pyc)):
|
if (os.path.exists(pyc)):
|
||||||
os.unlink(pyc)
|
os.unlink(pyc)
|
||||||
if (os.path.exists(pyo)):
|
if (os.path.exists(pyo)):
|
||||||
os.unlink(pyo)
|
os.unlink(pyo)
|
||||||
|
|
||||||
def CompileFiles(file):
|
def CompileFiles(file):
|
||||||
if (os.path.isfile(file)):
|
if (os.path.isfile(file)):
|
||||||
if (string.lower(file[-4:])==".egg"):
|
if (string.lower(file[-4:])==".egg"):
|
||||||
egg2bam(file)
|
egg2bam(file)
|
||||||
elif (string.lower(file[-3:])==".py"):
|
elif (string.lower(file[-3:])==".py"):
|
||||||
py2pyc(file)
|
py2pyc(file)
|
||||||
else: pass
|
else: pass
|
||||||
elif (os.path.isdir(file)):
|
elif (os.path.isdir(file)):
|
||||||
for x in os.listdir(file):
|
for x in os.listdir(file):
|
||||||
CompileFiles(os.path.join(file,x))
|
CompileFiles(os.path.join(file,x))
|
||||||
|
|
||||||
def DeleteFiles(file):
|
def DeleteFiles(file):
|
||||||
base = string.lower(os.path.basename(file))
|
base = string.lower(os.path.basename(file))
|
||||||
if (os.path.isdir(file)):
|
if (os.path.isdir(file)):
|
||||||
for pattern in OPTIONS["rmdir"]:
|
for pattern in OPTIONS["rmdir"]:
|
||||||
if (string.lower(pattern) == base):
|
if (string.lower(pattern) == base):
|
||||||
print "Deleting "+file
|
print "Deleting "+file
|
||||||
shutil.rmtree(file)
|
shutil.rmtree(file)
|
||||||
return
|
return
|
||||||
for x in os.listdir(file):
|
for x in os.listdir(file):
|
||||||
DeleteFiles(os.path.join(file,x))
|
DeleteFiles(os.path.join(file,x))
|
||||||
else:
|
else:
|
||||||
for ext in OPTIONS["rmext"]:
|
for ext in OPTIONS["rmext"]:
|
||||||
if (base[-(len(ext)+1):] == string.lower("."+ext)):
|
if (base[-(len(ext)+1):] == string.lower("."+ext)):
|
||||||
print "Deleting "+file
|
print "Deleting "+file
|
||||||
os.unlink(file)
|
os.unlink(file)
|
||||||
return
|
return
|
||||||
|
|
||||||
print ""
|
print ""
|
||||||
print "Compiling BAM and PYC files..."
|
print "Compiling BAM and PYC files..."
|
||||||
os.chdir(TMPDIR)
|
os.chdir(TMPDIR)
|
||||||
CompileFiles(".")
|
CompileFiles(".")
|
||||||
DeleteFiles(".")
|
DeleteFiles(".")
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Run NSIS. Yay!
|
# Run NSIS. Yay!
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
CMD=NSIS+"\\makensis.exe /V2 "
|
CMD=NSIS+"\\makensis.exe /V2 "
|
||||||
CMD=CMD+'/DCOMPRESSOR="'+COMPRESS+'" '
|
CMD=CMD+'/DCOMPRESSOR="'+COMPRESS+'" '
|
||||||
CMD=CMD+'/DNAME="'+NAME+'" '
|
CMD=CMD+'/DNAME="'+NAME+'" '
|
||||||
CMD=CMD+'/DSMDIRECTORY="'+SMDIRECTORY+'" '
|
CMD=CMD+'/DSMDIRECTORY="'+SMDIRECTORY+'" '
|
||||||
CMD=CMD+'/DINSTALLDIR="'+INSTALLDIR+'" '
|
CMD=CMD+'/DINSTALLDIR="'+INSTALLDIR+'" '
|
||||||
CMD=CMD+'/DOUTFILE="'+OUTFILE+'" '
|
CMD=CMD+'/DOUTFILE="'+OUTFILE+'" '
|
||||||
CMD=CMD+'/DLICENSE="'+LICENSE+'" '
|
CMD=CMD+'/DLICENSE="'+LICENSE+'" '
|
||||||
CMD=CMD+'/DLANGUAGE="English" '
|
CMD=CMD+'/DLANGUAGE="English" '
|
||||||
CMD=CMD+'/DRUNTEXT="Play '+NAME+'" '
|
CMD=CMD+'/DRUNTEXT="Play '+NAME+'" '
|
||||||
CMD=CMD+'/DIBITMAP="'+BITMAP+'" '
|
CMD=CMD+'/DIBITMAP="'+BITMAP+'" '
|
||||||
CMD=CMD+'/DUBITMAP="'+BITMAP+'" '
|
CMD=CMD+'/DUBITMAP="'+BITMAP+'" '
|
||||||
CMD=CMD+'/DPANDA="'+PANDA+'" '
|
CMD=CMD+'/DPANDA="'+PANDA+'" '
|
||||||
CMD=CMD+'/DPSOURCE="'+PSOURCE+'" '
|
CMD=CMD+'/DPSOURCE="'+PSOURCE+'" '
|
||||||
CMD=CMD+'/DPPGAME="'+TMPDIR+'" '
|
CMD=CMD+'/DPPGAME="'+TMPDIR+'" '
|
||||||
CMD=CMD+'/DPPMAIN="'+MAIN+'" '
|
CMD=CMD+'/DPPMAIN="'+MAIN+'" '
|
||||||
CMD=CMD+'"'+PSOURCE+'\\direct\\src\\directscripts\\packpanda.nsi"'
|
CMD=CMD+'"'+PSOURCE+'\\direct\\src\\directscripts\\packpanda.nsi"'
|
||||||
|
|
||||||
print ""
|
print ""
|
||||||
print CMD
|
print CMD
|
||||||
print "packing..."
|
print "packing..."
|
||||||
os.system(CMD)
|
os.system(CMD)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user