Beispiel #1
0
def display_useflags(query, pkg):
    """Display USE flag information for a given package."""

    try:
        useflags = [x.lstrip("+-") for x in pkg.environment("IUSE").split()]
    except errors.GentoolkitFatalError:
        # aux_get KeyError or other unexpected result
        return False

    if query not in useflags:
        return False

    if CONFIG['verbose']:
        pkgstr = PackageFormatter(pkg,
                                  do_format=True,
                                  custom_format=QUERY_OPTS["package_format"])
    else:
        pkgstr = PackageFormatter(pkg,
                                  do_format=False,
                                  custom_format=QUERY_OPTS["package_format"])

    if (QUERY_OPTS["in_installed"] and not QUERY_OPTS["in_porttree"]
            and not QUERY_OPTS["in_overlay"]):
        if not 'I' in pkgstr.location:
            return False
    if (QUERY_OPTS["in_porttree"] and not QUERY_OPTS["in_overlay"]):
        if not 'P' in pkgstr.location:
            return False
    if (QUERY_OPTS["in_overlay"] and not QUERY_OPTS["in_porttree"]):
        if not 'O' in pkgstr.location:
            return False
    pp.uprint(pkgstr)

    return True
Beispiel #2
0
def display_pkg(query, env_var, pkg):
    """Display information for a given package."""

    if CONFIG['verbose']:
        pkgstr = PackageFormatter(pkg,
                                  do_format=True,
                                  custom_format=QUERY_OPTS["package_format"])
    else:
        pkgstr = PackageFormatter(pkg,
                                  do_format=False,
                                  custom_format=QUERY_OPTS["package_format"])

    if (QUERY_OPTS["in_installed"] and not QUERY_OPTS["in_porttree"]
            and not QUERY_OPTS["in_overlay"]):
        if not 'I' in pkgstr.location:
            return False
    if (QUERY_OPTS["in_porttree"] and not QUERY_OPTS["in_overlay"]):
        if not 'P' in pkgstr.location:
            return False
    if (QUERY_OPTS["in_overlay"] and not QUERY_OPTS["in_porttree"]):
        if not 'O' in pkgstr.location:
            return False
    pp.uprint(pkgstr)

    return True
Beispiel #3
0
    def print_formated(pkg):
        """Print pkg as formatted output depending on CONFIG."""

        if None is pkg:
            return

        if CONFIG['verbose']:
            print(
                PackageFormatter(pkg,
                                 do_format=True,
                                 custom_format=QUERY_OPTS["package_format"]))
        else:
            print(
                PackageFormatter(pkg,
                                 do_format=False,
                                 custom_format=QUERY_OPTS["package_format"]))
Beispiel #4
0
def main(input_args):
	"""Parse input and run the program"""

	short_opts = "hdbefiImopF:" # -i, -e were options for default actions

	# 04/09: djanderson
	# --all is no longer needed. Kept for compatibility.
	# --installed is no longer needed. Kept for compatibility.
	# --exact-name is no longer needed. Kept for compatibility.
	long_opts = ('help', 'all', 'installed', 'exclude-installed',
		'mask-reason', 'portage-tree', 'overlay-tree', 'format=', 'full-regex',
		'exact-name', 'duplicates', 'binpkgs-missing')

	try:
		module_opts, queries = gnu_getopt(input_args, short_opts, long_opts)
	except GetoptError as err:
		sys.stderr.write(pp.error("Module %s" % err))
		print()
		print_help(with_description=False)
		sys.exit(2)

	parse_module_options(module_opts)

	# Only search installed packages when listing duplicate or missing binary packages
	if QUERY_OPTS["duplicates"] or QUERY_OPTS["binpkgs-missing"]:
		QUERY_OPTS["in_installed"] = True
		QUERY_OPTS["in_porttree"] = False
		QUERY_OPTS["in_overlay"] = False
		QUERY_OPTS["include_mask_reason"] = False

	if not queries:
		print_help()
		sys.exit(2)

	first_run = True
	for query in (Query(x, QUERY_OPTS['is_regex']) for x in queries):
		if not first_run:
			print()

		# if we are in quiet mode, do not raise GentoolkitNoMatches exception
		# instead we raise GentoolkitNonZeroExit to exit with an exit value of 3
		try:
			matches = query.smart_find(**QUERY_OPTS)
		except errors.GentoolkitNoMatches:
			if CONFIG['verbose']:
				raise
			else:
				raise errors.GentoolkitNonZeroExit(3)

		# Find duplicate packages
		if QUERY_OPTS["duplicates"]:
			matches = get_duplicates(matches)

		# Find missing binary packages
		if QUERY_OPTS["binpkgs-missing"]:
			matches = get_binpkgs_missing(matches)

		matches.sort()

		#
		# Output
		#

		for pkg in matches:
			pkgstr = PackageFormatter(
				pkg,
				do_format=CONFIG['verbose'],
				custom_format=QUERY_OPTS["package_format"]
			)

			if (QUERY_OPTS["in_porttree"] and
				not QUERY_OPTS["in_overlay"]):
				if not 'P' in pkgstr.location:
					continue
			if (QUERY_OPTS["in_overlay"] and
				not QUERY_OPTS["in_porttree"]):
				if not 'O' in pkgstr.location:
					continue
			pp.uprint(pkgstr)

			if QUERY_OPTS["include_mask_reason"]:
				ms_int, ms_orig = pkgstr.format_mask_status()
				if ms_int < 3:
					# ms_int is a number representation of mask level.
					# Only 2 and above are "hard masked" and have reasons.
					continue
				mask_reason = pkg.mask_reason()
				if not mask_reason:
					# Package not on system or not masked
					continue
				elif not any(mask_reason):
					print(" * No mask reason given")
				else:
					status = ', '.join(ms_orig)
					explanation = mask_reason[0]
					mask_location = mask_reason[1]
					pp.uprint(" * Masked by %r" % status)
					pp.uprint(" * %s:" % mask_location)
					pp.uprint('\n'.join(
						[' * %s' % line.lstrip(' #')
							for line in explanation.splitlines()]
						))

		first_run = False
