Exemplo n.º 1
0
 def __repr__(self):
     result = ['<%s instance at %s' % (self.__class__, hex(id(self)))]
     if self.path is not None:
         result += ' path:' + repr(self.path)
     if self.mode is not None:
         result += ' mode: %o (%s)' % (self.mode, xstat.mode_str(self.mode))
     if self.uid is not None:
         result += ' uid:' + str(self.uid)
     if self.gid is not None:
         result += ' gid:' + str(self.gid)
     if self.user is not None:
         result += ' user:'******' group:' + repr(self.group)
     if self.size is not None:
         result += ' size:' + repr(self.size)
     for name, val in (('atime', self.atime),
                       ('mtime', self.mtime),
                       ('ctime', self.ctime)):
         if val is not None:
             result += ' %s:%r (%d)' \
                       % (name,
                          strftime('%Y-%m-%d %H:%M %z',
                                   gmtime(xstat.fstime_floor_secs(val))),
                          val)
     result += '>'
     return ''.join(result)
Exemplo n.º 2
0
 def __repr__(self):
     result = ['<%s instance at %s' % (self.__class__, hex(id(self)))]
     if self.path:
         result += ' path:' + repr(self.path)
     if self.mode:
         result += ' mode:' + repr(xstat.mode_str(self.mode)
                                   + '(%s)' % hex(self.mode))
     if self.uid:
         result += ' uid:' + str(self.uid)
     if self.gid:
         result += ' gid:' + str(self.gid)
     if self.user:
         result += ' user:'******' group:' + repr(self.group)
     if self.size:
         result += ' size:' + repr(self.size)
     for name, val in (('atime', self.atime),
                       ('mtime', self.mtime),
                       ('ctime', self.ctime)):
         result += ' %s:%r' \
             % (name,
                time.strftime('%Y-%m-%d %H:%M %z',
                              time.gmtime(xstat.fstime_floor_secs(val))))
     result += '>'
     return ''.join(result)
