From 8f2b13efce66d1ce66060d55f26753d0e593d19f Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Mon, 27 Aug 2001 21:17:44 +0000 Subject: These have long outlived there usefulness, in my opinion. Moved to Unsupported. --- Mac/Unsupported/PackLibDir.py | 49 +++++++++++++++++ Mac/Unsupported/PackLibDir.rsrc | Bin 0 -> 3038 bytes Mac/Unsupported/RunLibScript.py | 111 ++++++++++++++++++++++++++++++++++++++ Mac/Unsupported/RunLibScript.rsrc | Bin 0 -> 3514 bytes Mac/Unsupported/run.py | 41 ++++++++++++++ Mac/scripts/PackLibDir.py | 49 ----------------- Mac/scripts/PackLibDir.rsrc | Bin 2925 -> 0 bytes Mac/scripts/RunLibScript.py | 111 -------------------------------------- Mac/scripts/RunLibScript.rsrc | Bin 3399 -> 0 bytes Mac/scripts/run.py | 41 -------------- 10 files changed, 201 insertions(+), 201 deletions(-) create mode 100644 Mac/Unsupported/PackLibDir.py create mode 100644 Mac/Unsupported/PackLibDir.rsrc create mode 100644 Mac/Unsupported/RunLibScript.py create mode 100644 Mac/Unsupported/RunLibScript.rsrc create mode 100644 Mac/Unsupported/run.py delete mode 100644 Mac/scripts/PackLibDir.py delete mode 100644 Mac/scripts/PackLibDir.rsrc delete mode 100644 Mac/scripts/RunLibScript.py delete mode 100644 Mac/scripts/RunLibScript.rsrc delete mode 100644 Mac/scripts/run.py diff --git a/Mac/Unsupported/PackLibDir.py b/Mac/Unsupported/PackLibDir.py new file mode 100644 index 0000000..ba689e6 --- /dev/null +++ b/Mac/Unsupported/PackLibDir.py @@ -0,0 +1,49 @@ +# +# Turn a pyc file into a resource file containing it in 'PYC ' resource form +from Carbon.Res import * +from Carbon import Res +from Carbon.Resources import * +import os +import macfs +import sys +import py_resource + +error = 'mkpycresourcefile.error' + +def mkpycresourcefile(src, dst): + """Copy pyc file/dir src to resource file dst.""" + + if not os.path.isdir(src) and src[-4:] <> '.pyc': + raise error, 'I can only handle .pyc files or directories' + fsid = py_resource.create(dst) + if os.path.isdir(src): + handlesubdir(src) + else: + id, name = py_resource.frompycfile(src) + print 'Wrote %d: %s %s'%(id, name, src) + CloseResFile(fsid) + +def handlesubdir(srcdir): + """Recursively scan a directory for pyc files and copy to resources""" + src = os.listdir(srcdir) + for file in src: + file = os.path.join(srcdir, file) + if os.path.isdir(file): + handlesubdir(file) + elif file[-4:] == '.pyc': + id, name = py_resource.frompycfile(file) + print 'Wrote %d: %s %s'%(id, name, file) + +if __name__ == '__main__': + args = sys.argv[1:] + if not args: + ifss, ok = macfs.GetDirectory('Select root of tree to pack:') + if not ok: + sys.exit(0) + args = [ifss.as_pathname()] + for ifn in args: + ofss, ok = macfs.StandardPutFile('Output for '+os.path.split(ifn)[1]) + if not ok: + sys.exit(0) + mkpycresourcefile(ifn, ofss.as_pathname()) + sys.exit(1) # So we can see something... diff --git a/Mac/Unsupported/PackLibDir.rsrc b/Mac/Unsupported/PackLibDir.rsrc new file mode 100644 index 0000000..bcdbf0b Binary files /dev/null and b/Mac/Unsupported/PackLibDir.rsrc differ diff --git a/Mac/Unsupported/RunLibScript.py b/Mac/Unsupported/RunLibScript.py new file mode 100644 index 0000000..6ecf643 --- /dev/null +++ b/Mac/Unsupported/RunLibScript.py @@ -0,0 +1,111 @@ +"""Import a module while pretending its name is __main__. This +can be used to run scripts from the PackedLib resource file while pretending +they have been double-clicked.""" + +import imp +import sys +import os +import string +from Carbon import Dlg +import macfs + +DIALOG_ID = 512 +OK = 1 +CANCEL = 2 +SCRIPTNAME=3 +ARGV=4 +STDIN_CONS=5 +STDIN_FILE=6 +STDOUT_CONS=7 +STDOUT_FILE=8 +WORKING_DIR=9 +PAUSE=10 + +def import_as_main(name): + fp, path, (suffix, mode, type) = imp.find_module(name) + if type == imp.PY_SOURCE: + imp.load_source('__main__', path, fp) + elif type == imp.PY_COMPILED: + imp.load_compiled('__main__', path, fp) + elif type == imp.PY_RESOURCE: + imp.load_resource('__main__', path) + +def interact(): + d = Dlg.GetNewDialog(DIALOG_ID, -1) + wdir = stdin = stdout = None + pause = 0 + + tp, in_c_h, rect = d.GetDialogItem(STDIN_CONS) + tp, in_f_h, rect = d.GetDialogItem(STDIN_FILE) + tp, out_c_h, rect = d.GetDialogItem(STDOUT_CONS) + tp, out_f_h, rect = d.GetDialogItem(STDOUT_FILE) + tp, pause_h, rect = d.GetDialogItem(PAUSE) + in_c_h = in_c_h.as_Control() + in_f_h = in_f_h.as_Control() + out_c_h = out_c_h.as_Control() + out_f_h = out_f_h.as_Control() + pause_h = pause_h.as_Control() + + while 1: + in_c_h.SetControlValue(not stdin) + in_f_h.SetControlValue(not not stdin) + out_c_h.SetControlValue(not stdout) + out_f_h.SetControlValue(not not stdout) + pause_h.SetControlValue(pause) + + n = Dlg.ModalDialog(None) + if n == OK: + break + elif n == CANCEL: + sys.exit(0) + elif n == STDIN_CONS: + stdin = None + elif n == STDIN_FILE: + fss, ok = macfs.StandardGetFile('TEXT') + if ok: + stdin = fss + elif n == STDOUT_FILE: + fss, ok = macfs.StandardPutFile('stdout:') + if ok: + stdout = fss + elif n == WORKING_DIR: + fss, ok = macfs.GetDirectory() + if ok: + wdir = fss + elif n == PAUSE: + pause = (not pause) + + tp, h, rect = d.GetDialogItem(SCRIPTNAME) + name = Dlg.GetDialogItemText(h) + tp, h, rect = d.GetDialogItem(ARGV) + argv = Dlg.GetDialogItemText(h) + return name, argv, stdin, stdout, wdir, pause + +def main(): + curdir = os.getcwd() + from Carbon import Res + try: + Res.FSpOpenResFile('RunLibScript.rsrc', 1) + except: + pass # Assume we're an applet already + name, argv, stdin, stdout, wdir, pause = interact() + if not name: + sys.exit(0) + sys.argv = [name] + string.split(argv) + if stdin: + sys.stdin = open(stdin.as_pathname()) + if stdout: + sys.stdout = open(stdout.as_pathname(), 'w') + if wdir: + os.chdir(wdir.as_pathname()) + else: + os.chdir(curdir) + + import_as_main(name) + + if pause: + sys.exit(1) + +if __name__ == '__main__': + main() + diff --git a/Mac/Unsupported/RunLibScript.rsrc b/Mac/Unsupported/RunLibScript.rsrc new file mode 100644 index 0000000..fea753c Binary files /dev/null and b/Mac/Unsupported/RunLibScript.rsrc differ diff --git a/Mac/Unsupported/run.py b/Mac/Unsupported/run.py new file mode 100644 index 0000000..75c6129 --- /dev/null +++ b/Mac/Unsupported/run.py @@ -0,0 +1,41 @@ +# Script (applet) to run any Python command + +def main(): + import sys + sys.stdout = sys.stderr + del sys.argv[:1] + if not sys.argv: + import macfs + srcfss, ok = macfs.StandardGetFile('TEXT') + if not ok: + return + filename = srcfss.as_pathname() + sys.argv.append(filename) + import __main__ + try: + execfile(sys.argv[0], __main__.__dict__) + except SystemExit, msg: + if msg: + message("Exit status: %s" % str(msg)) + print "exit", `msg` + #sys.exit(msg) + except: + etype = sys.exc_type + if hasattr(etype, "__name__"): etype = etype.__name__ + message("%s: %s" % (etype, sys.exc_value)) + print "exit 1" + #sys.exit(1) + +def message(str = "Hello, world!", id = 256): + from Carbon import Dlg + d = Dlg.GetNewDialog(id, -1) + if not d: + print str + return + tp, h, rect = d.GetDItem(2) + Dlg.SetIText(h, str) + while 1: + n = Dlg.ModalDialog(None) + if n == 1: break + +main() diff --git a/Mac/scripts/PackLibDir.py b/Mac/scripts/PackLibDir.py deleted file mode 100644 index ba689e6..0000000 --- a/Mac/scripts/PackLibDir.py +++ /dev/null @@ -1,49 +0,0 @@ -# -# Turn a pyc file into a resource file containing it in 'PYC ' resource form -from Carbon.Res import * -from Carbon import Res -from Carbon.Resources import * -import os -import macfs -import sys -import py_resource - -error = 'mkpycresourcefile.error' - -def mkpycresourcefile(src, dst): - """Copy pyc file/dir src to resource file dst.""" - - if not os.path.isdir(src) and src[-4:] <> '.pyc': - raise error, 'I can only handle .pyc files or directories' - fsid = py_resource.create(dst) - if os.path.isdir(src): - handlesubdir(src) - else: - id, name = py_resource.frompycfile(src) - print 'Wrote %d: %s %s'%(id, name, src) - CloseResFile(fsid) - -def handlesubdir(srcdir): - """Recursively scan a directory for pyc files and copy to resources""" - src = os.listdir(srcdir) - for file in src: - file = os.path.join(srcdir, file) - if os.path.isdir(file): - handlesubdir(file) - elif file[-4:] == '.pyc': - id, name = py_resource.frompycfile(file) - print 'Wrote %d: %s %s'%(id, name, file) - -if __name__ == '__main__': - args = sys.argv[1:] - if not args: - ifss, ok = macfs.GetDirectory('Select root of tree to pack:') - if not ok: - sys.exit(0) - args = [ifss.as_pathname()] - for ifn in args: - ofss, ok = macfs.StandardPutFile('Output for '+os.path.split(ifn)[1]) - if not ok: - sys.exit(0) - mkpycresourcefile(ifn, ofss.as_pathname()) - sys.exit(1) # So we can see something... diff --git a/Mac/scripts/PackLibDir.rsrc b/Mac/scripts/PackLibDir.rsrc deleted file mode 100644 index 7f23b93..0000000 Binary files a/Mac/scripts/PackLibDir.rsrc and /dev/null differ diff --git a/Mac/scripts/RunLibScript.py b/Mac/scripts/RunLibScript.py deleted file mode 100644 index 6ecf643..0000000 --- a/Mac/scripts/RunLibScript.py +++ /dev/null @@ -1,111 +0,0 @@ -"""Import a module while pretending its name is __main__. This -can be used to run scripts from the PackedLib resource file while pretending -they have been double-clicked.""" - -import imp -import sys -import os -import string -from Carbon import Dlg -import macfs - -DIALOG_ID = 512 -OK = 1 -CANCEL = 2 -SCRIPTNAME=3 -ARGV=4 -STDIN_CONS=5 -STDIN_FILE=6 -STDOUT_CONS=7 -STDOUT_FILE=8 -WORKING_DIR=9 -PAUSE=10 - -def import_as_main(name): - fp, path, (suffix, mode, type) = imp.find_module(name) - if type == imp.PY_SOURCE: - imp.load_source('__main__', path, fp) - elif type == imp.PY_COMPILED: - imp.load_compiled('__main__', path, fp) - elif type == imp.PY_RESOURCE: - imp.load_resource('__main__', path) - -def interact(): - d = Dlg.GetNewDialog(DIALOG_ID, -1) - wdir = stdin = stdout = None - pause = 0 - - tp, in_c_h, rect = d.GetDialogItem(STDIN_CONS) - tp, in_f_h, rect = d.GetDialogItem(STDIN_FILE) - tp, out_c_h, rect = d.GetDialogItem(STDOUT_CONS) - tp, out_f_h, rect = d.GetDialogItem(STDOUT_FILE) - tp, pause_h, rect = d.GetDialogItem(PAUSE) - in_c_h = in_c_h.as_Control() - in_f_h = in_f_h.as_Control() - out_c_h = out_c_h.as_Control() - out_f_h = out_f_h.as_Control() - pause_h = pause_h.as_Control() - - while 1: - in_c_h.SetControlValue(not stdin) - in_f_h.SetControlValue(not not stdin) - out_c_h.SetControlValue(not stdout) - out_f_h.SetControlValue(not not stdout) - pause_h.SetControlValue(pause) - - n = Dlg.ModalDialog(None) - if n == OK: - break - elif n == CANCEL: - sys.exit(0) - elif n == STDIN_CONS: - stdin = None - elif n == STDIN_FILE: - fss, ok = macfs.StandardGetFile('TEXT') - if ok: - stdin = fss - elif n == STDOUT_FILE: - fss, ok = macfs.StandardPutFile('stdout:') - if ok: - stdout = fss - elif n == WORKING_DIR: - fss, ok = macfs.GetDirectory() - if ok: - wdir = fss - elif n == PAUSE: - pause = (not pause) - - tp, h, rect = d.GetDialogItem(SCRIPTNAME) - name = Dlg.GetDialogItemText(h) - tp, h, rect = d.GetDialogItem(ARGV) - argv = Dlg.GetDialogItemText(h) - return name, argv, stdin, stdout, wdir, pause - -def main(): - curdir = os.getcwd() - from Carbon import Res - try: - Res.FSpOpenResFile('RunLibScript.rsrc', 1) - except: - pass # Assume we're an applet already - name, argv, stdin, stdout, wdir, pause = interact() - if not name: - sys.exit(0) - sys.argv = [name] + string.split(argv) - if stdin: - sys.stdin = open(stdin.as_pathname()) - if stdout: - sys.stdout = open(stdout.as_pathname(), 'w') - if wdir: - os.chdir(wdir.as_pathname()) - else: - os.chdir(curdir) - - import_as_main(name) - - if pause: - sys.exit(1) - -if __name__ == '__main__': - main() - diff --git a/Mac/scripts/RunLibScript.rsrc b/Mac/scripts/RunLibScript.rsrc deleted file mode 100644 index 22c097d..0000000 Binary files a/Mac/scripts/RunLibScript.rsrc and /dev/null differ diff --git a/Mac/scripts/run.py b/Mac/scripts/run.py deleted file mode 100644 index 75c6129..0000000 --- a/Mac/scripts/run.py +++ /dev/null @@ -1,41 +0,0 @@ -# Script (applet) to run any Python command - -def main(): - import sys - sys.stdout = sys.stderr - del sys.argv[:1] - if not sys.argv: - import macfs - srcfss, ok = macfs.StandardGetFile('TEXT') - if not ok: - return - filename = srcfss.as_pathname() - sys.argv.append(filename) - import __main__ - try: - execfile(sys.argv[0], __main__.__dict__) - except SystemExit, msg: - if msg: - message("Exit status: %s" % str(msg)) - print "exit", `msg` - #sys.exit(msg) - except: - etype = sys.exc_type - if hasattr(etype, "__name__"): etype = etype.__name__ - message("%s: %s" % (etype, sys.exc_value)) - print "exit 1" - #sys.exit(1) - -def message(str = "Hello, world!", id = 256): - from Carbon import Dlg - d = Dlg.GetNewDialog(id, -1) - if not d: - print str - return - tp, h, rect = d.GetDItem(2) - Dlg.SetIText(h, str) - while 1: - n = Dlg.ModalDialog(None) - if n == 1: break - -main() -- cgit v0.12