コード例 #1
0
ファイル: uses.py プロジェクト: pamxy/gentoolkit
def main(input_args):
	"""Parse input and run the program"""

	short_opts = "hai"
	long_opts = ('help', 'all', 'ignore-linguas')

	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)

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

	#
	# Output
	#

	first_run = True
	legend_printed = False
	for query in (Query(x) for x in queries):
		if not first_run:
			print()

		if QUERY_OPTS["all_versions"]:
			matches = query.find(include_masked=True)
		else:
			matches = [query.find_best()]

		if not any(matches):
			raise errors.GentoolkitNoMatches(query)

		matches.sort()

		global_usedesc = get_global_useflags()
		for pkg in matches:

			output = get_output_descriptions(pkg, global_usedesc)
			if output:
				if CONFIG['verbose']:
					if not legend_printed:
						print_legend()
						legend_printed = True
					print((" * Found these USE flags for %s:" %
						pp.cpv(str(pkg.cpv))))
					print(pp.emph(" U I"))
				display_useflags(output)
			else:
				if CONFIG['verbose']:
					sys.stderr.write(
						pp.warn("No USE flags found for %s" % pp.cpv(pkg.cpv))
					)

		first_run = False
コード例 #2
0
    def smart_find(self,
                   in_installed=True,
                   in_porttree=True,
                   in_overlay=True,
                   include_masked=True,
                   show_progress=True,
                   no_matches_fatal=True,
                   **kwargs):
        """A high-level wrapper around gentoolkit package-finder functions.

		@type in_installed: bool
		@param in_installed: search for query in VARDB
		@type in_porttree: bool
		@param in_porttree: search for query in PORTDB
		@type in_overlay: bool
		@param in_overlay: search for query in overlays
		@type show_progress: bool
		@param show_progress: output search progress
		@type no_matches_fatal: bool
		@param no_matches_fatal: raise errors.GentoolkitNoMatches
		@rtype: list
		@return: Package objects matching query
		"""

        if in_installed:
            if in_porttree or in_overlay:
                simple_package_finder = partial(self.find,
                                                include_masked=include_masked)
                complex_package_finder = helpers.get_cpvs
            else:
                simple_package_finder = self.find_installed
                complex_package_finder = helpers.get_installed_cpvs
        elif in_porttree or in_overlay:
            simple_package_finder = partial(self.find,
                                            include_masked=include_masked,
                                            in_installed=False)
            complex_package_finder = helpers.get_uninstalled_cpvs
        else:
            raise errors.GentoolkitFatalError(
                "Not searching in installed, Portage tree, or overlay. "
                "Nothing to do.")

        if self.query_type == "set":
            self.package_finder = simple_package_finder
            matches = self._do_set_lookup(show_progress=show_progress)
        elif self.query_type == "simple":
            self.package_finder = simple_package_finder
            matches = self._do_simple_lookup(in_installed=in_installed,
                                             show_progress=show_progress)
        else:
            self.package_finder = complex_package_finder
            matches = self._do_complex_lookup(show_progress=show_progress)

        if self.repo_filter is not None:
            matches = self._filter_by_repository(matches)

        if no_matches_fatal and not matches:
            ii = in_installed and not (in_porttree or in_overlay)
            raise errors.GentoolkitNoMatches(self.query, in_installed=ii)
        return matches
コード例 #3
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "hme"
    long_opts = ('help', 'include-masked', 'ebuild')

    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)

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

    for query in (Query(x) for x in queries):
        matches = query.find(include_masked=QUERY_OPTS['include_masked'],
                             in_installed=False)
        if matches:
            pkg = sorted(matches).pop()
            ebuild_path = pkg.ebuild_path()
            if ebuild_path:
                pp.uprint(os.path.normpath(ebuild_path))
                if QUERY_OPTS['ebuild']:
                    print_ebuild(ebuild_path)
            else:
                sys.stderr.write(pp.warn("No ebuilds to satisfy %s" % pkg.cpv))
        else:
            raise errors.GentoolkitNoMatches(query)
コード例 #4
0
ファイル: meta.py プロジェクト: clayne/gentoolkit
def main(input_args):
    """Parse input and run the program."""

    short_opts = "hdHklmrSuUx"
    long_opts = (
        "help",
        "description",
        "herd",
        "keywords",
        "license",
        "maintainer",
        "reverse",
        "stablereq",
        "useflags",
        "upstream",
        "xml",
    )

    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)

    # Find queries' Portage directory and throw error if invalid
    if not queries:
        print_help()
        sys.exit(2)

    first_run = True
    for query in (Query(x) for x in queries):
        best_match = query.find_best()
        matches = query.find(include_masked=True)
        if best_match is None or not matches:
            raise errors.GentoolkitNoMatches(query)

        if best_match.metadata is None:
            print(
                pp.warn("Package {0} is missing "
                        "metadata.xml".format(best_match.cpv)),
                file=sys.stderr,
            )
            continue

        if not first_run:
            print()

        matches.sort()
        matches.sort(reverse=any(name in ("-r", "--reverse")
                                 for name, opt in module_opts))
        call_format_functions(best_match, matches)

        first_run = False
