update storage information on print

pull/11/head
deadc0de6 5 years ago
parent 4c4731e3a6
commit 920ab5a7de

@ -133,7 +133,10 @@ def cmd_ls(args, noder, top):
path += SEPARATOR
if not path.endswith(WILD):
path += WILD
return noder.walk(top, path, rec=args['--recursive'])
found = noder.walk(top, path, rec=args['--recursive'])
if not found:
Logger.err('\"{}\": nothing found'.format(args['<path>']))
return found
def cmd_rm(args, noder, catalog, top):

@ -22,19 +22,24 @@ class Logger:
BOLD = '\033[1m'
UND = '\033[4m'
STORAGE = 'storage'
ARCHIVE = 'archive'
NBFILES = 'nbfiles'
def __init__(self):
pass
######################################################################
# node specific output
######################################################################
def storage(pre, name, attr):
def storage(pre, name, args, attr):
'''print a storage node'''
end = ''
if attr:
end = ' {}({}){}'.format(Logger.GRAY, attr, Logger.RESET)
s = '{}{}storage{}:'.format(pre, Logger.UND, Logger.RESET)
s = '{}{}{}{}:'.format(pre, Logger.UND, Logger.STORAGE, Logger.RESET)
s += ' {}{}{}{}'.format(Logger.PURPLE, name, Logger.RESET, end)
s += ' {}{}{}'.format(Logger.GRAY, args, Logger.RESET)
sys.stdout.write('{}\n'.format(s))
def file(pre, name, attr):
@ -47,7 +52,7 @@ class Logger:
'''print a directory node'''
end = []
if depth != '':
end.append('nbfiles:{}'.format(depth))
end.append('{}:{}'.format(Logger.NBFILES, depth))
if attr:
end.append(' '.join(['{}:{}'.format(x, y) for x, y in attr]))
if end:
@ -58,7 +63,8 @@ class Logger:
def arc(pre, name, archive):
s = '{}{}{}{}'.format(pre, Logger.YELLOW, name, Logger.RESET)
s += ' {}[archive:{}]{}'.format(Logger.GRAY, archive, Logger.RESET)
s += ' {}[{}:{}]{}'.format(Logger.GRAY, Logger.ARCHIVE,
archive, Logger.RESET)
sys.stdout.write('{}\n'.format(s))
######################################################################

@ -235,8 +235,10 @@ class Noder:
@recalcparent: get relpath from tree instead of relpath field
'''
if node.type == self.TYPE_TOP:
# top node
Logger.out('{}{}'.format(pre, node.name))
elif node.type == self.TYPE_FILE:
# node of type file
name = node.name
if withpath:
if recalcparent:
@ -253,6 +255,7 @@ class Noder:
compl += ', storage:{}'.format(Logger.bold(storage.name))
Logger.file(pre, name, compl)
elif node.type == self.TYPE_DIR:
# node of type directory
name = node.name
if withpath:
if recalcparent:
@ -271,20 +274,24 @@ class Noder:
attr.append(['storage', Logger.bold(storage.name)])
Logger.dir(pre, name, depth=depth, attr=attr)
elif node.type == self.TYPE_STORAGE:
# node of type storage
hf = utils.human(node.free)
ht = utils.human(node.total)
nbchildren = len(node.children)
dt = ''
if self._has_attr(node, 'ts'):
dt = ', date:'
dt += utils.epoch_to_str(node.ts)
name = '{} (free:{}, total:{}{})'.format(node.name, hf, ht, dt)
Logger.storage(pre, name, node.attr)
name = '{}'.format(node.name)
args = '(nbfiles:{}, free:{}/{}{})'.format(nbchildren,
hf, ht, dt)
Logger.storage(pre, name, args, node.attr)
elif node.type == self.TYPE_ARC:
# archive node
if self.arc:
Logger.arc(pre, node.name, node.archive)
else:
Logger.err('Weird node encountered: {}'.format(node))
# Logger.out('{}{}'.format(pre, node.name))
Logger.err('bad node encountered: {}'.format(node))
def print_tree(self, node, style=anytree.ContRoundStyle()):
'''print the tree similar to unix tool "tree"'''
@ -347,7 +354,7 @@ class Noder:
return []
if rec:
self.print_tree(found[0].parent)
return
return found
found = sorted(found, key=self._sort, reverse=self.sortsize)
self._print_node(found[0].parent,
withpath=False, withdepth=True)

Loading…
Cancel
Save