##// END OF EJS Templates
Merge pull request #9864 from anantkaushik89/master...
Thomas Kluyver -
r22842:c62f6720 merge
parent child Browse files
Show More
@@ -0,0 +1,8 b''
1 Functions Removed in 6.x Development cycle
2 ------------------------------------------
3
4 The following functions have been removed in the
5 development cycle marked for Milestone 6.0.
6
7 * IPython/utils/process.py - is_cmd_found
8 * IPython/utils/process.py - pycmd2argv
@@ -1,106 +1,70 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Utilities for working with external processes.
3 Utilities for working with external processes.
4 """
4 """
5
5
6 # Copyright (c) IPython Development Team.
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8
8
9 from __future__ import print_function
9 from __future__ import print_function
10
10
11 import os
11 import os
12 import sys
12 import sys
13
13
14 if sys.platform == 'win32':
14 if sys.platform == 'win32':
15 from ._process_win32 import system, getoutput, arg_split, check_pid
15 from ._process_win32 import system, getoutput, arg_split, check_pid
16 elif sys.platform == 'cli':
16 elif sys.platform == 'cli':
17 from ._process_cli import system, getoutput, arg_split, check_pid
17 from ._process_cli import system, getoutput, arg_split, check_pid
18 else:
18 else:
19 from ._process_posix import system, getoutput, arg_split, check_pid
19 from ._process_posix import system, getoutput, arg_split, check_pid
20
20
21 from ._process_common import getoutputerror, get_output_error_code, process_handler
21 from ._process_common import getoutputerror, get_output_error_code, process_handler
22 from . import py3compat
22 from . import py3compat
23
23
24
24
25 class FindCmdError(Exception):
25 class FindCmdError(Exception):
26 pass
26 pass
27
27
28
28
29 def find_cmd(cmd):
29 def find_cmd(cmd):
30 """Find absolute path to executable cmd in a cross platform manner.
30 """Find absolute path to executable cmd in a cross platform manner.
31
31
32 This function tries to determine the full path to a command line program
32 This function tries to determine the full path to a command line program
33 using `which` on Unix/Linux/OS X and `win32api` on Windows. Most of the
33 using `which` on Unix/Linux/OS X and `win32api` on Windows. Most of the
34 time it will use the version that is first on the users `PATH`.
34 time it will use the version that is first on the users `PATH`.
35
35
36 Warning, don't use this to find IPython command line programs as there
36 Warning, don't use this to find IPython command line programs as there
37 is a risk you will find the wrong one. Instead find those using the
37 is a risk you will find the wrong one. Instead find those using the
38 following code and looking for the application itself::
38 following code and looking for the application itself::
39
39
40 from IPython.utils.path import get_ipython_module_path
40 import sys
41 from IPython.utils.process import pycmd2argv
41 argv = [sys.executable, '-m', 'IPython']
42 argv = pycmd2argv(get_ipython_module_path('IPython.terminal.ipapp'))
43
42
44 Parameters
43 Parameters
45 ----------
44 ----------
46 cmd : str
45 cmd : str
47 The command line program to look for.
46 The command line program to look for.
48 """
47 """
49 path = py3compat.which(cmd)
48 path = py3compat.which(cmd)
50 if path is None:
49 if path is None:
51 raise FindCmdError('command could not be found: %s' % cmd)
50 raise FindCmdError('command could not be found: %s' % cmd)
52 return path
51 return path
53
52
54
53
55 def is_cmd_found(cmd):
56 """Check whether executable `cmd` exists or not and return a bool."""
57 try:
58 find_cmd(cmd)
59 return True
60 except FindCmdError:
61 return False
62
63
64 def pycmd2argv(cmd):
65 r"""Take the path of a python command and return a list (argv-style).
66
67 This only works on Python based command line programs and will find the
68 location of the ``python`` executable using ``sys.executable`` to make
69 sure the right version is used.
70
71 For a given path ``cmd``, this returns [cmd] if cmd's extension is .exe,
72 .com or .bat, and [, cmd] otherwise.
73
74 Parameters
75 ----------
76 cmd : string
77 The path of the command.
78
79 Returns
80 -------
81 argv-style list.
82 """
83 ext = os.path.splitext(cmd)[1]
84 if ext in ['.exe', '.com', '.bat']:
85 return [cmd]
86 else:
87 return [sys.executable, cmd]
88
89
90 def abbrev_cwd():
54 def abbrev_cwd():
91 """ Return abbreviated version of cwd, e.g. d:mydir """
55 """ Return abbreviated version of cwd, e.g. d:mydir """
92 cwd = py3compat.getcwd().replace('\\','/')
56 cwd = py3compat.getcwd().replace('\\','/')
93 drivepart = ''
57 drivepart = ''
94 tail = cwd
58 tail = cwd
95 if sys.platform == 'win32':
59 if sys.platform == 'win32':
96 if len(cwd) < 4:
60 if len(cwd) < 4:
97 return cwd
61 return cwd
98 drivepart,tail = os.path.splitdrive(cwd)
62 drivepart,tail = os.path.splitdrive(cwd)
99
63
100
64
101 parts = tail.split('/')
65 parts = tail.split('/')
102 if len(parts) > 2:
66 if len(parts) > 2:
103 tail = '/'.join(parts[-2:])
67 tail = '/'.join(parts[-2:])
104
68
105 return (drivepart + (
69 return (drivepart + (
106 cwd == '/' and '/' or tail))
70 cwd == '/' and '/' or tail))
General Comments 0
You need to be logged in to leave comments. Login now