Beispiel #1
0
 def getattr(self, path):
     path = argv_bytes(path)
     if self.verbose > 0:
         log('--getattr(%r)\n' % path)
     res = vfs.resolve(self.repo,
                       path,
                       want_meta=(not self.fake_metadata),
                       follow=False)
     name, item = res[-1]
     if not item:
         return -errno.ENOENT
     if self.fake_metadata:
         item = vfs.augment_item_meta(self.repo, item, include_size=True)
     else:
         item = vfs.ensure_item_has_metadata(self.repo,
                                             item,
                                             include_size=True)
     meta = item.meta
     # FIXME: do we want/need to do anything more with nlink?
     st = fuse.Stat(st_mode=meta.mode, st_nlink=1, st_size=meta.size)
     st.st_mode = meta.mode
     st.st_uid = meta.uid or 0
     st.st_gid = meta.gid or 0
     st.st_atime = max(0, xstat.fstime_floor_secs(meta.atime))
     st.st_mtime = max(0, xstat.fstime_floor_secs(meta.mtime))
     st.st_ctime = max(0, xstat.fstime_floor_secs(meta.ctime))
     return st
Beispiel #2
0
def _dir_contents(repo, resolution, show_hidden=False):
    """Yield the display information for the contents of dir_item."""

    url_query = b'?hidden=1' if show_hidden else b''

    def display_info(name,
                     item,
                     resolved_item,
                     display_name=None,
                     omitsize=False):
        global opt
        # link should be based on fully resolved type to avoid extra
        # HTTP redirect.
        link = tornado.escape.url_escape(name, plus=False)
        if stat.S_ISDIR(vfs.item_mode(resolved_item)):
            link += '/'
        link = link.encode('ascii')

        if not omitsize:
            size = vfs.item_size(repo, item)
            if opt.human_readable:
                display_size = format_filesize(size)
            else:
                display_size = size
        else:
            display_size = None

        if not display_name:
            mode = vfs.item_mode(item)
            if stat.S_ISDIR(mode):
                display_name = name + b'/'
                display_size = None
            elif stat.S_ISLNK(mode):
                display_name = name + b'@'
                display_size = None
            else:
                display_name = name

        return display_name, link + url_query, display_size

    dir_item = resolution[-1][1]
    for name, item in vfs.contents(repo, dir_item):
        if not show_hidden:
            if (name not in (b'.', b'..')) and name.startswith(b'.'):
                continue
        if name == b'.':
            parent_item = resolution[-2][1] if len(
                resolution) > 1 else dir_item
            yield display_info(b'..',
                               parent_item,
                               parent_item,
                               b'..',
                               omitsize=True)
            continue
        res_item = vfs.ensure_item_has_metadata(repo, item, include_size=True)
        yield display_info(name, item, res_item)
Beispiel #3
0
 def getattr(self, path):
     global opt
     if self.verbose > 0:
         log('--getattr(%r)\n' % path)
     res = vfs.resolve(self.repo, path, want_meta=(not self.fake_metadata),
                       follow=False)
     name, item = res[-1]
     if not item:
         return -errno.ENOENT
     if self.fake_metadata:
         item = vfs.augment_item_meta(self.repo, item, include_size=True)
     else:
         item = vfs.ensure_item_has_metadata(self.repo, item,
                                             include_size=True)
     meta = item.meta
     # FIXME: do we want/need to do anything more with nlink?
     st = fuse.Stat(st_mode=meta.mode, st_nlink=1, st_size=meta.size)
     st.st_mode = meta.mode
     st.st_uid = meta.uid
     st.st_gid = meta.gid
     st.st_atime = max(0, xstat.fstime_floor_secs(meta.atime))
     st.st_mtime = max(0, xstat.fstime_floor_secs(meta.mtime))
     st.st_ctime = max(0, xstat.fstime_floor_secs(meta.ctime))
     return st
