diff options
author | Ian Johnson <ian.johnson@appliedlanguage.com> | 2013-11-06 21:22:47 +0400 |
---|---|---|
committer | Ian Johnson <ian.johnson@appliedlanguage.com> | 2013-11-06 21:22:47 +0400 |
commit | 47e0bc7a1da52c754b156d5fddf46d8cbd24053e (patch) | |
tree | 975da0d8084f6224400174e88833eee1b64f2472 | |
parent | da5d2737a231e311b4290daa97b6322523b43335 (diff) |
Added more runtime functions.
-rw-r--r-- | src/runtime/pcl/io/file.py | 3 | ||||
-rw-r--r-- | src/runtime/pcl/os/path.py | 5 | ||||
-rw-r--r-- | src/runtime/pcl/system/process.py | 31 |
3 files changed, 32 insertions, 7 deletions
diff --git a/src/runtime/pcl/io/file.py b/src/runtime/pcl/io/file.py index eb56f98..13b8029 100644 --- a/src/runtime/pcl/io/file.py +++ b/src/runtime/pcl/io/file.py @@ -23,3 +23,6 @@ openFile = lambda fn, flags: open(fn, flags) # closeFile :: file -> () closeFile = lambda f: f.close() + +# rewindFile :: file -> () +rewindFile = lambda f: f.seek(0) diff --git a/src/runtime/pcl/os/path.py b/src/runtime/pcl/os/path.py index 8167f6b..593560d 100644 --- a/src/runtime/pcl/os/path.py +++ b/src/runtime/pcl/os/path.py @@ -32,3 +32,8 @@ makedirs = lambda p: os.makedirs(p.__str__()) # basename :: String -> String basename = lambda s: os.path.basename(s.__str__()) + +# splitext :: String -> [String] +def splitext(s): + t = os.path.splitext(s.__str__()) + return [t[0], t[1].split('.')[-1]] diff --git a/src/runtime/pcl/system/process.py b/src/runtime/pcl/system/process.py index 93b6221..8165f1d 100644 --- a/src/runtime/pcl/system/process.py +++ b/src/runtime/pcl/system/process.py @@ -19,20 +19,37 @@ import subprocess import sys + +def __pre_process_program(program): + is_shell = False + if hasattr(program, "__iter__"): + cmd_line = [str(c) for c in program] + else: + cmd_line = str(program) + is_shell = True + + return cmd_line, is_shell + + # callAndCheck :: * -> File -> File -> File def callAndCheck(program, stdin_stream = sys.stdin, stdout_stream = sys.stdout, stderr_stream = sys.stderr): - is_shell = False - if hasattr(program, "__iter__"): - cmd_line = [str(c) for c in program] - else: - cmd_line = str(program) - is_shell = True - + cmd_line, is_shell = __pre_process_program(program) subprocess.check_call(cmd_line, stdin = stdin_stream, stdout = stdout_stream, stderr = stderr_stream, shell = is_shell) + +def checkOutput(program, + stdin_stream = sys.stdin, + stdout_stream = sys.stdout, + stderr_stream = sys.stderr): + cmd_line, is_shell = __pre_process_program(program) + return subprocess.check_output(cmd_line, + stdin = stdin_stream, + stdout = stdout_stream, + stderr = stderr_stream, + shell = is_shell) |