Exemple #1
0
    def get_tree(self, name=None, backup=None, root=None, agent=None):
        """
        get_tree returns a list of dict representing files/dir (with their attr)
        within a given path
        """
        r = []
        if not name or not backup:
            return r
        if not root:
            top = ''
        else:
            try:
                top = root.decode('utf-8', 'replace')
            except UnicodeDecodeError:
                top = root

        result = self.status('c:{0}:b:{1}:p:{2}\n'.format(name, backup, top))
        if not result:
            return r
        clients = result['clients']
        if not clients:
            return r
        client = clients[0]
        if 'backups' not in client:
            return r
        backups = client['backups']
        if not backups:
            return r
        backup = backups[0]
        for entry in backup['browse']['entries']:
            t = {}
            if entry['name'] == '.':
                continue
            else:
                t['name'] = entry['name']
            t['mode'] = self._human_st_mode(entry['mode'])
            if re.match('^(d|l)', t['mode']):
                t['type'] = 'd'
            else:
                t['type'] = 'f'
            t['inodes'] = entry['nlink']
            t['uid'] = entry['uid']
            t['gid'] = entry['gid']
            t['parent'] = top
            t['size'] = '{0:.1eM}'.format(_hr(entry['size']))
            t['date'] = datetime.datetime.fromtimestamp(entry['mtime']).strftime('%Y-%m-%d %H:%M:%S')
            r.append(t)
        return r
Exemple #2
0
    def get_tree(self, name=None, backup=None, root=None, agent=None):
        """
        get_tree returns a list of dict representing files/dir (with their attr)
        within a given path
        """
        r = []
        if not name or not backup:
            return r
        if not root:
            top = ''
        else:
            try:
                top = root.decode('utf-8', 'replace')
            except UnicodeDecodeError:
                top = root

        f = self.status('c:{0}:b:{1}:p:{2}\n'.format(name, backup, top))
        useful = False
        for line in f:
            if not useful and re.match('^-list begin-$', line):
                useful = True
                continue
            if useful and re.match('^-list end-$', line):
                useful = False
                continue
            if useful:
                t = {}
                m = re.search('^(.{10})\s', line)
                if m:
                    if re.match('^(d|l)', m.group(1)):
                        t['type'] = 'd'
                    else:
                        t['type'] = 'f'
                    sp = re.split('\s+', line, 7)
                    t['mode'] = sp[0]
                    t['inodes'] = sp[1]
                    t['uid'] = sp[2]
                    t['gid'] = sp[3]
                    t['size'] = '{0:.1eM}'.format(_hr(sp[4]))
                    t['date'] = '{0} {1}'.format(sp[5], sp[6])
                    t['name'] = sp[7]
                    t['parent'] = top
                    r.append(t)
        return r
Exemple #3
0
def bytes_human(b):
    return '{0:.1eM}'.format(_hr(b))