##// END OF EJS Templates
Moving find_exe -> platutils.find_cmd and making is cross platform....
Brian Granger -
Show More
@@ -152,7 +152,11 b" def user_setup(ipythondir,rc_suffix,mode='install',interactive=True):"
152 152 printf = lambda s : None
153 153
154 154 # Install mode should be re-entrant: if the install dir already exists,
155 # bail out cleanly
155 # bail out cleanly.
156 # XXX. This is too hasty to return. We need to check to make sure that
157 # all the expected config files and directories are actually there. We
158 # currently have a failure mode if someone deletes a needed config file
159 # but still has the ipythondir.
156 160 if mode == 'install' and os.path.isdir(ipythondir):
157 161 return
158 162
@@ -54,22 +54,10 b' from IPython.kernel.fcutil import have_crypto'
54 54 from IPython.kernel.twistedutil import gatherBoth, wait_for_file
55 55 from IPython.kernel.util import printer
56 56
57
58 57 #-----------------------------------------------------------------------------
59 58 # General process handling code
60 59 #-----------------------------------------------------------------------------
61 60
62 def find_exe(cmd):
63 try:
64 import win32api
65 except ImportError:
66 raise ImportError('you need to have pywin32 installed for this to work')
67 else:
68 try:
69 (path, offest) = win32api.SearchPath(os.environ['PATH'],cmd + '.exe')
70 except:
71 (path, offset) = win32api.SearchPath(os.environ['PATH'],cmd + '.bat')
72 return path
73 61
74 62 class ProcessStateError(Exception):
75 63 pass
@@ -61,6 +61,33 b' def set_term_title(title):'
61 61 _platutils.set_term_title(title)
62 62
63 63
64 class FindCmdError(Exception):
65 pass
66
67 def find_cmd(cmd):
68 """Find full path to executable cmd in a cross platform manner.
69
70 This function tries to determine the full path to a command line program
71 using `which` on Unix/Linux/OS X and `win32api` on Windows. Most of the
72 time it will use the version that is first on the users `PATH`. If
73 cmd is `python` return `sys.executable`.
74
75 Parameters
76 ----------
77 cmd : str
78 The command line program to look for.
79 """
80 if cmd == 'python':
81 return sys.executable
82 try:
83 path = _platutils.find_cmd(cmd)
84 except:
85 raise FindCmdError('command could not be found: %s' % cmd)
86 # which returns empty if not found
87 if path == '':
88 raise FindCmdError('command could not be found: %s' % cmd)
89 return path
90
64 91 #-----------------------------------------------------------------------------
65 92 # Deprecated functions
66 93 #-----------------------------------------------------------------------------
@@ -23,3 +23,7 b' ignore_termtitle = True'
23 23 def set_term_title(*args,**kw):
24 24 """Dummy no-op."""
25 25 pass
26
27 def find_cmd(cmd):
28 """Find the full path to a command using which."""
29 return os.popen('which %s' % cmd).read().strip()
@@ -30,3 +30,7 b" if os.environ.get('TERM','') == 'xterm':"
30 30 set_term_title = _set_term_title_xterm
31 31 else:
32 32 set_term_title = _dummy_op
33
34 def find_cmd(cmd):
35 """Find the full path to a command using which."""
36 return os.popen('which %s' % cmd).read().strip()
@@ -41,3 +41,16 b' except ImportError:'
41 41 if ret:
42 42 # non-zero return code signals error, don't try again
43 43 ignore_termtitle = True
44
45 def find_cmd(cmd):
46 """Find the full path to a .bat or .exe using the win32api module."""
47 try:
48 import win32api
49 except ImportError:
50 raise ImportError('you need to have pywin32 installed for this to work')
51 else:
52 try:
53 (path, offest) = win32api.SearchPath(os.environ['PATH'],cmd + '.exe')
54 except:
55 (path, offset) = win32api.SearchPath(os.environ['PATH'],cmd + '.bat')
56 return path
General Comments 0
You need to be logged in to leave comments. Login now