Exemplo n.º 3
0
def detailed_bytes(meta, fields = None):
    # FIXME: should optional fields be omitted, or empty i.e. "rdev:
    # 0", "link-target:", etc.
    if not fields:
        fields = all_fields

    result = []
    if 'path' in fields:
        path = meta.path or b''
        result.append(b'path: ' + path)
    if 'mode' in fields:
        result.append(b'mode: %o (%s)'
                      % (meta.mode, xstat.mode_str(meta.mode).encode('ascii')))
    if 'link-target' in fields and stat.S_ISLNK(meta.mode):
        result.append(b'link-target: ' + meta.symlink_target)
    if 'rdev' in fields:
        if meta.rdev:
            result.append(b'rdev: %d,%d' % (os.major(meta.rdev),
                                            os.minor(meta.rdev)))
        else:
            result.append(b'rdev: 0')
    if 'size' in fields and meta.size is not None:
        result.append(b'size: %d' % meta.size)
    if 'uid' in fields:
        result.append(b'uid: %d' % meta.uid)
    if 'gid' in fields:
        result.append(b'gid: %d' % meta.gid)
    if 'user' in fields:
        result.append(b'user: '******'group' in fields:
        result.append(b'group: ' + meta.group)
    if 'atime' in fields:
        # If we don't have xstat.lutime, that means we have to use
        # utime(), and utime() has no way to set the mtime/atime of a
        # symlink.  Thus, the mtime/atime of a symlink is meaningless,
        # so let's not report it.  (That way scripts comparing
        # before/after won't trigger.)
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append(b'atime: ' + xstat.fstime_to_sec_bytes(meta.atime))
        else:
            result.append(b'atime: 0')
    if 'mtime' in fields:
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append(b'mtime: ' + xstat.fstime_to_sec_bytes(meta.mtime))
        else:
            result.append(b'mtime: 0')
    if 'ctime' in fields:
        result.append(b'ctime: ' + xstat.fstime_to_sec_bytes(meta.ctime))
    if 'linux-attr' in fields and meta.linux_attr:
        result.append(b'linux-attr: %x' % meta.linux_attr)
    if 'linux-xattr' in fields and meta.linux_xattr:
        for name, value in meta.linux_xattr:
            result.append(b'linux-xattr: %s -> %s' % (name, value))
    if 'posix1e-acl' in fields and meta.posix1e_acl:
        acl = meta.posix1e_acl[0]
        result.append(b'posix1e-acl: ' + acl + b'\n')
        if stat.S_ISDIR(meta.mode):
            def_acl = meta.posix1e_acl[2]
            result.append(b'posix1e-acl-default: ' + def_acl + b'\n')
    return b'\n'.join(result)
Exemplo n.º 4
0
def detailed_str(meta, fields = None):
    # FIXME: should optional fields be omitted, or empty i.e. "rdev:
    # 0", "link-target:", etc.
    if not fields:
        fields = all_fields

    result = []
    if 'path' in fields:
        path = meta.path or ''
        result.append('path: ' + path)
    if 'mode' in fields:
        result.append('mode: %s (%s)' % (oct(meta.mode),
                                         xstat.mode_str(meta.mode)))
    if 'link-target' in fields and stat.S_ISLNK(meta.mode):
        result.append('link-target: ' + meta.symlink_target)
    if 'rdev' in fields:
        if meta.rdev:
            result.append('rdev: %d,%d' % (os.major(meta.rdev),
                                           os.minor(meta.rdev)))
        else:
            result.append('rdev: 0')
    if 'size' in fields and meta.size:
        result.append('size: ' + str(meta.size))
    if 'uid' in fields:
        result.append('uid: ' + str(meta.uid))
    if 'gid' in fields:
        result.append('gid: ' + str(meta.gid))
    if 'user' in fields:
        result.append('user: '******'group' in fields:
        result.append('group: ' + meta.group)
    if 'atime' in fields:
        # If we don't have xstat.lutime, that means we have to use
        # utime(), and utime() has no way to set the mtime/atime of a
        # symlink.  Thus, the mtime/atime of a symlink is meaningless,
        # so let's not report it.  (That way scripts comparing
        # before/after won't trigger.)
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append('atime: ' + xstat.fstime_to_sec_str(meta.atime))
        else:
            result.append('atime: 0')
    if 'mtime' in fields:
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append('mtime: ' + xstat.fstime_to_sec_str(meta.mtime))
        else:
            result.append('mtime: 0')
    if 'ctime' in fields:
        result.append('ctime: ' + xstat.fstime_to_sec_str(meta.ctime))
    if 'linux-attr' in fields and meta.linux_attr:
        result.append('linux-attr: ' + hex(meta.linux_attr))
    if 'linux-xattr' in fields and meta.linux_xattr:
        for name, value in meta.linux_xattr:
            result.append('linux-xattr: %s -> %s' % (name, repr(value)))
    if 'posix1e-acl' in fields and meta.posix1e_acl:
        acl = meta.posix1e_acl[0]
        result.append('posix1e-acl: ' + acl + '\n')
        if stat.S_ISDIR(meta.mode):
            def_acl = meta.posix1e_acl[2]
            result.append('posix1e-acl-default: ' + def_acl + '\n')
    return '\n'.join(result)
Exemplo n.º 5
0
def detailed_str(meta, fields=None):
    # FIXME: should optional fields be omitted, or empty i.e. "rdev:
    # 0", "link-target:", etc.
    if not fields:
        fields = all_fields

    result = []
    if "path" in fields:
        path = meta.path or ""
        result.append("path: " + path)
    if "mode" in fields:
        result.append("mode: %s (%s)" % (oct(meta.mode), xstat.mode_str(meta.mode)))
    if "link-target" in fields and stat.S_ISLNK(meta.mode):
        result.append("link-target: " + meta.symlink_target)
    if "rdev" in fields:
        if meta.rdev:
            result.append("rdev: %d,%d" % (os.major(meta.rdev), os.minor(meta.rdev)))
        else:
            result.append("rdev: 0")
    if "size" in fields and meta.size:
        result.append("size: " + str(meta.size))
    if "uid" in fields:
        result.append("uid: " + str(meta.uid))
    if "gid" in fields:
        result.append("gid: " + str(meta.gid))
    if "user" in fields:
        result.append("user: "******"group" in fields:
        result.append("group: " + meta.group)
    if "atime" in fields:
        # If we don't have xstat.lutime, that means we have to use
        # utime(), and utime() has no way to set the mtime/atime of a
        # symlink.  Thus, the mtime/atime of a symlink is meaningless,
        # so let's not report it.  (That way scripts comparing
        # before/after won't trigger.)
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append("atime: " + xstat.fstime_to_sec_str(meta.atime))
        else:
            result.append("atime: 0")
    if "mtime" in fields:
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append("mtime: " + xstat.fstime_to_sec_str(meta.mtime))
        else:
            result.append("mtime: 0")
    if "ctime" in fields:
        result.append("ctime: " + xstat.fstime_to_sec_str(meta.ctime))
    if "linux-attr" in fields and meta.linux_attr:
        result.append("linux-attr: " + hex(meta.linux_attr))
    if "linux-xattr" in fields and meta.linux_xattr:
        for name, value in meta.linux_xattr:
            result.append("linux-xattr: %s -> %s" % (name, repr(value)))
    if "posix1e-acl" in fields and meta.posix1e_acl:
        acl = meta.posix1e_acl[0]
        result.append("posix1e-acl: " + acl + "\n")
        if stat.S_ISDIR(meta.mode):
            def_acl = meta.posix1e_acl[2]
            result.append("posix1e-acl-default: " + def_acl + "\n")
    return "\n".join(result)
Exemplo n.º 6
0
Arquivo: metadata.py Projeto: bup/bup
def summary_bytes(meta,
                  numeric_ids=False,
                  classification=None,
                  human_readable=False):
    """Return bytes containing the "ls -l" style listing for meta.
    Classification may be "all", "type", or None."""
    user_str = group_str = size_or_dev_str = b'?'
    symlink_target = None
    if meta:
        name = meta.path
        mode_str = xstat.mode_str(meta.mode).encode('ascii')
        symlink_target = meta.symlink_target
        mtime_secs = xstat.fstime_floor_secs(meta.mtime)
        mtime_str = strftime('%Y-%m-%d %H:%M',
                             time.localtime(mtime_secs)).encode('ascii')
        if meta.user and not numeric_ids:
            user_str = meta.user
        elif meta.uid != None:
            user_str = str(meta.uid).encode()
        if meta.group and not numeric_ids:
            group_str = meta.group
        elif meta.gid != None:
            group_str = str(meta.gid).encode()
        if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
            if meta.rdev:
                size_or_dev_str = (
                    '%d,%d' %
                    (os.major(meta.rdev), os.minor(meta.rdev))).encode()
        elif meta.size != None:
            if human_readable:
                size_or_dev_str = format_filesize(meta.size).encode()
            else:
                size_or_dev_str = str(meta.size).encode()
        else:
            size_or_dev_str = b'-'
        if classification:
            classification_str = \
                xstat.classification_str(meta.mode,
                                         classification == 'all').encode()
    else:
        mode_str = b'?' * 10
        mtime_str = b'????-??-?? ??:??'
        classification_str = b'?'

    name = name or b''
    if classification:
        name += classification_str
    if symlink_target:
        name += b' -> ' + meta.symlink_target

    return b'%-10s %-11s %11s %16s %s' % (mode_str,
                                          user_str + b'/' + group_str,
                                          size_or_dev_str, mtime_str, name)
Exemplo n.º 7
0
def summary_str(meta, numeric_ids = False, classification = None,
                human_readable = False):

    """Return a string containing the "ls -l" style listing for meta.
    Classification may be "all", "type", or None."""
    user_str = group_str = size_or_dev_str = '?'
    symlink_target = None
    if meta:
        name = meta.path
        mode_str = xstat.mode_str(meta.mode)
        symlink_target = meta.symlink_target
        mtime_secs = xstat.fstime_floor_secs(meta.mtime)
        mtime_str = time.strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
        if meta.user and not numeric_ids:
            user_str = meta.user
        elif meta.uid != None:
            user_str = str(meta.uid)
        if meta.group and not numeric_ids:
            group_str = meta.group
        elif meta.gid != None:
            group_str = str(meta.gid)
        if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
            if meta.rdev:
                size_or_dev_str = '%d,%d' % (os.major(meta.rdev),
                                             os.minor(meta.rdev))
        elif meta.size != None:
            if human_readable:
                size_or_dev_str = format_filesize(meta.size)
            else:
                size_or_dev_str = str(meta.size)
        else:
            size_or_dev_str = '-'
        if classification:
            classification_str = \
                xstat.classification_str(meta.mode, classification == 'all')
    else:
        mode_str = '?' * 10
        mtime_str = '????-??-?? ??:??'
        classification_str = '?'

    name = name or ''
    if classification:
        name += classification_str
    if symlink_target:
        name += ' -> ' + meta.symlink_target

    return '%-10s %-11s %11s %16s %s' % (mode_str,
                                         user_str + "/" + group_str,
                                         size_or_dev_str,
                                         mtime_str,
                                         name)
Exemplo n.º 8
0
Arquivo: metadata.py Projeto: niun/bup
 def __repr__(self):
     result = ["<%s instance at %s" % (self.__class__, hex(id(self)))]
     if self.path:
         result += " path:" + repr(self.path)
     if self.mode:
         result += " mode:" + repr(xstat.mode_str(self.mode) + "(%s)" % hex(self.mode))
     if self.uid:
         result += " uid:" + str(self.uid)
     if self.gid:
         result += " gid:" + str(self.gid)
     if self.user:
         result += " user:"******" group:" + repr(self.group)
     if self.size:
         result += " size:" + repr(self.size)
     for name, val in (("atime", self.atime), ("mtime", self.mtime), ("ctime", self.ctime)):
         result += " %s:%r" % (name, time.strftime("%Y-%m-%d %H:%M %z", time.gmtime(xstat.fstime_floor_secs(val))))
     result += ">"
     return "".join(result)
Exemplo n.º 9
0
def summary_str(meta):
    mode_val = xstat.mode_str(meta.mode)
    user_val = meta.user
    if not user_val:
        user_val = str(meta.uid)
    group_val = meta.group
    if not group_val:
        group_val = str(meta.gid)
    size_or_dev_val = '-'
    if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
        size_or_dev_val = '%d,%d' % (os.major(meta.rdev), os.minor(meta.rdev))
    elif meta.size:
        size_or_dev_val = meta.size
    mtime_secs = xstat.fstime_floor_secs(meta.mtime)
    time_val = time.strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
    path_val = meta.path or ''
    if stat.S_ISLNK(meta.mode):
        path_val += ' -> ' + meta.symlink_target
    return '%-10s %-11s %11s %16s %s' % (mode_val, user_val + "/" + group_val,
                                         size_or_dev_val, time_val, path_val)
Exemplo n.º 10
0
def summary_str(meta, numeric_ids=False, human_readable=False):
    mode_val = xstat.mode_str(meta.mode)
    user_val = meta.user
    if numeric_ids or not user_val:
        user_val = str(meta.uid)
    group_val = meta.group
    if numeric_ids or not group_val:
        group_val = str(meta.gid)
    size_or_dev_val = "-"
    if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
        size_or_dev_val = "%d,%d" % (os.major(meta.rdev), os.minor(meta.rdev))
    elif meta.size != None:
        size_or_dev_val = meta.size
        if human_readable:
            size_or_dev_val = format_filesize(meta.size)
    mtime_secs = xstat.fstime_floor_secs(meta.mtime)
    time_val = time.strftime("%Y-%m-%d %H:%M", time.localtime(mtime_secs))
    path_val = meta.path or ""
    if stat.S_ISLNK(meta.mode):
        path_val += " -> " + meta.symlink_target
    return "%-10s %-11s %11s %16s %s" % (mode_val, user_val + "/" + group_val, size_or_dev_val, time_val, path_val)
Exemplo n.º 11
0
def summary_str(meta):
    mode_val = xstat.mode_str(meta.mode)
    user_val = meta.user
    if not user_val:
        user_val = str(meta.uid)
    group_val = meta.group
    if not group_val:
        group_val = str(meta.gid)
    size_or_dev_val = '-'
    if stat.S_ISCHR(meta.mode) or stat.S_ISBLK(meta.mode):
        size_or_dev_val = '%d,%d' % (os.major(meta.rdev), os.minor(meta.rdev))
    elif meta.size:
        size_or_dev_val = meta.size
    mtime_secs = xstat.fstime_floor_secs(meta.mtime)
    time_val = time.strftime('%Y-%m-%d %H:%M', time.localtime(mtime_secs))
    path_val = meta.path or ''
    if stat.S_ISLNK(meta.mode):
        path_val += ' -> ' + meta.symlink_target
    return '%-10s %-11s %11s %16s %s' % (mode_val,
                                         user_val + "/" + group_val,
                                         size_or_dev_val,
                                         time_val,
                                         path_val)
Exemplo n.º 12
0
def _get_mode(node):
    return xstat.mode_str(node.mode_meta_default())
Exemplo n.º 13
0
def detailed_str(meta, fields = None):
    # FIXME: should optional fields be omitted, or empty i.e. "rdev:
    # 0", "link-target:", etc.
    if not fields:
        fields = all_fields

    result = []
    if 'path' in fields:
        path = meta.path or ''
        result.append('path: ' + path)
    if 'mode' in fields:
        result.append('mode: %s (%s)' % (oct(meta.mode),
                                         xstat.mode_str(meta.mode)))
    if 'link-target' in fields and stat.S_ISLNK(meta.mode):
        result.append('link-target: ' + meta.symlink_target)
    if 'rdev' in fields:
        if meta.rdev:
            result.append('rdev: %d,%d' % (os.major(meta.rdev),
                                           os.minor(meta.rdev)))
        else:
            result.append('rdev: 0')
    if 'size' in fields and meta.size:
        result.append('size: ' + str(meta.size))
    if 'uid' in fields:
        result.append('uid: ' + str(meta.uid))
    if 'gid' in fields:
        result.append('gid: ' + str(meta.gid))
    if 'user' in fields:
        result.append('user: '******'group' in fields:
        result.append('group: ' + meta.group)
    if 'atime' in fields:
        # If we don't have xstat.lutime, that means we have to use
        # utime(), and utime() has no way to set the mtime/atime of a
        # symlink.  Thus, the mtime/atime of a symlink is meaningless,
        # so let's not report it.  (That way scripts comparing
        # before/after won't trigger.)
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append('atime: ' + xstat.fstime_to_sec_str(meta.atime))
        else:
            result.append('atime: 0')
    if 'mtime' in fields:
        if xstat.lutime or not stat.S_ISLNK(meta.mode):
            result.append('mtime: ' + xstat.fstime_to_sec_str(meta.mtime))
        else:
            result.append('mtime: 0')
    if 'ctime' in fields:
        result.append('ctime: ' + xstat.fstime_to_sec_str(meta.ctime))
    if 'linux-attr' in fields and meta.linux_attr:
        result.append('linux-attr: ' + hex(meta.linux_attr))
    if 'linux-xattr' in fields and meta.linux_xattr:
        for name, value in meta.linux_xattr:
            result.append('linux-xattr: %s -> %s' % (name, repr(value)))
    if 'posix1e-acl' in fields and meta.posix1e_acl and posix1e:
        flags = posix1e.TEXT_ABBREVIATE
        if stat.S_ISDIR(meta.mode):
            acl = meta.posix1e_acl[0]
            default_acl = meta.posix1e_acl[2]
            result.append(acl.to_any_text('posix1e-acl: ', '\n', flags))
            result.append(acl.to_any_text('posix1e-acl-default: ', '\n', flags))
        else:
            acl = meta.posix1e_acl[0]
            result.append(acl.to_any_text('posix1e-acl: ', '\n', flags))
    return '\n'.join(result)
Exemplo n.º 14
0
 def mode_str(self):
     return xstat.mode_str(self.mode)