rearrange path search functions

This commit is contained in:
adam j hartz 2016-06-16 00:22:52 -04:00
parent 8395216a67
commit caad772382

View file

@ -141,28 +141,17 @@ def globsearch(s):
return globpath(s, ignore_case=(not csc), return_empty=True)
def pathsearch(s, pymode=False):
def pathsearch(func, s, pymode=False):
"""
Takes a string and returns a list of file paths that match (regex, glob,
or arbitrary search function).
"""
searchfunc, pattern = re.match(SearchPath, s).groups()
if searchfunc == 'r' or searchfunc == '':
o = regexsearch(pattern)
elif searchfunc == 'g':
o = globsearch(pattern)
else:
ctx = builtins.__xonsh_ctx__
searchfunc = searchfunc[1:]
if (searchfunc not in ctx or
not callable(ctx[searchfunc]) or
len(inspect.signature(ctx[searchfunc]).parameters) != 1):
error = "%r is not a known path search function"
raise XonshError(error % searchfunc)
try:
o = ctx[searchfunc](pattern)
except Exception:
o = []
searchfunc = searchfunc[1:]
if (not callable(func) or
len(inspect.signature(func).parameters) != 1):
error = "%r is not a known path search function"
raise XonshError(error % searchfunc)
o = func(pattern)
no_match = [] if pymode else [pattern]
return o if len(o) != 0 else no_match
@ -686,6 +675,8 @@ def load_builtins(execer=None, config=None, login=False, ctx=None):
builtins.__xonsh_help__ = helper
builtins.__xonsh_superhelp__ = superhelper
builtins.__xonsh_pathsearch__ = pathsearch
builtins.__xonsh_globsearch__ = globsearch
builtins.__xonsh_regexsearch__ = regexsearch
builtins.__xonsh_glob__ = globpath
builtins.__xonsh_expand_path__ = expand_path
builtins.__xonsh_exit__ = False
@ -754,6 +745,8 @@ def unload_builtins():
'__xonsh_help__',
'__xonsh_superhelp__',
'__xonsh_pathsearch__',
'__xonsh_globsearch__',
'__xonsh_regexsearch__',
'__xonsh_glob__',
'__xonsh_expand_path__',
'__xonsh_exit__',