mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
rearrange path search functions
This commit is contained in:
parent
8395216a67
commit
caad772382
1 changed files with 11 additions and 18 deletions
|
@ -141,28 +141,17 @@ def globsearch(s):
|
||||||
return globpath(s, ignore_case=(not csc), return_empty=True)
|
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,
|
Takes a string and returns a list of file paths that match (regex, glob,
|
||||||
or arbitrary search function).
|
or arbitrary search function).
|
||||||
"""
|
"""
|
||||||
searchfunc, pattern = re.match(SearchPath, s).groups()
|
searchfunc = searchfunc[1:]
|
||||||
if searchfunc == 'r' or searchfunc == '':
|
if (not callable(func) or
|
||||||
o = regexsearch(pattern)
|
len(inspect.signature(func).parameters) != 1):
|
||||||
elif searchfunc == 'g':
|
error = "%r is not a known path search function"
|
||||||
o = globsearch(pattern)
|
raise XonshError(error % searchfunc)
|
||||||
else:
|
o = func(pattern)
|
||||||
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 = []
|
|
||||||
no_match = [] if pymode else [pattern]
|
no_match = [] if pymode else [pattern]
|
||||||
return o if len(o) != 0 else no_match
|
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_help__ = helper
|
||||||
builtins.__xonsh_superhelp__ = superhelper
|
builtins.__xonsh_superhelp__ = superhelper
|
||||||
builtins.__xonsh_pathsearch__ = pathsearch
|
builtins.__xonsh_pathsearch__ = pathsearch
|
||||||
|
builtins.__xonsh_globsearch__ = globsearch
|
||||||
|
builtins.__xonsh_regexsearch__ = regexsearch
|
||||||
builtins.__xonsh_glob__ = globpath
|
builtins.__xonsh_glob__ = globpath
|
||||||
builtins.__xonsh_expand_path__ = expand_path
|
builtins.__xonsh_expand_path__ = expand_path
|
||||||
builtins.__xonsh_exit__ = False
|
builtins.__xonsh_exit__ = False
|
||||||
|
@ -754,6 +745,8 @@ def unload_builtins():
|
||||||
'__xonsh_help__',
|
'__xonsh_help__',
|
||||||
'__xonsh_superhelp__',
|
'__xonsh_superhelp__',
|
||||||
'__xonsh_pathsearch__',
|
'__xonsh_pathsearch__',
|
||||||
|
'__xonsh_globsearch__',
|
||||||
|
'__xonsh_regexsearch__',
|
||||||
'__xonsh_glob__',
|
'__xonsh_glob__',
|
||||||
'__xonsh_expand_path__',
|
'__xonsh_expand_path__',
|
||||||
'__xonsh_exit__',
|
'__xonsh_exit__',
|
||||||
|
|
Loading…
Add table
Reference in a new issue