diff --git a/README.md b/README.md index a51d013..9e7c844 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/catcli/catcli.py b/catcli/catcli.py index 245f0ce..e9e62d3 100755 --- a/catcli/catcli.py +++ b/catcli/catcli.py @@ -45,8 +45,8 @@ Usage: {NAME} find [--catalog=] [--format=] [-aBCbdVs] [--path=] [] {NAME} index [--catalog=] [--meta=...] - [-aBCcfnV] - {NAME} update [--catalog=] [-aBCcfnV] + [-aBCcfV] + {NAME} update [--catalog=] [-aBCcfV] [--lpath=] {NAME} mount [--catalog=] [-V] {NAME} rm [--catalog=] [-BCfV] @@ -70,7 +70,6 @@ Options: -F --format= see \"print_supported_formats\" [default: native]. -f --force Do not ask when updating the catalog [default: False]. -l --lpath= Path where changes are logged [default: ] - -n --no-subsize Do not store size of directories [default: False]. -p --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[''] 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}') diff --git a/catcli/noder.py b/catcli/noder.py index 7f5f0f8..d20d5d0 100644 --- a/catcli/noder.py +++ b/catcli/noder.py @@ -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'): diff --git a/catcli/nodes.py b/catcli/nodes.py index 545ba3f..fe49ec9 100644 --- a/catcli/nodes.py +++ b/catcli/nodes.py @@ -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""" diff --git a/catcli/walker.py b/catcli/walker.py index c5762f6..d57f5cd 100644 --- a/catcli/walker.py +++ b/catcli/walker.py @@ -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) diff --git a/tests/test_index.py b/tests/test_index.py index 088f65a..46734de 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -50,7 +50,7 @@ class TestIndexing(unittest.TestCase): tmpdirname = 'tmpdir' args = {'': dirpath, '': tmpdirname, '--hash': True, '--meta': ['some meta'], - '--no-subsize': False, '--verbose': True} + '--verbose': True} # index the directory cmd_index(args, noder, catalog, top) diff --git a/tests/test_update.py b/tests/test_update.py index 7365377..d70c564 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -62,8 +62,7 @@ class TestUpdate(unittest.TestCase): tmpdirname = 'tmpdir' args = {'': dirpath, '': tmpdirname, '--hash': True, '--meta': ['some meta'], - '--no-subsize': False, '--verbose': True, - '--lpath': None} + '--verbose': True, '--lpath': None} # index the directory unix_tree(dirpath)