Beispiel #5
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "hdbefiImopF:"  # -i, -e were options for default actions

    # 04/09: djanderson
    # --all is no longer needed. Kept for compatibility.
    # --installed is no longer needed. Kept for compatibility.
    # --exact-name is no longer needed. Kept for compatibility.
    long_opts = ('help', 'all', 'installed', 'exclude-installed',
                 'mask-reason', 'portage-tree', 'overlay-tree', 'format=',
                 'full-regex', 'exact-name', 'duplicates', 'binpkgs-missing')

    try:
        module_opts, queries = gnu_getopt(input_args, short_opts, long_opts)
    except GetoptError as err:
        sys.stderr.write(pp.error("Module %s" % err))
        print()
        print_help(with_description=False)
        sys.exit(2)

    parse_module_options(module_opts)

    # Only search installed packages when listing duplicate or missing binary packages
    if QUERY_OPTS["duplicates"] or QUERY_OPTS["binpkgs-missing"]:
        QUERY_OPTS["in_installed"] = True
        QUERY_OPTS["in_porttree"] = False
        QUERY_OPTS["in_overlay"] = False
        QUERY_OPTS["include_mask_reason"] = False

    if not queries:
        print_help()
        sys.exit(2)

    first_run = True
    for query in (Query(x, QUERY_OPTS['is_regex']) for x in queries):
        if not first_run:
            print()

        # if we are in quiet mode, do not raise GentoolkitNoMatches exception
        # instead we raise GentoolkitNonZeroExit to exit with an exit value of 3
        try:
            matches = query.smart_find(**QUERY_OPTS)
        except errors.GentoolkitNoMatches:
            if CONFIG['verbose']:
                raise
            else:
                raise errors.GentoolkitNonZeroExit(3)

        # Find duplicate packages
        if QUERY_OPTS["duplicates"]:
            matches = get_duplicates(matches)

        # Find missing binary packages
        if QUERY_OPTS["binpkgs-missing"]:
            matches = get_binpkgs_missing(matches)

        matches.sort()

        #
        # Output
        #

        for pkg in matches:
            pkgstr = PackageFormatter(
                pkg,
                do_format=CONFIG['verbose'],
                custom_format=QUERY_OPTS["package_format"])

            if (QUERY_OPTS["in_porttree"] and not QUERY_OPTS["in_overlay"]):
                if not 'P' in pkgstr.location:
                    continue
            if (QUERY_OPTS["in_overlay"] and not QUERY_OPTS["in_porttree"]):
                if not 'O' in pkgstr.location:
                    continue
            pp.uprint(pkgstr)

            if QUERY_OPTS["include_mask_reason"]:
                ms_int, ms_orig = pkgstr.format_mask_status()
                if ms_int < 3:
                    # ms_int is a number representation of mask level.
                    # Only 2 and above are "hard masked" and have reasons.
                    continue
                mask_reason = pkg.mask_reason()
                if not mask_reason:
                    # Package not on system or not masked
                    continue
                elif not any(mask_reason):
                    print(" * No mask reason given")
                else:
                    status = ', '.join(ms_orig)
                    explanation = mask_reason[0]
                    mask_location = mask_reason[1]
                    pp.uprint(" * Masked by %r" % status)
                    pp.uprint(" * %s:" % mask_location)
                    pp.uprint('\n'.join([
                        ' * %s' % line.lstrip(' #')
                        for line in explanation.splitlines()
                    ]))

        first_run = False