Show More
@@ -211,18 +211,6 b' def filter(s, cmd):' | |||
|
211 | 211 | return fn(s, cmd[len(name):].lstrip()) |
|
212 | 212 | return pipefilter(s, cmd) |
|
213 | 213 | |
|
214 | def find_in_path(name, path, default=None): | |
|
215 | '''find name in search path. path can be string (will be split | |
|
216 | with os.pathsep), or iterable thing that returns strings. if name | |
|
217 | found, return path to name. else return default.''' | |
|
218 | if isinstance(path, str): | |
|
219 | path = path.split(os.pathsep) | |
|
220 | for p in path: | |
|
221 | p_name = os.path.join(p, name) | |
|
222 | if os.path.exists(p_name): | |
|
223 | return p_name | |
|
224 | return default | |
|
225 | ||
|
226 | 214 | def binary(s): |
|
227 | 215 | """return true if a string is binary data using diff's heuristic""" |
|
228 | 216 | if s and '\0' in s[:4096]: |
@@ -921,6 +909,30 b" if os.name == 'nt':" | |||
|
921 | 909 | def isowner(fp, st=None): |
|
922 | 910 | return True |
|
923 | 911 | |
|
912 | def find_in_path(name, path, default=None): | |
|
913 | '''find name in search path. path can be string (will be split | |
|
914 | with os.pathsep), or iterable thing that returns strings. if name | |
|
915 | found, return path to name. else return default. name is looked up | |
|
916 | using cmd.exe rules, using PATHEXT.''' | |
|
917 | if isinstance(path, str): | |
|
918 | path = path.split(os.pathsep) | |
|
919 | ||
|
920 | pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD') | |
|
921 | pathext = pathext.lower().split(os.pathsep) | |
|
922 | isexec = os.path.splitext(name)[1].lower() in pathext | |
|
923 | ||
|
924 | for p in path: | |
|
925 | p_name = os.path.join(p, name) | |
|
926 | ||
|
927 | if isexec and os.path.exists(p_name): | |
|
928 | return p_name | |
|
929 | ||
|
930 | for ext in pathext: | |
|
931 | p_name_ext = p_name + ext | |
|
932 | if os.path.exists(p_name_ext): | |
|
933 | return p_name_ext | |
|
934 | return default | |
|
935 | ||
|
924 | 936 | try: |
|
925 | 937 | # override functions with win32 versions if possible |
|
926 | 938 | from util_win32 import * |
@@ -1059,6 +1071,18 b' else:' | |||
|
1059 | 1071 | st = fstat(fp) |
|
1060 | 1072 | return st.st_uid == os.getuid() |
|
1061 | 1073 | |
|
1074 | def find_in_path(name, path, default=None): | |
|
1075 | '''find name in search path. path can be string (will be split | |
|
1076 | with os.pathsep), or iterable thing that returns strings. if name | |
|
1077 | found, return path to name. else return default.''' | |
|
1078 | if isinstance(path, str): | |
|
1079 | path = path.split(os.pathsep) | |
|
1080 | for p in path: | |
|
1081 | p_name = os.path.join(p, name) | |
|
1082 | if os.path.exists(p_name): | |
|
1083 | return p_name | |
|
1084 | return default | |
|
1085 | ||
|
1062 | 1086 | def _buildencodefun(): |
|
1063 | 1087 | e = '_' |
|
1064 | 1088 | win_reserved = [ord(x) for x in '\\:*?"<>|'] |
@@ -298,29 +298,4 b' class posixfile_nt(object):' | |||
|
298 | 298 | except pywintypes.error, err: |
|
299 | 299 | raise WinIOError(err) |
|
300 | 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 | |
|
325 | ||
|
326 | 301 | getuser_fallback = win32api.GetUserName |
General Comments 0
You need to be logged in to leave comments.
Login now