Show More
@@ -211,18 +211,6 b' def filter(s, cmd):' | |||||
211 | return fn(s, cmd[len(name):].lstrip()) |
|
211 | return fn(s, cmd[len(name):].lstrip()) | |
212 | return pipefilter(s, cmd) |
|
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 | def binary(s): |
|
214 | def binary(s): | |
227 | """return true if a string is binary data using diff's heuristic""" |
|
215 | """return true if a string is binary data using diff's heuristic""" | |
228 | if s and '\0' in s[:4096]: |
|
216 | if s and '\0' in s[:4096]: | |
@@ -920,6 +908,30 b" if os.name == 'nt':" | |||||
920 | # username and groupname functions above, too. |
|
908 | # username and groupname functions above, too. | |
921 | def isowner(fp, st=None): |
|
909 | def isowner(fp, st=None): | |
922 | return True |
|
910 | return True | |
|
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 | |||
923 |
|
935 | |||
924 | try: |
|
936 | try: | |
925 | # override functions with win32 versions if possible |
|
937 | # override functions with win32 versions if possible | |
@@ -1058,6 +1070,18 b' else:' | |||||
1058 | if st is None: |
|
1070 | if st is None: | |
1059 | st = fstat(fp) |
|
1071 | st = fstat(fp) | |
1060 | return st.st_uid == os.getuid() |
|
1072 | return st.st_uid == os.getuid() | |
|
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 | |||
1061 |
|
1085 | |||
1062 | def _buildencodefun(): |
|
1086 | def _buildencodefun(): | |
1063 | e = '_' |
|
1087 | e = '_' |
@@ -297,30 +297,5 b' class posixfile_nt(object):' | |||||
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 |
|
|||
325 |
|
300 | |||
326 | getuser_fallback = win32api.GetUserName |
|
301 | getuser_fallback = win32api.GetUserName |
General Comments 0
You need to be logged in to leave comments.
Login now