Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 4407:f97b89314fb3
Move win32 find_in_files from util_win32 to util.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 06 May 2007 16:40:53 +0200 |
parents | f9cd48bd8625 |
children | 439b1c35348a |
comparison
equal
deleted
inserted
replaced
4404:47371e1c1db4 | 4407:f97b89314fb3 |
---|---|
208 "filter a string through a command that transforms its input to its output" | 208 "filter a string through a command that transforms its input to its output" |
209 for name, fn in filtertable.iteritems(): | 209 for name, fn in filtertable.iteritems(): |
210 if cmd.startswith(name): | 210 if cmd.startswith(name): |
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 | |
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 | 213 |
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]: |
229 return True | 217 return True |
918 | 906 |
919 # if you change this stub into a real check, please try to implement the | 907 # if you change this stub into a real check, please try to implement the |
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 |
926 from util_win32 import * | 938 from util_win32 import * |
927 if not is_win_9x(): | 939 if not is_win_9x(): |
1056 The return value of a util.fstat(f) may be passed as the st argument. | 1068 The return value of a util.fstat(f) may be passed as the st argument. |
1057 """ | 1069 """ |
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 = '_' |
1064 win_reserved = [ord(x) for x in '\\:*?"<>|'] | 1088 win_reserved = [ord(x) for x in '\\:*?"<>|'] |
1065 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ]) | 1089 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ]) |