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 path += SEPARATOR
if not path.endswith(WILD): if not path.endswith(WILD):
path += 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): def cmd_rm(args, noder, catalog, top):

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

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

Loading…
Cancel
Save