Beispiel #4
0
Datei: ls.py Projekt: jmberg/bup
def show_paths(repo, opt, paths, out, pwd, should_columnate, prefix=b''):
    def item_line(item, name):
        return item_info(item,
                         prefix + name,
                         show_hash=opt.hash,
                         commit_hash=opt.commit_hash,
                         long_fmt=opt.long_listing,
                         classification=opt.classification,
                         numeric_ids=opt.numeric_ids,
                         human_readable=opt.human_readable)

    ret = 0
    want_meta = bool(opt.long_listing or opt.classification)

    pending = []

    last_n = len(paths) - 1
    for n, printpath in enumerate(paths):
        path = posixpath.join(pwd, printpath)
        try:
            if last_n > 0:
                out.write(b'%s:\n' % printpath)

            if opt.directory:
                resolved = vfs.resolve(repo, path, follow=False)
            else:
                resolved = vfs.try_resolve(repo, path, want_meta=want_meta)

            leaf_name, leaf_item = resolved[-1]
            if not leaf_item:
                log('error: cannot access %r in %r\n' %
                    ('/'.join(path_msg(name)
                              for name, item in resolved), path_msg(path)))
                ret = 1
                continue
            if not opt.directory and S_ISDIR(vfs.item_mode(leaf_item)):
                items = vfs.contents(repo, leaf_item, want_meta=want_meta)
                if opt.show_hidden == 'all':
                    # Match non-bup "ls -a ... /".
                    parent = resolved[-2] if len(resolved) > 1 else resolved[0]
                    items = chain(items, ((b'..', parent[1]), ))
                for sub_name, sub_item in sorted(items, key=lambda x: x[0]):
                    if opt.show_hidden != 'all' and sub_name == b'.':
                        continue
                    if sub_name.startswith(b'.') and \
                       opt.show_hidden not in ('almost', 'all'):
                        continue
                    # always skip . and .. in the subfolders - already printed it anyway
                    if prefix and sub_name in (b'.', b'..'):
                        continue
                    if opt.l:
                        sub_item = vfs.ensure_item_has_metadata(
                            repo, sub_item, include_size=True)
                    elif want_meta:
                        sub_item = vfs.augment_item_meta(repo,
                                                         sub_item,
                                                         include_size=True)
                    line = item_line(sub_item, sub_name)
                    if should_columnate:
                        pending.append(line)
                    else:
                        out.write(line)
                        out.write(b'\n')
                    # recurse into subdirectories (apart from . and .., of course)
                    if opt.recursive and S_ISDIR(
                            vfs.item_mode(sub_item)) and sub_name not in (
                                b'.', b'..'):
                        show_paths(repo,
                                   opt, [path + b'/' + sub_name],
                                   out,
                                   pwd,
                                   should_columnate,
                                   prefix=prefix + sub_name + b'/')
            else:
                if opt.long_listing:
                    leaf_item = vfs.augment_item_meta(repo,
                                                      leaf_item,
                                                      include_size=True)
                line = item_line(leaf_item, os.path.normpath(path))
                if should_columnate:
                    pending.append(line)
                else:
                    out.write(line)
                    out.write(b'\n')
        except vfs.IOError as ex:
            log('bup: %s\n' % ex)
            ret = 1

        if pending:
            out.write(columnate(pending, b''))
            pending = []

        if n < last_n:
            out.write(b'\n')

    return ret
Beispiel #5
0
Datei: ls.py Projekt: bup/bup
def within_repo(repo, opt):

    if opt.commit_hash:
        opt.hash = True

    def item_line(item, name):
        return item_info(item, name,
                         show_hash=opt.hash,
                         commit_hash=opt.commit_hash,
                         long_fmt=opt.long_listing,
                         classification=opt.classification,
                         numeric_ids=opt.numeric_ids,
                         human_readable=opt.human_readable)

    ret = 0
    pending = []
    for path in opt.paths:
        try:
            if opt.directory:
                resolved = vfs.resolve(repo, path, follow=False)
            else:
                resolved = vfs.try_resolve(repo, path)

            leaf_name, leaf_item = resolved[-1]
            if not leaf_item:
                log('error: cannot access %r in %r\n'
                    % ('/'.join(name for name, item in resolved),
                       path))
                ret = 1
                continue
            if not opt.directory and S_ISDIR(vfs.item_mode(leaf_item)):
                items = vfs.contents(repo, leaf_item)
                if opt.show_hidden == 'all':
                    # Match non-bup "ls -a ... /".
                    parent = resolved[-2] if len(resolved) > 1 else resolved[0]
                    items = chain(items, (('..', parent[1]),))
                for sub_name, sub_item in sorted(items, key=lambda x: x[0]):
                    if opt.show_hidden != 'all' and sub_name == '.':
                        continue
                    if sub_name.startswith('.') and \
                       opt.show_hidden not in ('almost', 'all'):
                        continue
                    if opt.l:
                        sub_item = vfs.ensure_item_has_metadata(repo, sub_item,
                                                                include_size=True)
                    else:
                        sub_item = vfs.augment_item_meta(repo, sub_item,
                                                         include_size=True)
                    line = item_line(sub_item, sub_name)
                    if not opt.long_listing and istty1:
                        pending.append(line)
                    else:
                        print(line)
            else:
                leaf_item = vfs.augment_item_meta(repo, leaf_item,
                                                  include_size=True)
                line = item_line(leaf_item, os.path.normpath(path))
                if not opt.long_listing and istty1:
                    pending.append(line)
                else:
                    print(line)
        except vfs.IOError as ex:
            log('bup: %s\n' % ex)
            ret = 1

    if pending:
        sys.stdout.write(columnate(pending, ''))

    return ret
