refactoring

pull/29/head
deadc0de6 2 years ago
parent 362d824787
commit 173dca1d34

@ -193,7 +193,7 @@ def cmd_find(args, noder, top):
script = args['--script'] script = args['--script']
search_for = args['<term>'] search_for = args['<term>']
return noder.find_name(top, search_for, script=script, return noder.find_name(top, search_for, script=script,
startpath=startpath, directory=directory, startpath=startpath, only_dir=directory,
parentfromtree=fromtree, fmt=fmt, raw=raw) parentfromtree=fromtree, fmt=fmt, raw=raw)

@ -515,7 +515,7 @@ class Noder:
# searching # searching
############################################################### ###############################################################
def find_name(self, top, key, def find_name(self, top, key,
script=False, directory=False, script=False, only_dir=False,
startpath=None, parentfromtree=False, startpath=None, parentfromtree=False,
fmt='native', raw=False): fmt='native', raw=False):
""" """
@ -536,7 +536,7 @@ class Noder:
start = top start = top
if startpath: if startpath:
start = self.get_node(top, startpath) start = self.get_node(top, startpath)
filterfunc = self._callback_find_name(key, directory) filterfunc = self._callback_find_name(key, only_dir)
found = anytree.findall(start, filter_=filterfunc) found = anytree.findall(start, filter_=filterfunc)
nbfound = len(found) nbfound = len(found)
self._debug(f'found {nbfound} node(s)') self._debug(f'found {nbfound} node(s)')
@ -584,7 +584,7 @@ class Noder:
return list(paths.values()) return list(paths.values())
def _callback_find_name(self, term, directory): def _callback_find_name(self, term, only_dir):
"""callback for finding files""" """callback for finding files"""
def find_name(node): def find_name(node):
if node.type == self.TYPE_STORAGE: if node.type == self.TYPE_STORAGE:
@ -596,7 +596,7 @@ class Noder:
if node.type == self.TYPE_META: if node.type == self.TYPE_META:
# ignore meta nodes # ignore meta nodes
return False return False
if directory and node.type != self.TYPE_DIR: if only_dir and node.type != self.TYPE_DIR:
# ignore non directory # ignore non directory
return False return False

Loading…
Cancel
Save