handle file listing and glob

features-42
deadc0de6 4 months ago
parent 9050c6bcf6
commit f918ea5ae4

@ -376,6 +376,26 @@ class Noder:
if len(line) > 0:
Logger.stdout_nocolor(line)
def node_has_subs(self, node: Any) -> bool:
"""
node may have children
we explicitely handle all case
for clarity
"""
if not node:
return False
if node.type == nodes.TYPE_TOP:
return True
if node.type == nodes.TYPE_FILE:
return False
if node.type == nodes.TYPE_DIR:
return True
if node.type == nodes.TYPE_STORAGE:
return True
if node.type == nodes.TYPE_ARCHIVED:
return True
return False
def _print_node_native(self, node: NodeAny,
pre: str = '',
withpath: bool = False,
@ -678,8 +698,20 @@ class Noder:
resolv = anytree.resolver.Resolver('name')
found = []
try:
# resolve the path in the tree
found = resolv.glob(top, path)
if '*' in path or '?' in path:
# we need to handle glob
found = resolv.glob(top, path)
else:
# we have a canonical path
found = resolv.get(top, path)
if found and self.node_has_subs(found):
# let's find its children as well
print(path)
modpath = os.path.join(path, '*')
found = resolv.glob(top, modpath)
else:
found = [found]
if len(found) < 1:
# nothing found
self._debug('nothing found')

@ -41,9 +41,9 @@ def path_to_search_all(path: str) -> str:
if not path.endswith(os.path.sep):
# ensure ends with a separator
path += os.path.sep
if not path.endswith(WILD):
# add wild card
path += WILD
# if not path.endswith(WILD):
# # add wild card
# path += WILD
return path

Loading…
Cancel
Save