Пример #1
0
def format_filetype(path, fdesc, show_type=False, show_md5=False,
        show_timestamp=False):
    """Format a path for printing.

    @type path: str
    @param path: the path
    @type fdesc: list
    @param fdesc: [file_type, timestamp, MD5 sum/symlink target]
        file_type is one of dev, dir, obj, sym, fif.
        If file_type is dir, there is no timestamp or MD5 sum.
        If file_type is sym, fdesc[2] is the target of the symlink.
    @type show_type: bool
    @param show_type: if True, prepend the file's type to the formatted string
    @type show_md5: bool
    @param show_md5: if True, append MD5 sum to the formatted string
    @type show_timestamp: bool
    @param show_timestamp: if True, append time-of-creation after pathname
    @rtype: str
    @return: formatted pathname with optional added information
    """

    ftype = fpath = stamp = md5sum = ""

    if fdesc[0] == "obj":
        ftype = "file"
        fpath = path
        stamp = format_timestamp(fdesc[1])
        md5sum = fdesc[2]
    elif fdesc[0] == "dir":
        ftype = "dir"
        fpath = pp.path(path)
    elif fdesc[0] == "sym":
        ftype = "sym"
        stamp = format_timestamp(fdesc[1])
        tgt = fdesc[2].split()[0]
        if CONFIG["piping"]:
            fpath = path
        else:
            fpath = pp.path_symlink(path + " -> " + tgt)
    elif fdesc[0] == "dev":
        ftype = "dev"
        fpath = path
    elif fdesc[0] == "fif":
        ftype = "fifo"
        fpath = path
    else:
        sys.stderr.write(
            pp.error("%s has unknown type: %s" % (path, fdesc[0]))
        )

    result = ""
    if show_type:
        result += "%4s " % ftype
    result += fpath
    if show_timestamp:
        result += "  " + stamp
    if show_md5:
        result += "  " + md5sum

    return result
Пример #2
0
def format_filetype(path, fdesc, show_type=False, show_md5=False,
		show_timestamp=False):
	"""Format a path for printing.

	@type path: str
	@param path: the path
	@type fdesc: list
	@param fdesc: [file_type, timestamp, MD5 sum/symlink target]
		file_type is one of dev, dir, obj, sym, fif.
		If file_type is dir, there is no timestamp or MD5 sum.
		If file_type is sym, fdesc[2] is the target of the symlink.
	@type show_type: bool
	@param show_type: if True, prepend the file's type to the formatted string
	@type show_md5: bool
	@param show_md5: if True, append MD5 sum to the formatted string
	@type show_timestamp: bool
	@param show_timestamp: if True, append time-of-creation after pathname
	@rtype: str
	@return: formatted pathname with optional added information
	"""

	ftype = fpath = stamp = md5sum = ""

	if fdesc[0] == "obj":
		ftype = "file"
		fpath = path
		stamp = format_timestamp(fdesc[1])
		md5sum = fdesc[2]
	elif fdesc[0] == "dir":
		ftype = "dir"
		fpath = pp.path(path)
	elif fdesc[0] == "sym":
		ftype = "sym"
		stamp = format_timestamp(fdesc[1])
		tgt = fdesc[2].split()[0]
		if CONFIG["piping"]:
			fpath = path
		else:
			fpath = pp.path_symlink(path + " -> " + tgt)
	elif fdesc[0] == "dev":
		ftype = "dev"
		fpath = path
	elif fdesc[0] == "fif":
		ftype = "fifo"
		fpath = path
	else:
		sys.stderr.write(
			pp.error("%s has unknown type: %s" % (path, fdesc[0]))
		)

	result = ""
	if show_type:
		result += "%4s " % ftype
	result += fpath
	if show_timestamp:
		result += "  " + stamp
	if show_md5:
		result += "  " + md5sum

	return result
Пример #3
0
def display_files(contents):
    """Display the content of an installed package.

    @see: gentoolkit.package.Package.parsed_contents
    @type contents: dict
    @param contents: {'path': ['filetype', ...], ...}
    """

    filenames = list(contents.keys())
    filenames.sort()
    last = []

    for name in filenames:
        if QUERY_OPTS["output_tree"]:
            dirdepth = name.count("/")
            indent = " "
            if dirdepth == 2:
                indent = "   "
            elif dirdepth > 2:
                indent = "   " * (dirdepth - 1)

            basename = name.rsplit("/", dirdepth - 1)
            if contents[name][0] == "dir":
                if len(last) == 0:
                    last = basename
                    pp.uprint(pp.path(indent + basename[0]))
                    continue
                for i, directory in enumerate(basename):
                    try:
                        if directory in last[i]:
                            continue
                    except IndexError:
                        pass
                    last = basename
                    if len(last) == 1:
                        pp.uprint(pp.path(indent + last[0]))
                        continue
                    pp.uprint(pp.path(indent + "> /" + last[-1]))
            elif contents[name][0] == "sym":
                pp.uprint(pp.path(indent + "+"), end=" ")
                pp.uprint(pp.path_symlink(basename[-1] + " -> " + contents[name][2]))
            else:
                pp.uprint(pp.path(indent + "+ ") + basename[-1])
        else:
            pp.uprint(
                format_filetype(
                    name,
                    contents[name],
                    show_type=QUERY_OPTS["show_type"],
                    show_md5=QUERY_OPTS["show_MD5"],
                    show_timestamp=QUERY_OPTS["show_timestamp"],
                )
            )
Пример #4
0
def display_files(contents):
	"""Display the content of an installed package.

	@see: gentoolkit.package.Package.parsed_contents
	@type contents: dict
	@param contents: {'path': ['filetype', ...], ...}
	"""

	filenames = list(contents.keys())
	filenames.sort()
	last = []

	for name in filenames:
		if QUERY_OPTS["output_tree"]:
			dirdepth = name.count('/')
			indent = " "
			if dirdepth == 2:
				indent = "   "
			elif dirdepth > 2:
				indent = "   " * (dirdepth - 1)

			basename = name.rsplit("/", dirdepth - 1)
			if contents[name][0] == "dir":
				if len(last) == 0:
					last = basename
					pp.uprint(pp.path(indent + basename[0]))
					continue
				for i, directory in enumerate(basename):
					try:
						if directory in last[i]:
							continue
					except IndexError:
						pass
					last = basename
					if len(last) == 1:
						pp.uprint(pp.path(indent + last[0]))
						continue
					pp.uprint(pp.path(indent + "> /" + last[-1]))
			elif contents[name][0] == "sym":
				pp.uprint(pp.path(indent + "+"), end=' ')
				pp.uprint(pp.path_symlink(basename[-1] + " -> " +
					contents[name][2]))
			else:
				pp.uprint(pp.path(indent + "+ ") + basename[-1])
		else:
			pp.uprint(format_filetype(
				name,
				contents[name],
				show_type=QUERY_OPTS["show_type"],
				show_md5=QUERY_OPTS["show_MD5"],
				show_timestamp=QUERY_OPTS["show_timestamp"]
			))