comparison mercurial/util_win32.py @ 4380:8c2a18cc3096

Fix find_in_path not including some file extension logic under win32. Windows shell resolves utility path by combining PATH, the utility name and a set of file extensions from PATHEXT.
author Patrick Mezard <pmezard@gmail.com>
date Sat, 28 Apr 2007 11:43:31 +0200
parents c08b6af023bc
children f97b89314fb3
comparison
equal deleted inserted replaced
4379:f4af7960d578 4380:8c2a18cc3096
295 win32file.SetFilePointer(self.handle, int(pos), 295 win32file.SetFilePointer(self.handle, int(pos),
296 win32file.FILE_BEGIN) 296 win32file.FILE_BEGIN)
297 win32file.SetEndOfFile(self.handle) 297 win32file.SetEndOfFile(self.handle)
298 except pywintypes.error, err: 298 except pywintypes.error, err:
299 raise WinIOError(err) 299 raise WinIOError(err)
300
301 def find_in_path(name, path, default=None):
302 '''find name in search path. path can be string (will be split
303 with os.pathsep), or iterable thing that returns strings. if name
304 found, return path to name. else return default. name is looked up
305 using cmd.exe rules, using PATHEXT.'''
306 if isinstance(path, str):
307 path = path.split(os.pathsep)
308
309 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
310 pathext = pathext.lower().split(os.pathsep)
311 isexec = os.path.splitext(name)[1].lower() in pathext
312
313 for p in path:
314 p_name = os.path.join(p, name)
315
316 if isexec and os.path.exists(p_name):
317 return p_name
318
319 for ext in pathext:
320 p_name_ext = p_name + ext
321 if os.path.exists(p_name_ext):
322 return p_name_ext
323
324 return default
300 325
301 getuser_fallback = win32api.GetUserName 326 getuser_fallback = win32api.GetUserName