2002-08-12 17:30:02 -04:00
|
|
|
#----------------------------------------------------------------------
|
2002-08-26 21:11:04 -04:00
|
|
|
# Name: CreateMacScripts.py
|
2004-01-17 18:20:49 -05:00
|
|
|
# Purpose: Massages the scripts to be usable with MacPython-OSX
|
2002-08-12 17:30:02 -04:00
|
|
|
#
|
|
|
|
# Author: Robin Dunn
|
|
|
|
#
|
|
|
|
# Created: 12-Aug-2002
|
|
|
|
# Copyright: (c) 2002 by Total Control Software
|
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
import sys, os
|
|
|
|
|
|
|
|
python = sys.executable
|
|
|
|
destdir = os.path.split(python)[0]
|
2003-03-25 01:35:27 -05:00
|
|
|
prefix = destdir
|
2002-08-12 17:30:02 -04:00
|
|
|
pythonw = os.path.join(destdir, 'pythonw')
|
|
|
|
scriptdir = os.getcwd()
|
|
|
|
|
2002-08-26 21:11:04 -04:00
|
|
|
if len(sys.argv) > 1:
|
2003-03-25 01:35:27 -05:00
|
|
|
root = sys.argv[1]
|
|
|
|
p = prefix = sys.argv[2]
|
|
|
|
if p[0] == '/': p = p[1:]
|
|
|
|
destdir = os.path.join(root, p)
|
|
|
|
|
2002-08-26 21:11:04 -04:00
|
|
|
|
2002-08-12 17:30:02 -04:00
|
|
|
from CreateBatchFiles import scripts
|
|
|
|
repltxt = "#!/usr/bin/env python"
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
# use the existing pythonw as a template
|
2006-07-05 01:23:28 -04:00
|
|
|
gui_template = """
|
|
|
|
#!/bin/sh
|
|
|
|
exec "%s" %%s.py "$@"
|
|
|
|
""" % (sys.executable)
|
2002-08-12 17:30:02 -04:00
|
|
|
|
|
|
|
def main():
|
|
|
|
for script, usegui in scripts:
|
|
|
|
destfile = os.path.join(destdir, script)
|
2003-03-25 01:35:27 -05:00
|
|
|
prefixfile = os.path.join(prefix, script)
|
|
|
|
|
2002-08-12 17:30:02 -04:00
|
|
|
thescript = open(script).read()
|
|
|
|
if usegui:
|
|
|
|
f = open(destfile+'.py', 'w')
|
2002-08-26 21:11:04 -04:00
|
|
|
print destfile+'.py'
|
2002-08-12 17:30:02 -04:00
|
|
|
f.write(thescript.replace(repltxt, ''))
|
|
|
|
f.close()
|
|
|
|
f = open(destfile, 'w')
|
2002-08-26 21:11:04 -04:00
|
|
|
print destfile
|
2003-03-25 01:35:27 -05:00
|
|
|
f.write(gui_template % prefixfile)
|
2002-08-12 17:30:02 -04:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
else:
|
|
|
|
thescript = thescript.replace(repltxt, '#!'+python)
|
|
|
|
f = open(destfile, 'w')
|
2002-08-26 21:11:04 -04:00
|
|
|
print destfile
|
2002-08-12 17:30:02 -04:00
|
|
|
f.write(thescript)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
os.chmod(destfile, 0755)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|