]>
Commit | Line | Data |
---|---|---|
2eb31f8b | 1 | #---------------------------------------------------------------------- |
9c6b4824 | 2 | # Name: CreateMacScripts.py |
46456f61 | 3 | # Purpose: Massages the scripts to be usable with MacPython-OSX |
2eb31f8b RD |
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] | |
1e4a197e | 16 | prefix = destdir |
2eb31f8b RD |
17 | pythonw = os.path.join(destdir, 'pythonw') |
18 | scriptdir = os.getcwd() | |
19 | ||
9c6b4824 | 20 | if len(sys.argv) > 1: |
1e4a197e RD |
21 | root = sys.argv[1] |
22 | p = prefix = sys.argv[2] | |
23 | if p[0] == '/': p = p[1:] | |
24 | destdir = os.path.join(root, p) | |
25 | ||
9c6b4824 | 26 | |
2eb31f8b RD |
27 | from CreateBatchFiles import scripts |
28 | repltxt = "#!/usr/bin/env python" | |
29 | ||
1e4a197e | 30 | # use the existing pythonw as a template |
0f475e8a RD |
31 | gui_template = """ |
32 | #!/bin/sh | |
33 | exec "%s" %%s.py "$@" | |
34 | """ % (sys.executable) | |
2eb31f8b RD |
35 | |
36 | def main(): | |
37 | for script, usegui in scripts: | |
38 | destfile = os.path.join(destdir, script) | |
1e4a197e RD |
39 | prefixfile = os.path.join(prefix, script) |
40 | ||
2eb31f8b RD |
41 | thescript = open(script).read() |
42 | if usegui: | |
43 | f = open(destfile+'.py', 'w') | |
9c6b4824 | 44 | print destfile+'.py' |
2eb31f8b RD |
45 | f.write(thescript.replace(repltxt, '')) |
46 | f.close() | |
47 | f = open(destfile, 'w') | |
9c6b4824 | 48 | print destfile |
1e4a197e | 49 | f.write(gui_template % prefixfile) |
2eb31f8b RD |
50 | f.close() |
51 | ||
52 | else: | |
53 | thescript = thescript.replace(repltxt, '#!'+python) | |
54 | f = open(destfile, 'w') | |
9c6b4824 | 55 | print destfile |
2eb31f8b RD |
56 | f.write(thescript) |
57 | f.close() | |
58 | ||
59 | os.chmod(destfile, 0755) | |
60 | ||
61 | ||
62 | if __name__ == '__main__': | |
63 | main() | |
64 |