| 1 | #---------------------------------------------------------------------- |
| 2 | # Name: CreateMacScripts.py |
| 3 | # Purpose: Massages the scripts to be usable with MachoPython |
| 4 | # |
| 5 | # Author: Robin Dunn |
| 6 | # |
| 7 | # Created: 12-Aug-2002 |
| 8 | # Copyright: (c) 2002 by Total Control Software |
| 9 | # Licence: wxWindows license |
| 10 | #---------------------------------------------------------------------- |
| 11 | |
| 12 | import sys, os |
| 13 | |
| 14 | python = sys.executable |
| 15 | destdir = os.path.split(python)[0] |
| 16 | pythonw = os.path.join(destdir, 'pythonw') |
| 17 | scriptdir = os.getcwd() |
| 18 | |
| 19 | if len(sys.argv) > 1: |
| 20 | destdir = sys.argv[1] |
| 21 | |
| 22 | from CreateBatchFiles import scripts |
| 23 | repltxt = "#!/usr/bin/env python" |
| 24 | |
| 25 | gui_template = """\ |
| 26 | #!/bin/sh |
| 27 | exec /Applications/Python.app/Contents/MacOS/python %s.py |
| 28 | """ |
| 29 | |
| 30 | def main(): |
| 31 | for script, usegui in scripts: |
| 32 | destfile = os.path.join(destdir, script) |
| 33 | thescript = open(script).read() |
| 34 | if usegui: |
| 35 | f = open(destfile+'.py', 'w') |
| 36 | print destfile+'.py' |
| 37 | f.write(thescript.replace(repltxt, '')) |
| 38 | f.close() |
| 39 | f = open(destfile, 'w') |
| 40 | print destfile |
| 41 | f.write(gui_template % destfile) |
| 42 | f.close() |
| 43 | |
| 44 | else: |
| 45 | thescript = thescript.replace(repltxt, '#!'+python) |
| 46 | f = open(destfile, 'w') |
| 47 | print destfile |
| 48 | f.write(thescript) |
| 49 | f.close() |
| 50 | |
| 51 | os.chmod(destfile, 0755) |
| 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | main() |
| 56 | |