示例#1
0
def fmt_iso(timestamp):
    """ Format a UNIX timestamp to an ISO datetime string.
    """
    try:
        return fmt.iso_datetime(timestamp)
    except (ValueError, TypeError):
        return "N/A".rjust(len(fmt.iso_datetime(0)))
示例#2
0
def fmt_iso(timestamp):
    """ Format a UNIX timestamp to an ISO datetime string.
    """
    try:
        return fmt.iso_datetime(timestamp)
    except (ValueError, TypeError):
        return "N/A".rjust(len(fmt.iso_datetime(0)))
示例#3
0
def _fmt_files(filelist):
    """ Produce a file listing.
    """
    depth = max(i.path.count('/') for i in filelist)
    pad = [u'\uFFFE'] * depth

    base_indent = ' ' * 38
    indent = 0
    result = []
    prev_path = pad
    sorted_files = sorted(
        (i.path.split('/')[:-1] + pad, i.path.rsplit('/', 1)[-1], i)
        for i in filelist)

    for path, name, fileinfo in sorted_files:
        path = path[:depth]
        if path != prev_path:
            common = min([depth] + [
                idx for idx, (dirname,
                              prev_name) in enumerate(zip(path, prev_path))
                if dirname != prev_name
            ])
            #result.append("!!%r %r" % (indent, common))
            #result.append("!!%r" % (prev_path,))
            #result.append("!!%r" % (path,))

            while indent > common:
                indent -= 1
                result.append("%s%s/" % (base_indent, ' ' * indent))

            for dirname in path[common:]:
                if dirname == u'\uFFFE':
                    break
                result.append("%s%s\\ %s" %
                              (base_indent, ' ' * indent, dirname))
                indent += 1

        ##result.append("!!%r %r" % (path, name))
        result.append("  %s %s %s %s| %s" % (
            {
                0: "off ",
                1: "    ",
                2: "high"
            }.get(fileinfo.prio, "????"),
            fmt.iso_datetime(fileinfo.mtime),
            fmt.human_size(fileinfo.size),
            ' ' * indent,
            name,
        ))

        prev_path = path

    while indent > 0:
        indent -= 1
        result.append("%s%s/" % (base_indent, ' ' * indent))
    result.append("%s= %d file(s)" % (base_indent, len(filelist)))

    return '\n'.join(result)
示例#4
0
def _fmt_files(filelist):
    """ Produce a file listing.
    """
    depth = max(i.path.count("/") for i in filelist)
    pad = [u"\uFFFE"] * depth

    base_indent = " " * 38
    indent = 0
    result = []
    prev_path = pad
    sorted_files = sorted((i.path.split("/")[:-1] + pad, i.path.rsplit("/", 1)[-1], i) for i in filelist)

    for path, name, fileinfo in sorted_files:
        path = path[:depth]
        if path != prev_path:
            common = min(
                [depth] + [idx for idx, (dirname, prev_name) in enumerate(zip(path, prev_path)) if dirname != prev_name]
            )
            # result.append("!!%r %r" % (indent, common))
            # result.append("!!%r" % (prev_path,))
            # result.append("!!%r" % (path,))

            while indent > common:
                indent -= 1
                result.append("%s%s/" % (base_indent, " " * indent))

            for dirname in path[common:]:
                if dirname == u"\uFFFE":
                    break
                result.append("%s%s\\ %s" % (base_indent, " " * indent, dirname))
                indent += 1

        ##result.append("!!%r %r" % (path, name))
        result.append(
            "  %s %s %s %s| %s"
            % (
                {0: "off ", 1: "    ", 2: "high"}.get(fileinfo.prio, "????"),
                fmt.iso_datetime(fileinfo.mtime),
                fmt.human_size(fileinfo.size),
                " " * indent,
                name,
            )
        )

        prev_path = path

    while indent > 0:
        indent -= 1
        result.append("%s%s/" % (base_indent, " " * indent))
    result.append("%s= %d file(s)" % (base_indent, len(filelist)))

    return "\n".join(result)