find by directory and by path

pull/11/head
deadc0de6 5 years ago
parent b0793dd97b
commit a72a1b60fc

@ -39,7 +39,7 @@ Usage:
{1} index [--catalog=<path>] [--meta=<meta>...] [-acfuV] <name> <path>
{1} update [--catalog=<path>] [-acfuV] <name> <path>
{1} ls [--catalog=<path>] [-arVS] [<path>]
{1} find [--catalog=<path>] [-abVP] <term>
{1} find [--catalog=<path>] [-abdVP] [--path=<path>] <term>
{1} rm [--catalog=<path>] [-fV] <storage>
{1} tree [--catalog=<path>] [-aVS] [<path>]
{1} rename [--catalog=<path>] [-fV] <storage> <name>
@ -52,9 +52,11 @@ Usage:
Options:
--catalog=<path> Path to the catalog [default: {2}].
--meta=<meta> Additional attribute to store [default: ].
-p --path=<path> Start path.
-u --subsize Store size of directories [default: False].
-a --archive Handle archive file [default: False].
-f --force Do not ask when updating the catalog [default: False].
-d --directory Only directory (default: False).
-b --script Output script to manage found file(s) [default: False].
-S --sortsize Sort by size, largest first [default: False].
-c --hash Calculate md5 hash [default: False].
@ -153,7 +155,10 @@ def cmd_rm(args, noder, catalog, top):
def cmd_find(args, noder, top):
fromtree = args['--parent']
directory = args['--directory']
startpath = args['--path']
return noder.find_name(top, args['<term>'], script=args['--script'],
startpath=startpath, directory=directory,
parentfromtree=fromtree)

@ -245,6 +245,7 @@ class Noder:
name = os.sep.join([self._get_parents(node.parent), name])
else:
name = node.relpath
name = name.lstrip(os.sep)
if withstorage:
storage = self._get_storage(node)
attr = ''
@ -262,6 +263,7 @@ class Noder:
name = os.sep.join([self._get_parents(node.parent), name])
else:
name = node.relpath
name = name.lstrip(os.sep)
depth = ''
if withdepth:
depth = len(node.children)
@ -309,18 +311,24 @@ class Noder:
# searching
###############################################################
def find_name(self, root, key,
script=False,
parentfromtree=False):
script=False, directory=False,
startpath=None, parentfromtree=False):
'''find files based on their names'''
if self.verbose:
Logger.info('searching for \"{}\"'.format(key))
start = root
if startpath:
start = self.get_node(root, startpath)
self.term = key
found = anytree.findall(root, filter_=self._find_name)
found = anytree.findall(start, filter_=self._find_name)
paths = []
for f in found:
if f.type == self.TYPE_STORAGE:
# ignore storage nodes
continue
if directory and f.type != self.TYPE_DIR:
# ignore non directory
continue
self._print_node(f, withpath=True, withdepth=True,
withstorage=True, recalcparent=parentfromtree)
if parentfromtree:

Loading…
Cancel
Save