Example #1
0
 def _print_node(self, node, pre='', withpath=False,
                 withdepth=False, withstorage=False):
     '''print a node'''
     if node.type == self.TYPE_TOP:
         Logger.out('{}{}'.format(pre, node.name))
     elif node.type == self.TYPE_FILE:
         name = node.name
         if withpath:
             name = node.relpath
         if withstorage:
             storage = self._get_storage(node)
         attr = ''
         if node.md5:
             attr = ', md5:{}'.format(node.md5)
         compl = 'size:{}{}'.format(utils.human(node.size), attr)
         if withstorage:
             compl += ', storage:{}'.format(Logger.bold(storage.name))
         Logger.file(pre, name, compl)
     elif node.type == self.TYPE_DIR:
         name = node.name
         if withpath:
             name = node.relpath
         depth = ''
         if withdepth:
             depth = len(node.children)
         if withstorage:
             storage = self._get_storage(node)
         attr = []
         if node.size:
             attr.append(['totsize', utils.human(node.size)])
         if withstorage:
             attr.append(['storage', Logger.bold(storage.name)])
         Logger.dir(pre, name, depth=depth, attr=attr)
     elif node.type == self.TYPE_STORAGE:
         hf = utils.human(node.free)
         ht = utils.human(node.total)
         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)
     elif node.type == self.TYPE_ARC:
         if self.arc:
             Logger.arc(pre, node.name, node.archive)
     else:
         Logger.err('Weird node encountered: {}'.format(node))
Example #2
0
File: noder.py Project: birt/catcli
 def _print_node(self,
                 node,
                 pre='',
                 withpath=False,
                 withdepth=False,
                 withstorage=False,
                 recalcparent=False):
     '''
     print a node
     @node: the node to print
     @pre: string to print before node
     @withpath: print the node path
     @withdepth: print the node depth info
     @withstorage: print the node storage it belongs to
     @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:
                 name = os.sep.join([self._get_parents(node.parent), name])
             else:
                 name = node.relpath
         name = name.lstrip(os.sep)
         if withstorage:
             storage = self._get_storage(node)
         attr = ''
         if node.md5:
             attr = ', md5:{}'.format(node.md5)
         compl = 'size:{}{}'.format(utils.human(node.size), attr)
         if withstorage:
             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:
                 name = os.sep.join([self._get_parents(node.parent), name])
             else:
                 name = node.relpath
         name = name.lstrip(os.sep)
         depth = ''
         if withdepth:
             depth = len(node.children)
         if withstorage:
             storage = self._get_storage(node)
         attr = []
         if node.size:
             attr.append(['totsize', utils.human(node.size)])
         if withstorage:
             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)
         # get the date
         dt = ''
         if self._has_attr(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:{}'.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:
             Logger.arc(pre, node.name, node.archive)
     else:
         Logger.err('bad node encountered: {}'.format(node))