##// END OF EJS Templates
Removing unecessary checks for win32
Jörgen Stenarson -
Show More
@@ -1,119 +1,117 b''
1 1 # encoding: utf-8
2 2 """
3 3 Utilities for working with external processes.
4 4 """
5 5
6 6 #-----------------------------------------------------------------------------
7 7 # Copyright (C) 2008-2011 The IPython Development Team
8 8 #
9 9 # Distributed under the terms of the BSD License. The full license is in
10 10 # the file COPYING, distributed as part of this software.
11 11 #-----------------------------------------------------------------------------
12 12
13 13 #-----------------------------------------------------------------------------
14 14 # Imports
15 15 #-----------------------------------------------------------------------------
16 16 from __future__ import print_function
17 17
18 18 # Stdlib
19 19 import os
20 20 import sys
21 21 import shlex
22 22
23 23 # Our own
24 24 if sys.platform == 'win32':
25 25 from ._process_win32 import _find_cmd, system, getoutput, AvoidUNCPath, arg_split
26 26 else:
27 27 from ._process_posix import _find_cmd, system, getoutput, arg_split
28 28
29 29
30 30 from ._process_common import getoutputerror
31 31 from IPython.utils import py3compat
32 32
33 33 #-----------------------------------------------------------------------------
34 34 # Code
35 35 #-----------------------------------------------------------------------------
36 36
37 37
38 38 class FindCmdError(Exception):
39 39 pass
40 40
41 41
42 42 def find_cmd(cmd):
43 43 """Find absolute path to executable cmd in a cross platform manner.
44 44
45 45 This function tries to determine the full path to a command line program
46 46 using `which` on Unix/Linux/OS X and `win32api` on Windows. Most of the
47 47 time it will use the version that is first on the users `PATH`. If
48 48 cmd is `python` return `sys.executable`.
49 49
50 50 Warning, don't use this to find IPython command line programs as there
51 51 is a risk you will find the wrong one. Instead find those using the
52 52 following code and looking for the application itself::
53 53
54 54 from IPython.utils.path import get_ipython_module_path
55 55 from IPython.utils.process import pycmd2argv
56 56 argv = pycmd2argv(get_ipython_module_path('IPython.frontend.terminal.ipapp'))
57 57
58 58 Parameters
59 59 ----------
60 60 cmd : str
61 61 The command line program to look for.
62 62 """
63 63 if cmd == 'python':
64 64 return os.path.abspath(sys.executable)
65 65 try:
66 66 path = _find_cmd(cmd).rstrip()
67 67 except OSError:
68 68 raise FindCmdError('command could not be found: %s' % cmd)
69 69 # which returns empty if not found
70 70 if path == '':
71 71 raise FindCmdError('command could not be found: %s' % cmd)
72 72 return os.path.abspath(path)
73 73
74 74
75 75 def pycmd2argv(cmd):
76 76 r"""Take the path of a python command and return a list (argv-style).
77 77
78 78 This only works on Python based command line programs and will find the
79 79 location of the ``python`` executable using ``sys.executable`` to make
80 80 sure the right version is used.
81 81
82 82 For a given path ``cmd``, this returns [cmd] if cmd's extension is .exe,
83 83 .com or .bat, and [, cmd] otherwise.
84 84
85 85 Parameters
86 86 ----------
87 87 cmd : string
88 88 The path of the command.
89 89
90 90 Returns
91 91 -------
92 92 argv-style list.
93 93 """
94 94 ext = os.path.splitext(cmd)[1]
95 95 if ext in ['.exe', '.com', '.bat']:
96 96 return [cmd]
97 97 else:
98 if sys.platform == 'win32':
99 return [sys.executable, cmd]
100 else:
101 return [sys.executable, cmd]
98 return [sys.executable, cmd]
99
102 100
103 101 def abbrev_cwd():
104 102 """ Return abbreviated version of cwd, e.g. d:mydir """
105 103 cwd = os.getcwdu().replace('\\','/')
106 104 drivepart = ''
107 105 tail = cwd
108 106 if sys.platform == 'win32':
109 107 if len(cwd) < 4:
110 108 return cwd
111 109 drivepart,tail = os.path.splitdrive(cwd)
112 110
113 111
114 112 parts = tail.split('/')
115 113 if len(parts) > 2:
116 114 tail = '/'.join(parts[-2:])
117 115
118 116 return (drivepart + (
119 117 cwd == '/' and '/' or tail))
General Comments 0
You need to be logged in to leave comments. Login now