adding totsize everywhere

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

@ -36,8 +36,8 @@ USAGE = """
{0}
Usage:
{1} index [--catalog=<path>] [--meta=<meta>...] [-acfuV] <name> <path>
{1} update [--catalog=<path>] [-acfuV] <name> <path>
{1} index [--catalog=<path>] [--meta=<meta>...] [-acfnV] <name> <path>
{1} update [--catalog=<path>] [-acfnV] <name> <path>
{1} ls [--catalog=<path>] [-arVS] [<path>]
{1} find [--catalog=<path>] [-abdVP] [--path=<path>] <term>
{1} rm [--catalog=<path>] [-fV] <storage>
@ -53,7 +53,7 @@ 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].
-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['<path>']
name = args['<name>']
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['<path>']
name = args['<name>']
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()

@ -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:

Loading…
Cancel
Save