features-42
deadc0de6 4 months ago
parent e58da8b6bf
commit bed81ffee4

@ -148,9 +148,6 @@ directory under `catcli.catalog`.
The `--meta` switch allows to add any additional information to store along in
the catalog like for example `the blue disk in my office`.
Catcli will calculate and store the total size of each node (directories, storages, etc)
unless the `-n --no-subsize` switch is used.
Using the `-a --archive` switch allows to also index archive files as explained
[below](#index-archive-files).

@ -45,8 +45,8 @@ Usage:
{NAME} find [--catalog=<path>] [--format=<fmt>]
[-aBCbdVs] [--path=<path>] [<term>]
{NAME} index [--catalog=<path>] [--meta=<meta>...]
[-aBCcfnV] <name> <path>
{NAME} update [--catalog=<path>] [-aBCcfnV]
[-aBCcfV] <name> <path>
{NAME} update [--catalog=<path>] [-aBCcfV]
[--lpath=<path>] <name> <path>
{NAME} mount [--catalog=<path>] [-V] <mountpoint>
{NAME} rm [--catalog=<path>] [-BCfV] <storage>
@ -70,7 +70,6 @@ Options:
-F --format=<fmt> see \"print_supported_formats\" [default: native].
-f --force Do not ask when updating the catalog [default: False].
-l --lpath=<path> Path where changes are logged [default: ]
-n --no-subsize Do not store size of directories [default: False].
-p --path=<path> Start path.
-r --recursive Recursive [default: False].
-s --raw-size Print raw size [default: False].
@ -106,7 +105,6 @@ def cmd_index(args: Dict[str, Any],
name = args['<name>']
usehash = args['--hash']
debug = args['--verbose']
subsize = not args['--no-subsize']
if not os.path.exists(path):
Logger.err(f'\"{path}\" does not exist')
return
@ -119,15 +117,15 @@ def cmd_index(args: Dict[str, Any],
Logger.err('aborted')
return
node = top.get_storage_node()
node.parent = None
if node:
node.parent = None
start = datetime.datetime.now()
walker = Walker(noder, usehash=usehash, debug=debug)
attr = args['--meta']
root = noder.new_storage_node(name, path, top, attr)
_, cnt = walker.index(path, root, name)
if subsize:
root.nodesize = root.get_rec_size()
root.nodesize = root.get_rec_size()
stop = datetime.datetime.now()
diff = stop - start
Logger.info(f'Indexed {cnt} file(s) in {diff}')
@ -145,7 +143,6 @@ def cmd_update(args: Dict[str, Any],
usehash = args['--hash']
logpath = args['--lpath']
debug = args['--verbose']
subsize = not args['--no-subsize']
if not os.path.exists(path):
Logger.err(f'\"{path}\" does not exist')
return
@ -158,8 +155,7 @@ def cmd_update(args: Dict[str, Any],
walker = Walker(noder, usehash=usehash, debug=debug,
logpath=logpath)
cnt = walker.reindex(path, storage, top)
if subsize:
storage.nodesize = storage.get_rec_size()
storage.nodesize = storage.get_rec_size()
stop = datetime.datetime.now()
diff = stop - start
Logger.info(f'updated {cnt} file(s) in {diff}')

@ -610,7 +610,8 @@ class Noder:
self.csv_printer.print_header()
for item in found:
if fmt == 'native':
self._print_node_native(item, withpath=False,
self._print_node_native(item,
withpath=True,
withnbchildren=True,
raw=raw)
elif fmt.startswith('csv'):

@ -146,7 +146,7 @@ class NodeFile(NodeAny):
path = self.parent.get_parent_hierarchy()
if path:
return os.sep.join([path, self.name])
return str(self.name)
return ''
def get_storage_node(self) -> NodeAny:
"""recursively traverse up to find storage"""
@ -185,7 +185,7 @@ class NodeDir(NodeAny):
path = self.parent.get_parent_hierarchy()
if path:
return os.sep.join([path, self.name])
return str(self.name)
return ''
def get_storage_node(self) -> NodeAny:
"""recursively traverse up to find storage"""
@ -230,7 +230,7 @@ class NodeArchived(NodeAny):
path = self.parent.get_parent_hierarchy()
if path:
return os.sep.join([path, self.name])
return str(self.name)
return ''
def get_storage_node(self) -> NodeAny:
"""recursively traverse up to find storage"""
@ -312,7 +312,7 @@ class NodeMeta(NodeAny):
path = self.parent.get_parent_hierarchy()
if path:
return os.sep.join([path, self.name])
return str(self.name)
return ''
def get_rec_size(self) -> int:
"""recursively traverse tree and return size"""

@ -35,7 +35,8 @@ class Walker:
self.debug = debug
self.lpath = logpath
def index(self, path: str,
def index(self,
path: str,
parent: NodeAny,
name: str,
storagepath: str = '') -> Tuple[str, int]:
@ -47,6 +48,7 @@ class Walker:
"""
self._debug(f'indexing starting at {path}')
if not parent:
# create the parent
parent = self.noder.new_dir_node(name,
path,
parent)

@ -50,7 +50,7 @@ class TestIndexing(unittest.TestCase):
tmpdirname = 'tmpdir'
args = {'<path>': dirpath, '<name>': tmpdirname,
'--hash': True, '--meta': ['some meta'],
'--no-subsize': False, '--verbose': True}
'--verbose': True}
# index the directory
cmd_index(args, noder, catalog, top)

@ -62,8 +62,7 @@ class TestUpdate(unittest.TestCase):
tmpdirname = 'tmpdir'
args = {'<path>': dirpath, '<name>': tmpdirname,
'--hash': True, '--meta': ['some meta'],
'--no-subsize': False, '--verbose': True,
'--lpath': None}
'--verbose': True, '--lpath': None}
# index the directory
unix_tree(dirpath)

Loading…
Cancel
Save