equal
deleted
inserted
replaced
16 |
16 |
17 from .i18n import _ |
17 from .i18n import _ |
18 from . import ( |
18 from . import ( |
19 encoding, |
19 encoding, |
20 osutil, |
20 osutil, |
|
21 pycompat, |
21 win32, |
22 win32, |
22 ) |
23 ) |
23 |
24 |
24 try: |
25 try: |
25 import _winreg as winreg |
26 import _winreg as winreg |
301 If command is a basename then PATH is searched for command. |
302 If command is a basename then PATH is searched for command. |
302 PATH isn't searched if command is an absolute or relative path. |
303 PATH isn't searched if command is an absolute or relative path. |
303 An extension from PATHEXT is found and added if not present. |
304 An extension from PATHEXT is found and added if not present. |
304 If command isn't found None is returned.''' |
305 If command isn't found None is returned.''' |
305 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD') |
306 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD') |
306 pathexts = [ext for ext in pathext.lower().split(os.pathsep)] |
307 pathexts = [ext for ext in pathext.lower().split(pycompat.ospathsep)] |
307 if os.path.splitext(command)[1].lower() in pathexts: |
308 if os.path.splitext(command)[1].lower() in pathexts: |
308 pathexts = [''] |
309 pathexts = [''] |
309 |
310 |
310 def findexisting(pathcommand): |
311 def findexisting(pathcommand): |
311 'Will append extension (if needed) and return existing file' |
312 'Will append extension (if needed) and return existing file' |
316 return None |
317 return None |
317 |
318 |
318 if os.sep in command: |
319 if os.sep in command: |
319 return findexisting(command) |
320 return findexisting(command) |
320 |
321 |
321 for path in os.environ.get('PATH', '').split(os.pathsep): |
322 for path in os.environ.get('PATH', '').split(pycompat.ospathsep): |
322 executable = findexisting(os.path.join(path, command)) |
323 executable = findexisting(os.path.join(path, command)) |
323 if executable is not None: |
324 if executable is not None: |
324 return executable |
325 return executable |
325 return findexisting(os.path.expanduser(os.path.expandvars(command))) |
326 return findexisting(os.path.expanduser(os.path.expandvars(command))) |
326 |
327 |