コード例 #5
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "hAMUl"
    long_opts = ("help", "no-atom", "no-useflags", "no-mask", "depth=")

    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)

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

    #
    # Output
    #

    first_run = True
    for query in (Query(x) for x in queries):
        if not first_run:
            print()

        matches = query.smart_find(**QUERY_OPTS)

        if not matches:
            raise errors.GentoolkitNoMatches(query)

        matches.sort()

        if CONFIG["verbose"]:
            printer = partial(
                depgraph_printer,
                no_atom=QUERY_OPTS["no_atom"],
                no_indent=QUERY_OPTS["no_indent"],
                no_use=QUERY_OPTS["no_useflags"],
                no_mask=QUERY_OPTS["no_mask"],
            )
        else:
            printer = partial(
                depgraph_printer,
                no_atom=True,
                no_indent=True,
                no_use=True,
                no_mask=True,
            )

        for pkg in matches:
            make_depgraph(pkg, printer)

        first_run = False
コード例 #6
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "h"
    long_opts = ('help')

    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)

    if not queries or len(queries) > 1:
        print_help()
        sys.exit(2)

    #
    # Output
    #
    query = Query(queries[0])
    matches = query.find(include_masked=True, in_installed=False)

    if not matches:
        raise errors.GentoolkitNoMatches(query)

    matches.sort()
    matches.reverse()

    if CONFIG['verbose']:
        print(matches[0].ebuild_path())
        print()

    pkgdeps = matches[0].deps
    deps = pkgdeps.get_all_depends(raw=True)
    deps = paren_reduce(deps)

    if CONFIG['verbose']:
        print(deps)
        print()

    kwdict = parse_list(deps)

    if CONFIG['verbose']:
        print()

    if not kwdict == None:
        print(' '.join(kwdict.values()))
    else:
        print()
コード例 #7
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "h"
    long_opts = ('help')

    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)

    if not queries or len(queries) > 1:
        print_help()
        sys.exit(2)

    #
    # Output
    #

    query = Query(queries[0])

    matches = query.find(include_masked=True, in_installed=False)

    if not matches:
        raise errors.GentoolkitNoMatches(query)

    matches.sort()
    matches.reverse()

    if CONFIG['verbose']:
        print(matches[0].ebuild_path())
        print()

    ebkw = matches[0].environment('KEYWORDS')
    uskw = []

    for kw in ebkw.split():
        if kw[0] != '-' and kw[0] != '~':
            uskw.append('~' + kw)
        else:
            uskw.append(kw)

    print(' '.join(uskw))
コード例 #8
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "hof"
    long_opts = ("help", "only-failures", "full-regex")

    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)

    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()

        matches = query.smart_find(**QUERY_OPTS)

        if not matches:
            raise errors.GentoolkitNoMatches(query, in_installed=True)

        matches.sort()

        printer = partial(
            checks_printer,
            verbose=CONFIG["verbose"],
            only_failures=QUERY_OPTS["only_failures"],
        )
        check = VerifyContents(printer_fn=printer)
        check(matches)

        first_run = False
コード例 #9
0
def parse_atom(tok, indent=0):
    """Parse dependency atom"""

    assert (not isinstance(tok, list))

    if CONFIG['verbose']:
        print(' ' * indent, 'atom', tok)

    atom = Atom(tok)

    # Try to find matches for this atom
    query = Query(atom)
    matches = query.find(include_masked=True)
    # We didn't find any so raise an error
    if not matches:
        raise errors.GentoolkitNoMatches(query)

    # Loop through the matching packages combining their best arch keywords into a single dictionary
    matches.sort()
    kwdict = {}
    for pkg in matches:
        if CONFIG['verbose']:
            print(' ' * (indent + 2), pkg)
        keywords_str = pkg.environment(('KEYWORDS'), prefer_vdb=False)
        if keywords_str:
            if CONFIG['verbose']:
                print(' ' * (indent + 4), keywords_str)
            for keyword in keywords_str.split():
                skw = make_stable(keyword)
                if skw not in kwdict:
                    kwdict[skw] = keyword
                else:
                    kwdict[skw] = best_keyword(kwdict[skw], keyword)

    if CONFIG['verbose']:
        print(' ' * indent, 'return', kwdict)

    return kwdict