Show More
@@ -0,0 +1,63 b'' | |||||
|
1 | """cli-specific implementation of process utilities. | |||
|
2 | ||||
|
3 | cli - Common Language Infrastructure for IronPython. Code | |||
|
4 | can run on any operating system. Check os.name for os- | |||
|
5 | specific settings. | |||
|
6 | ||||
|
7 | This file is only meant to be imported by process.py, not by end-users. | |||
|
8 | ||||
|
9 | This file is largely untested. To become a full drop-in process | |||
|
10 | interface for IronPython will probably require you to help fill | |||
|
11 | in the details. | |||
|
12 | """ | |||
|
13 | ||||
|
14 | # Import cli libraries: | |||
|
15 | import clr | |||
|
16 | import System | |||
|
17 | ||||
|
18 | # Import Python libraries: | |||
|
19 | import os | |||
|
20 | ||||
|
21 | # Import IPython libraries: | |||
|
22 | from IPython.utils import py3compat | |||
|
23 | from ._process_common import arg_split | |||
|
24 | ||||
|
25 | def _find_cmd(cmd): | |||
|
26 | """Find the full path to a command using which.""" | |||
|
27 | paths = System.Environment.GetEnvironmentVariable("PATH").Split(os.pathsep) | |||
|
28 | for path in paths: | |||
|
29 | filename = os.path.join(path, cmd) | |||
|
30 | if System.IO.File.Exists(filename): | |||
|
31 | return py3compat.bytes_to_str(filename) | |||
|
32 | raise OSError("command %r not found" % cmd) | |||
|
33 | ||||
|
34 | def system(cmd): | |||
|
35 | """ | |||
|
36 | system(cmd) should work in a cli environment on Mac OSX, Linux, | |||
|
37 | and Windows | |||
|
38 | """ | |||
|
39 | psi = System.Diagnostics.ProcessStartInfo(cmd) | |||
|
40 | psi.RedirectStandardOutput = True | |||
|
41 | psi.RedirectStandardError = True | |||
|
42 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal | |||
|
43 | psi.UseShellExecute = False | |||
|
44 | # Start up process: | |||
|
45 | reg = System.Diagnostics.Process.Start(psi) | |||
|
46 | ||||
|
47 | def getoutput(cmd): | |||
|
48 | """ | |||
|
49 | getoutput(cmd) should work in a cli environment on Mac OSX, Linux, | |||
|
50 | and Windows | |||
|
51 | """ | |||
|
52 | psi = System.Diagnostics.ProcessStartInfo(cmd) | |||
|
53 | psi.RedirectStandardOutput = True | |||
|
54 | psi.RedirectStandardError = True | |||
|
55 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal | |||
|
56 | psi.UseShellExecute = False | |||
|
57 | # Start up process: | |||
|
58 | reg = System.Diagnostics.Process.Start(psi) | |||
|
59 | myOutput = reg.StandardOutput | |||
|
60 | output = myOutput.ReadToEnd() | |||
|
61 | myError = reg.StandardError | |||
|
62 | error = myError.ReadToEnd() | |||
|
63 | return output |
@@ -147,7 +147,10 b' HOME = os.path.realpath(HOME)' | |||||
147 | USER = py3compat.str_to_unicode(os.environ.get("USER",'')) |
|
147 | USER = py3compat.str_to_unicode(os.environ.get("USER",'')) | |
148 | HOSTNAME = py3compat.str_to_unicode(socket.gethostname()) |
|
148 | HOSTNAME = py3compat.str_to_unicode(socket.gethostname()) | |
149 | HOSTNAME_SHORT = HOSTNAME.split(".")[0] |
|
149 | HOSTNAME_SHORT = HOSTNAME.split(".")[0] | |
150 | ROOT_SYMBOL = "#" if (os.name=='nt' or os.getuid()==0) else "$" |
|
150 | ||
|
151 | # IronPython doesn't currently have os.getuid() even if | |||
|
152 | # os.name == 'posix'; 2/8/2014 | |||
|
153 | ROOT_SYMBOL = "#" if (os.name=='nt' or sys.platform=='cli' or os.getuid()==0) else "$" | |||
151 |
|
154 | |||
152 | prompt_abbreviations = { |
|
155 | prompt_abbreviations = { | |
153 | # Prompt/history count |
|
156 | # Prompt/history count |
@@ -30,6 +30,9 b'' | |||||
30 | """ |
|
30 | """ | |
31 | Decorator module, see http://pypi.python.org/pypi/decorator |
|
31 | Decorator module, see http://pypi.python.org/pypi/decorator | |
32 | for the documentation. |
|
32 | for the documentation. | |
|
33 | ||||
|
34 | NOTE: this is an IPython-patched version to work on IronPython. See | |||
|
35 | FIXED comment below. | |||
33 | """ |
|
36 | """ | |
34 | from __future__ import print_function |
|
37 | from __future__ import print_function | |
35 |
|
38 | |||
@@ -139,7 +142,12 b' class FunctionMaker(object):' | |||||
139 | func.__defaults__ = getattr(self, 'defaults', ()) |
|
142 | func.__defaults__ = getattr(self, 'defaults', ()) | |
140 | func.__kwdefaults__ = getattr(self, 'kwonlydefaults', None) |
|
143 | func.__kwdefaults__ = getattr(self, 'kwonlydefaults', None) | |
141 | func.__annotations__ = getattr(self, 'annotations', None) |
|
144 | func.__annotations__ = getattr(self, 'annotations', None) | |
142 | callermodule = sys._getframe(3).f_globals.get('__name__', '?') |
|
145 | # FIXED: The following is try/excepted in IPython to work | |
|
146 | # with IronPython. | |||
|
147 | try: | |||
|
148 | callermodule = sys._getframe(3).f_globals.get('__name__', '?') | |||
|
149 | except AttributeError: # IronPython _getframe only exists with FullFrames | |||
|
150 | callermodule = '?' | |||
143 | func.__module__ = getattr(self, 'module', callermodule) |
|
151 | func.__module__ = getattr(self, 'module', callermodule) | |
144 | func.__dict__.update(kw) |
|
152 | func.__dict__.update(kw) | |
145 |
|
153 |
@@ -18,6 +18,8 b' try:' | |||||
18 | import ctypes |
|
18 | import ctypes | |
19 | except ImportError: |
|
19 | except ImportError: | |
20 | ctypes = None |
|
20 | ctypes = None | |
|
21 | except SystemError: # IronPython issue, 2/8/2014 | |||
|
22 | ctypes = None | |||
21 | import os |
|
23 | import os | |
22 | import sys |
|
24 | import sys | |
23 | from distutils.version import LooseVersion as V |
|
25 | from distutils.version import LooseVersion as V |
@@ -81,7 +81,7 b' class IOStream:' | |||||
81 | pass |
|
81 | pass | |
82 |
|
82 | |||
83 | # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr |
|
83 | # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr | |
84 |
devnull = open(os.devnull, ' |
|
84 | devnull = open(os.devnull, 'w') | |
85 | stdin = IOStream(sys.stdin, fallback=devnull) |
|
85 | stdin = IOStream(sys.stdin, fallback=devnull) | |
86 | stdout = IOStream(sys.stdout, fallback=devnull) |
|
86 | stdout = IOStream(sys.stdout, fallback=devnull) | |
87 | stderr = IOStream(sys.stderr, fallback=devnull) |
|
87 | stderr = IOStream(sys.stderr, fallback=devnull) |
@@ -22,11 +22,12 b' import shlex' | |||||
22 |
|
22 | |||
23 | # Our own |
|
23 | # Our own | |
24 | if sys.platform == 'win32': |
|
24 | if sys.platform == 'win32': | |
25 |
from ._process_win32 import _find_cmd, system, getoutput, |
|
25 | from ._process_win32 import _find_cmd, system, getoutput, arg_split | |
|
26 | elif sys.platform == 'cli': | |||
|
27 | from ._process_cli import _find_cmd, system, getoutput, arg_split | |||
26 | else: |
|
28 | else: | |
27 | from ._process_posix import _find_cmd, system, getoutput, arg_split |
|
29 | from ._process_posix import _find_cmd, system, getoutput, arg_split | |
28 |
|
30 | |||
29 |
|
||||
30 | from ._process_common import getoutputerror, get_output_error_code, process_handler |
|
31 | from ._process_common import getoutputerror, get_output_error_code, process_handler | |
31 | from . import py3compat |
|
32 | from . import py3compat | |
32 |
|
33 |
General Comments 0
You need to be logged in to leave comments.
Login now