adding totsize everywhere

pull/11/head
deadc0de6 5 years ago
parent f97e90bf22
commit 5c268d212c

@ -36,8 +36,8 @@ USAGE = """
{0} {0}
Usage: Usage:
{1} index [--catalog=<path>] [--meta=<meta>...] [-acfuV] <name> <path> {1} index [--catalog=<path>] [--meta=<meta>...] [-acfnV] <name> <path>
{1} update [--catalog=<path>] [-acfuV] <name> <path> {1} update [--catalog=<path>] [-acfnV] <name> <path>
{1} ls [--catalog=<path>] [-arVS] [<path>] {1} ls [--catalog=<path>] [-arVS] [<path>]
{1} find [--catalog=<path>] [-abdVP] [--path=<path>] <term> {1} find [--catalog=<path>] [-abdVP] [--path=<path>] <term>
{1} rm [--catalog=<path>] [-fV] <storage> {1} rm [--catalog=<path>] [-fV] <storage>
@ -53,7 +53,7 @@ Options:
--catalog=<path> Path to the catalog [default: {2}]. --catalog=<path> Path to the catalog [default: {2}].
--meta=<meta> Additional attribute to store [default: ]. --meta=<meta> Additional attribute to store [default: ].
-p --path=<path> Start path. -p --path=<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]. -a --archive Handle archive file [default: False].
-f --force Do not ask when updating the catalog [default: False]. -f --force Do not ask when updating the catalog [default: False].
-d --directory Only directory (default: False). -d --directory Only directory (default: False).
@ -72,7 +72,7 @@ def cmd_index(args, noder, catalog, top, debug=False):
path = args['<path>'] path = args['<path>']
name = args['<name>'] name = args['<name>']
nohash = not args['--hash'] nohash = not args['--hash']
subsize = args['--subsize'] subsize = not args['--no-subsize']
if not os.path.exists(path): if not os.path.exists(path):
Logger.err('\"{}\" does not exist'.format(path)) Logger.err('\"{}\" does not exist'.format(path))
return return
@ -103,7 +103,7 @@ def cmd_update(args, noder, catalog, top, debug=False):
path = args['<path>'] path = args['<path>']
name = args['<name>'] name = args['<name>']
nohash = not args['--hash'] nohash = not args['--hash']
subsize = args['--subsize'] subsize = not args['--no-subsize']
if not os.path.exists(path): if not os.path.exists(path):
Logger.err('\"{}\" does not exist'.format(path)) Logger.err('\"{}\" does not exist'.format(path))
return return
@ -223,6 +223,9 @@ def main():
print(USAGE) print(USAGE)
return True return True
if args['--verbose']:
print(args)
# print banner # print banner
banner() banner()

@ -91,23 +91,37 @@ class Noder:
except StopIteration: except StopIteration:
return None return None
def rec_size(self, node): def _rec_size(self, node, store=True):
'''recursively traverse tree and store dir size''' '''
recursively traverse tree and return size
@store: store the size in the node
'''
if self.verbose: if self.verbose:
Logger.info('getting directory size recursively') Logger.info('getting node size recursively')
if node.type == self.TYPE_FILE: if node.type == self.TYPE_FILE:
return node.size return node.size
size = 0 size = 0
for i in node.children: for i in node.children:
if node.type == self.TYPE_DIR: 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: 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: else:
continue continue
node.size = size if store:
node.size = size
return size return size
def rec_size(self, node):
'''recursively traverse tree and store dir size'''
return self._rec_size(node, store=True)
############################################################### ###############################################################
# public helpers # public helpers
############################################################### ###############################################################
@ -280,14 +294,23 @@ class Noder:
hf = utils.human(node.free) hf = utils.human(node.free)
ht = utils.human(node.total) ht = utils.human(node.total)
nbchildren = len(node.children) nbchildren = len(node.children)
# get the date
dt = '' dt = ''
if self._has_attr(node, 'ts'): if self._has_attr(node, 'ts'):
dt = ', date:' dt = 'date:{}'.format(utils.epoch_to_str(node.ts))
dt += 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) name = '{}'.format(node.name)
args = '(nbfiles:{}, free:{}/{}{})'.format(nbchildren, args = [
hf, ht, dt) 'nbfiles:{}'.format(nbchildren),
Logger.storage(pre, name, args, node.attr) 'free:{}/{}'.format(hf, ht),
dt,
ds]
Logger.storage(pre, name, '({})'.format(','.join(args)), node.attr)
elif node.type == self.TYPE_ARC: elif node.type == self.TYPE_ARC:
# archive node # archive node
if self.arc: if self.arc:

Loading…
Cancel
Save