Beispiel #6
0
Datei: ls.py Projekt: westes/bup
def within_repo(repo, opt):

    if opt.commit_hash:
        opt.hash = True

    def item_line(item, name):
        return item_info(item,
                         name,
                         show_hash=opt.hash,
                         commit_hash=opt.commit_hash,
                         long_fmt=opt.long_listing,
                         classification=opt.classification,
                         numeric_ids=opt.numeric_ids,
                         human_readable=opt.human_readable)

    ret = 0
    pending = []
    for path in opt.paths:
        try:
            if opt.directory:
                resolved = vfs.resolve(repo, path, follow=False)
            else:
                resolved = vfs.try_resolve(repo, path)

            leaf_name, leaf_item = resolved[-1]
            if not leaf_item:
                log('error: cannot access %r in %r\n' %
                    ('/'.join(name for name, item in resolved), path))
                ret = 1
                continue
            if not opt.directory and S_ISDIR(vfs.item_mode(leaf_item)):
                items = vfs.contents(repo, leaf_item)
                if opt.show_hidden == 'all':
                    # Match non-bup "ls -a ... /".
                    parent = resolved[-2] if len(resolved) > 1 else resolved[0]
                    items = chain(items, (('..', parent[1]), ))
                for sub_name, sub_item in sorted(items, key=lambda x: x[0]):
                    if opt.show_hidden != 'all' and sub_name == '.':
                        continue
                    if sub_name.startswith('.') and \
                       opt.show_hidden not in ('almost', 'all'):
                        continue
                    if opt.l:
                        sub_item = vfs.ensure_item_has_metadata(
                            repo, sub_item, include_size=True)
                    else:
                        sub_item = vfs.augment_item_meta(repo,
                                                         sub_item,
                                                         include_size=True)
                    line = item_line(sub_item, sub_name)
                    if not opt.long_listing and istty1:
                        pending.append(line)
                    else:
                        print(line)
            else:
                leaf_item = vfs.augment_item_meta(repo,
                                                  leaf_item,
                                                  include_size=True)
                line = item_line(leaf_item, os.path.normpath(path))
                if not opt.long_listing and istty1:
                    pending.append(line)
                else:
                    print(line)
        except vfs.IOError as ex:
            log('bup: %s\n' % ex)
            ret = 1

    if pending:
        sys.stdout.write(columnate(pending, ''))

    return ret
Beispiel #7
0
def _dir_contents(repo, resolution, args):
    """Yield the display information for the contents of dir_item."""
    def display_info(name,
                     item,
                     resolved_item,
                     display_name=None,
                     omitsize=False):
        global opt
        # link should be based on fully resolved type to avoid extra
        # HTTP redirect.
        link = tornado.escape.url_escape(name, plus=False)
        if stat.S_ISDIR(vfs.item_mode(resolved_item)):
            link += '/'
        link = link.encode('ascii')

        if not omitsize:
            size = vfs.item_size(repo, item)
            if args.hsizes:
                display_size = format_filesize(size)
            else:
                display_size = size
        else:
            display_size = None

        if not display_name:
            mode = vfs.item_mode(item)
            if stat.S_ISDIR(mode):
                display_name = name + b'/'
                display_size = None
            elif stat.S_ISLNK(mode):
                display_name = name + b'@'
                display_size = None
            else:
                display_name = name

        meta = resolved_item.meta
        if not isinstance(meta, Metadata):
            meta = None
        try:
            oidx = hexlify(resolved_item.oid)
        except AttributeError:
            oidx = ''
        return display_name, link + args, display_size, meta, oidx

    dir_item = resolution[-1][1]
    for name, item in vfs.contents(repo, dir_item):
        if not args.hidden:
            if (name not in (b'.', b'..')) and name.startswith(b'.'):
                continue
        if name == b'.':
            if len(resolution) > 1:
                parent_item = resolution[-2][1] if len(
                    resolution) > 1 else dir_item
                yield display_info(b'..',
                                   parent_item,
                                   parent_item,
                                   b'..',
                                   omitsize=True)
            continue
        res_item = vfs.ensure_item_has_metadata(repo,
                                                item,
                                                include_size=args.meta)
        yield display_info(name, item, res_item, omitsize=not args.meta)