##// END OF EJS Templates
Minimal changes to import IPython from IronPython
Doug Blank -
Show More
@@ -0,0 +1,61 b''
1 """
2 cli-specific implementation of process utilities.
3
4 cli - Common Language Infrastructure for IronPython. Code
5 can run on any operating system. Check os.name for os-
6 specific settings.
7
8 This file is only meant to be imported by process.py, not by end-users.
9 """
10
11 # Import cli libraries:
12 import clr
13 import System
14
15 # Import Python libraries:
16 import os
17
18 # Import IPython libraries:
19 from IPython.utils import py3compat
20 from ._process_common import arg_split
21
22 def _find_cmd(cmd):
23 """Find the full path to a command using which."""
24 os_path_sep = ":" if os.name == "posix" else ";"
25 paths = System.Environment.GetEnvironmentVariable("PATH").Split(os_path_sep)
26 for path in paths:
27 filename = os.path.join(path, cmd)
28 if System.IO.File.Exists(filename):
29 return py3compat.bytes_to_str(filename)
30 raise OSError("command %r not found" % cmd)
31
32 def system(cmd):
33 """
34 system(cmd) should work in a cli environment on Mac OSX, Linux,
35 and Windows
36 """
37 psi = System.Diagnostics.ProcessStartInfo(cmd)
38 psi.RedirectStandardOutput = True
39 psi.RedirectStandardError = True
40 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
41 psi.UseShellExecute = False
42 # Start up process:
43 reg = System.Diagnostics.Process.Start(psi)
44
45 def getoutput(cmd):
46 """
47 getoutput(cmd) should work in a cli environment on Mac OSX, Linux,
48 and Windows
49 """
50 psi = System.Diagnostics.ProcessStartInfo(cmd)
51 psi.RedirectStandardOutput = True
52 psi.RedirectStandardError = True
53 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
54 psi.UseShellExecute = False
55 # Start up process:
56 reg = System.Diagnostics.Process.Start(psi)
57 myOutput = reg.StandardOutput
58 output = myOutput.ReadToEnd()
59 myError = reg.StandardError
60 error = myError.ReadToEnd()
61 return output
@@ -45,7 +45,10 b' import time'
45 # this is used as a bitmask to extract future-related code flags.
45 # this is used as a bitmask to extract future-related code flags.
46 PyCF_MASK = functools.reduce(operator.or_,
46 PyCF_MASK = functools.reduce(operator.or_,
47 (getattr(__future__, fname).compiler_flag
47 (getattr(__future__, fname).compiler_flag
48 for fname in __future__.all_feature_names))
48 for fname in __future__.all_feature_names
49 if (hasattr(__future__, fname) and
50 hasattr(getattr(__future__, fname), "compiler_flag"))),
51 0)
49
52
50 #-----------------------------------------------------------------------------
53 #-----------------------------------------------------------------------------
51 # Local utilities
54 # Local utilities
@@ -66,7 +66,10 b' Notes:'
66 # Imports
66 # Imports
67 #-----------------------------------------------------------------------------
67 #-----------------------------------------------------------------------------
68
68
69 import __main__
69 try:
70 import __main__
71 except ImportError:
72 pass
70 import glob
73 import glob
71 import inspect
74 import inspect
72 import itertools
75 import itertools
@@ -147,7 +147,8 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 ROOT_SYMBOL = "#" if (os.name=='nt' or sys.platform=='cli' or os.getuid()==0) else "$"
151
152
152 prompt_abbreviations = {
153 prompt_abbreviations = {
153 # Prompt/history count
154 # Prompt/history count
@@ -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:
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, 'a')
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, AvoidUNCPath, arg_split
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