diff --git a/catcli/catcli.py b/catcli/catcli.py index b6e0f59..af01244 100755 --- a/catcli/catcli.py +++ b/catcli/catcli.py @@ -36,8 +36,8 @@ USAGE = """ {0} Usage: - {1} index [--catalog=] [--meta=...] [-acfuV] - {1} update [--catalog=] [-acfuV] + {1} index [--catalog=] [--meta=...] [-acfnV] + {1} update [--catalog=] [-acfnV] {1} ls [--catalog=] [-arVS] [] {1} find [--catalog=] [-abdVP] [--path=] {1} rm [--catalog=] [-fV] @@ -53,7 +53,7 @@ Options: --catalog= Path to the catalog [default: {2}]. --meta= Additional attribute to store [default: ]. -p --path= Start path. - -u --subsize Store size of directories [default: False]. + -n --no-subsize Do not 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). @@ -72,7 +72,7 @@ def cmd_index(args, noder, catalog, top, debug=False): path = args[''] name = args[''] nohash = not args['--hash'] - subsize = args['--subsize'] + subsize = not args['--no-subsize'] if not os.path.exists(path): Logger.err('\"{}\" does not exist'.format(path)) return @@ -103,7 +103,7 @@ def cmd_update(args, noder, catalog, top, debug=False): path = args[''] name = args[''] nohash = not args['--hash'] - subsize = args['--subsize'] + subsize = not args['--no-subsize'] if not os.path.exists(path): Logger.err('\"{}\" does not exist'.format(path)) return @@ -223,6 +223,9 @@ def main(): print(USAGE) return True + if args['--verbose']: + print(args) + # print banner banner() diff --git a/catcli/noder.py b/catcli/noder.py index b10951a..df493e3 100644 --- a/catcli/noder.py +++ b/catcli/noder.py @@ -91,23 +91,37 @@ class Noder: except StopIteration: return None - def rec_size(self, node): - '''recursively traverse tree and store dir size''' + def _rec_size(self, node, store=True): + ''' + recursively traverse tree and return size + @store: store the size in the node + ''' if self.verbose: - Logger.info('getting directory size recursively') + Logger.info('getting node size recursively') if node.type == self.TYPE_FILE: return node.size size = 0 for i in node.children: if node.type == self.TYPE_DIR: - size += self.rec_size(i) + sz = self._rec_size(i, store=store) + if store: + i.size = sz + size += sz if node.type == self.TYPE_STORAGE: - self.rec_size(i) + sz = self._rec_size(i, store=store) + if store: + i.size = sz + size += sz else: continue - node.size = size + if store: + node.size = size return size + def rec_size(self, node): + '''recursively traverse tree and store dir size''' + return self._rec_size(node, store=True) + ############################################################### # public helpers ############################################################### @@ -280,14 +294,23 @@ class Noder: hf = utils.human(node.free) ht = utils.human(node.total) nbchildren = len(node.children) + # get the date dt = '' if self._has_attr(node, 'ts'): - dt = ', date:' - dt += utils.epoch_to_str(node.ts) + dt = 'date:{}'.format(utils.epoch_to_str(node.ts)) + ds = '' + # the children size + sz = self._rec_size(node, store=False) + sz = utils.human(sz) + ds = 'totsize:{}'.format(sz) + # format the output name = '{}'.format(node.name) - args = '(nbfiles:{}, free:{}/{}{})'.format(nbchildren, - hf, ht, dt) - Logger.storage(pre, name, args, node.attr) + args = [ + 'nbfiles:{}'.format(nbchildren), + 'free:{}/{}'.format(hf, ht), + dt, + ds] + Logger.storage(pre, name, '({})'.format(','.join(args)), node.attr) elif node.type == self.TYPE_ARC: # archive node if self.arc: