Beispiel #1
0
    def run(self, query=None, obj=None):
        matches = Query(query).find(
            include_masked=True,
            in_installed=False,
        )

        if not matches:
            sys.stderr.write(
                self.style.ERROR("Unknown package '%s'\n" % query)
            )
            return

        matches = sorted(matches)
        pkg = matches.pop()
        if '9999' in pkg.version and len(matches):
            pkg = matches.pop()

        if not obj:
            obj, created = Package.objects.get_or_create(
                category=pkg.category, name=pkg.name
            )
        else:
            created = False

        try:
            obj.homepage = pkg.environment("HOMEPAGE")
            obj.description = pkg.environment("DESCRIPTION")
        except GentoolkitFatalError, err:
            sys.stderr.write(
                self.style.ERROR(
                    "Gentoolkit fatal error: '%s'\n" % str(err)
                )
            )
Beispiel #2
0
    def metadata_from_portage(self, query, pkg=None):
        from gentoolkit.query import Query

        matches = Query(query).smart_find(
            in_installed=True,
            in_porttree=True,
            in_overlay=True,
            include_masked=True,
            show_progress=False,
            no_matches_fatal=False,
        )

        if not matches:
            self.logger.error(self.style.ERROR("Unknown package '%s'" % query))
            return pkg, None

        matches = sorted(matches)
        package = matches.pop()
        if '9999' in package.version and len(matches):
            package = matches.pop()

        if not pkg:
            pkg, created = Package.objects.get_or_create(
                category=package.category, name=package.name)
        else:
            created = False

        if created:
            self.logger.info('+ [p] %s/%s' % (pkg.category, pkg.name))

        return pkg, package.metadata
Beispiel #3
0
	def __init__(self, query, parser=None):
		Query.__init__(self, query)
		self.use = []
		self.depatom = str()

		# Allow a custom parser function:
		self.parser = parser if parser else self._parser
Beispiel #4
0
    def __init__(self, query, parser=None):
        Query.__init__(self, query)
        self.use = []
        self.depatom = str()

        # Allow a custom parser function:
        self.parser = parser if parser else self._parser
Beispiel #5
0
    def metadata_from_portage(self, query, pkg=None):
        from gentoolkit.query import Query

        matches = Query(query).smart_find(
            in_installed=True,
            in_porttree=True,
            in_overlay=True,
            include_masked=True,
            show_progress=False,
            no_matches_fatal=False,
        )

        if not matches:
            self.logger.error(self.style.ERROR("Unknown package '%s'" % query))
            return pkg, None

        matches = sorted(matches)
        package = matches.pop()
        if "9999" in package.version and len(matches):
            package = matches.pop()

        if not pkg:
            pkg, created = Package.objects.get_or_create(category=package.category, name=package.name)
        else:
            created = False

        if created:
            self.logger.info("+ [p] %s/%s" % (pkg.category, pkg.name))

        return pkg, package.metadata
Beispiel #6
0
def scan_upstream(query):
    matches = Query(query).find(
        include_masked=True,
        in_installed=False
    )

    if not matches:
        sys.stderr.write(pp.warn("No package matching '%s'" % pp.pkgquery(query)))
        return []

    matches = sorted(matches)
    pkg = matches.pop()

    while '9999' in pkg.version and len(matches):
        pkg = matches.pop()

    if not pkg:
        sys.stderr.write(pp.warn("Package '%s' only have a dev version (9999)"
                                 % pp.pkgquery(pkg.cp)))
        return []

    if pkg.cp in BLACKLIST_PACKAGES:
        sys.stderr.write(pp.warn("Package '%s' is blacklisted" % pp.pkgquery(pkg.cp)))
        return []

    if not CONFIG['quiet']:
        pp.uprint(" * %s [%s]" % (pp.cpv(pkg.cpv), pp.section(pkg.repo_name())))
        pp.uprint()

        ebuild_path = pkg.ebuild_path()
        if ebuild_path:
            pp.uprint('Ebuild: ' + pp.path(os.path.normpath(ebuild_path)))

        pp.uprint('Repository: ' + pkg.repo_name())
        pp.uprint('Homepage: ' + pkg.environment("HOMEPAGE"))
        pp.uprint('Description: ' + pkg.environment("DESCRIPTION"))

    cpv = pkg.cpv
    metadata = {
        "EAPI"    : port_settings["EAPI"],
        "SRC_URI" : pkg.environment("SRC_URI", False),
    }
    use = frozenset(port_settings["PORTAGE_USE"].split())
    try:
        alist = porttree._parse_uri_map(cpv, metadata, use=use)
        aalist = porttree._parse_uri_map(cpv, metadata)
    except Exception as e:
        sys.stderr.write(pp.warn("%s\n" % str(e)))
        sys.stderr.write(pp.warn("Invalid SRC_URI for '%s'" % pp.pkgquery(cpv)))
        return []

    if "mirror" in portage.settings.features:
        urls = aalist
    else:
        urls = alist

    return scan_upstream_urls(pkg.cpv, urls)
Beispiel #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()

    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()
Beispiel #8
0
def main(input_args):
	"""Parse input and run the program"""

	# -e, --exact-name is legacy option. djanderson '09
	short_opts = "hemstf:"
	long_opts = ('help', 'exact-name', 'md5sum', 'timestamp', 'type', 'tree',
		'filter=')

	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)

	# Turn off filtering for tree output
	if QUERY_OPTS["output_tree"]:
		QUERY_OPTS["type_filter"] = None

	#
	# Output files
	#

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

		matches = Query(query).smart_find(**QUERY_OPTS)

		if not matches:
			sys.stderr.write(
				pp.error("No matching packages found for %s" % query)
			)

		matches.sort()

		for pkg in matches:
			if CONFIG['verbose']:
				pp.uprint(" * Contents of %s:" % pp.cpv(str(pkg.cpv)))

			contents = pkg.parsed_contents()
			display_files(filter_contents(contents))

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

    short_opts = "hiIpoF:"  # -i was option for default action
    # --installed is no longer needed, kept for compatibility (djanderson '09)
    long_opts = (
        "help",
        "installed",
        "exclude-installed",
        "portage-tree",
        "overlay-tree",
        "format=",
    )

    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)

    matches = Query("*").smart_find(**QUERY_OPTS)
    matches.sort()

    #
    # Output
    #

    first_run = True
    got_match = False
    for query in queries:
        if not first_run:
            print()

        if CONFIG["verbose"]:
            pp.uprint(" * Searching for USE flag %s ... " % pp.emph(query))

        for pkg in matches:
            if display_useflags(query, pkg):
                got_match = True

        first_run = False

    if not got_match:
        sys.exit(1)
Beispiel #10
0
def upstream_remote_id(query):
    matches = Query(query).find(include_masked=True, in_installed=False)

    if not matches:
        sys.stderr.write(pp.warn("No package matching '%s'" % pp.pkgquery(query)))
        return

    matches = sorted(matches)
    matches.reverse()
    # Only latest version
    matches = matches[:1]
    for package in matches:
        upstream_remote_id_package(package)
Beispiel #11
0
def main(input_args):
    """Parse input and run the program"""

    # -e, --exact-name is legacy option. djanderson '09
    short_opts = "hemstf:"
    long_opts = ('help', 'exact-name', 'md5sum', 'timestamp', 'type', 'tree',
                 'filter=')

    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)

    # Turn off filtering for tree output
    if QUERY_OPTS["output_tree"]:
        QUERY_OPTS["type_filter"] = None

    #
    # Output files
    #

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

        matches = Query(query).smart_find(**QUERY_OPTS)

        if not matches:
            sys.stderr.write(
                pp.error("No matching packages found for %s" % query))

        matches.sort()

        for pkg in matches:
            if CONFIG['verbose']:
                pp.uprint(" * Contents of %s:" % pp.cpv(str(pkg.cpv)))

            contents = pkg.parsed_contents()
            display_files(filter_contents(contents))

        first_run = False
Beispiel #12
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))
Beispiel #13
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)
Beispiel #14
0
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
Beispiel #15
0
def main(input_args):
	"""Parse input and run the program"""

	short_opts = "hiIpoF:" # -i was option for default action
	# --installed is no longer needed, kept for compatibility (djanderson '09)
	long_opts = ('help', 'installed', 'exclude-installed', 'portage-tree',
		'overlay-tree', 'format=')

	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)

	matches = Query("*").smart_find(**QUERY_OPTS)
	matches.sort()

	#
	# Output
	#

	first_run = True
	got_match = False
	for query in queries:
		if not first_run:
			print()

		if CONFIG['verbose']:
			pp.uprint(" * Searching for USE flag %s ... " % pp.emph(query))

		for pkg in matches:
			if display_useflags(query, pkg):
				got_match = True

		first_run = False

	if not got_match:
		sys.exit(1)
Beispiel #16
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
Beispiel #17
0
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
Beispiel #18
0
def packages(*params):
    query_str = next(iter(params), '*')
    query = Query(query_str)
    matches = query.smart_find(**QUERY_OPTS)

    _packages = [{
        "deps": x.deps.get_all_depends(),
        "category": x.category,
        "name": x.name,
        "revision": x.revision,
        "size": x.size()[0],
        "files": x.size()[1],
        "uncounted_files": x.size()[2],
        "use": x.use().split(" "),
        "active_use": x.use_status(),
        "version": x.version,
    } for x in matches]

    return _packages
Beispiel #19
0
def depgraph(query_str):
    query = Query(query_str)
    package = query.find_best()
    if not package:
        return
    orphans = []
    targets = list({x.cp for x in package.deps.get_all_depends()})
    deplist = [{"source": package.cp, "targets": targets}]

    while True:
        targets = list(set(itertools.chain(*[x["targets"] for x in deplist])))
        sources = [x["source"] for x in deplist]
        sources_to_add = [x for x in targets if x not in sources]
        if not sources_to_add:
            break
        else:
            for cp in sources_to_add:
                query = Query(cp)
                package = query.find_best()
                if package is None:
                    orphans.append(cp)
                    deplist.append({
                        "source": cp,
                        "targets": [],
                    })
                else:
                    deplist.append({
                        "source": package.cp,
                        "targets": list({x.cp for x in package.deps.get_all_depends()}),
                    })
    return {"deplist": deplist, "orphans": orphans}
Beispiel #20
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
Beispiel #21
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
Beispiel #22
0
def main(input_args):
    """Parse input and run the program"""

    # -e, --exact-name is no longer needed. Kept for compatibility.
    # 04/09 djanderson
    short_opts = "hbfe"
    long_opts = ('help', 'bytes', 'full-regex', 'exact-name')

    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:
            sys.stderr.write(pp.error("No package found matching %s" % query))

        matches.sort()

        display_size(matches)

        first_run = False
Beispiel #23
0
    def graph_depends(
            self,
            max_depth=1,
            printer_fn=None,
            # The rest of these are only used internally:
            depth=1,
            seen=None,
            depcache=None,
            result=None):
        """Graph direct dependencies for self.

		Optionally gather indirect dependencies.

		@type max_depth: int
		@keyword max_depth: Maximum depth to recurse if.
			<1 means no maximum depth
			>0 means recurse only this depth;
		@type printer_fn: callable
		@keyword printer_fn: If None, no effect. If set, it will be applied to
			each result.
		@rtype: list
		@return: [(depth, pkg), ...]
		"""
        if seen is None:
            seen = set()
        if depcache is None:
            depcache = dict()
        if result is None:
            result = list()

        pkgdep = None
        deps = self.get_all_depends()
        for dep in deps:
            if dep.atom in depcache:
                continue
            try:
                pkgdep = depcache[dep.atom]
            except KeyError:
                pkgdep = Query(dep.atom).find_best()
                depcache[dep.atom] = pkgdep
            if not pkgdep:
                continue
            elif pkgdep.cpv in seen:
                continue
            if depth <= max_depth or max_depth == 0:
                if printer_fn is not None:
                    printer_fn(depth, pkgdep, dep)
                result.append((depth, pkgdep))

                seen.add(pkgdep.cpv)
                if depth < max_depth or max_depth == 0:
                    # result is passed in and added to directly
                    # so rdeps is disposable
                    rdeps = pkgdep.deps.graph_depends(  # noqa
                        max_depth=max_depth,
                        printer_fn=printer_fn,
                        # The rest of these are only used internally:
                        depth=depth + 1,
                        seen=seen,
                        depcache=depcache,
                        result=result)
        return result
Beispiel #24
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 #25
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "hiIpoF:"  # -i was option for default action
    # --installed is no longer needed, kept for compatibility (djanderson '09)
    long_opts = ('help', 'installed', 'exclude-installed', 'portage-tree',
                 'overlay-tree', 'format=', 'package=')

    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)

    query_scope = QUERY_OPTS['package_filter'] or '*'
    matches = Query(query_scope).smart_find(**QUERY_OPTS)
    matches.sort()

    # split out the first query since it is suppose to be the env_var
    QUERY_OPTS['env_var'] = queries.pop(0)
    env_var = QUERY_OPTS['env_var']

    #
    # Output
    #

    if not queries:
        if not QUERY_OPTS['package_filter']:
            err = "Used ENV_VAR without match_expression or --package"
            raise errors.GentoolkitFatalError(err, is_serious=False)
        else:
            if len(matches) > 1:
                raise errors.AmbiguousPackageName(matches)
            for match in matches:
                env = QUERY_OPTS['env_var']
                print(match.environment(env))

    first_run = True
    got_match = False
    for query in queries:
        if not first_run:
            print()

        if CONFIG['verbose']:
            status = " * Searching for {0} {1} ... "
            pp.uprint(status.format(env_var, pp.emph(query)))

        for pkg in matches:
            if query_in_env(query, env_var, pkg):
                display_pkg(query, env_var, pkg)
                got_match = True
        first_run = False

    if not got_match:
        sys.exit(1)
Beispiel #26
0
def scan_upstream(query, on_progress=None):
    """
    Scans the upstream searching new versions for the given query
    """

    maxval = 3
    curval = 0

    matches = []

    if query.endswith(".ebuild"):
        cpv = package_from_ebuild(query)
        if cpv:
            reload_gentoolkit()
            matches = [Package(cpv)]
    else:
        matches = Query(query).find(
            include_masked=True,
            in_installed=False
        )

    if not matches:
        output.ewarn(
            pp.warn("No package matching '%s'" % pp.pkgquery(query))
        )
        return None

    matches = sorted(matches)
    pkg = matches.pop()

    while '9999' in pkg.version and len(matches):
        pkg = matches.pop()

    if not pkg:
        output.ewarn(
            pp.warn("Package '%s' only have a dev version (9999)"
                    % pp.pkgquery(pkg.cp))
        )
        return None

    # useful data only for formatted output
    start_time = datetime.now()
    output.metadata("datetime", start_time.isoformat(), show=False)
    output.metadata("cp", pkg.cp, show=False)
    output.metadata("cpv", pkg.cpv, show=False)

    curval += 1
    if on_progress:
        on_progress(maxval, curval)

    if pkg.cp in BLACKLIST_PACKAGES:
        output.ewarn(
            pp.warn("Package '%s' is blacklisted" % pp.pkgquery(pkg.cp))
        )
        return None

    if not CONFIG['quiet']:
        if not CONFIG['format']:
            pp.uprint(
                " * %s [%s]" % (pp.cpv(pkg.cpv), pp.section(pkg.repo_name()))
            )
            pp.uprint()
        else:
            output.metadata("overlay", pp.section(pkg.repo_name()))

        ebuild_path = pkg.ebuild_path()
        if ebuild_path:
            output.metadata(
                "ebuild", pp.path(os.path.normpath(ebuild_path))
            )

        output.metadata("repository", pkg.repo_name())
        output.metadata("homepage", pkg.environment("HOMEPAGE"))
        output.metadata("description", pkg.environment("DESCRIPTION"))

    cpv = pkg.cpv
    metadata = {
        "EAPI": portage.settings["EAPI"],
        "SRC_URI": pkg.environment("SRC_URI", False),
    }
    use = frozenset(portage.settings["PORTAGE_USE"].split())
    try:
        alist = porttree._parse_uri_map(cpv, metadata, use=use)
        aalist = porttree._parse_uri_map(cpv, metadata)
    except Exception as e:
        output.ewarn(pp.warn("%s\n" % str(e)))
        output.ewarn(
            pp.warn("Invalid SRC_URI for '%s'" % pp.pkgquery(cpv))
        )
        return None

    if "mirror" in portage.settings.features:
        urls = aalist
    else:
        urls = alist

    # output scan time for formatted output
    scan_time = (datetime.now() - start_time).total_seconds()
    output.metadata("scan_time", scan_time, show=False)

    curval += 1
    if on_progress:
        on_progress(maxval, curval)

    result = scan_upstream_urls(pkg.cpv, urls, on_progress)

    curval += 1
    if on_progress:
        on_progress(maxval, curval)

    return result
Beispiel #27
0
def main(input_args):
    """Parse input and run the program"""

    short_opts = "hlf"
    long_opts = ('help', 'full', 'from=', 'latest', 'limit=', 'to=')

    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
    got_match = False
    for query in (Query(x) for x in queries):
        if not first_run:
            print()

        match = query.find_best()
        if match is None:
            continue

        got_match = True
        changelog_path = os.path.join(match.package_path(), 'ChangeLog')
        changelog = ChangeLog(changelog_path)

        #
        # Output
        #

        if (QUERY_OPTS['only_latest']
                or (changelog.entries and not changelog.indexed_entries)):
            pp.uprint(changelog.latest.strip())
        else:
            end = QUERY_OPTS['limit'] or len(changelog.indexed_entries)
            if QUERY_OPTS['to'] or QUERY_OPTS['from']:
                print_entries(
                    changelog.entries_matching_range(
                        from_ver=QUERY_OPTS['from'],
                        to_ver=QUERY_OPTS['to'])[:end])
            elif QUERY_OPTS['show_full_log']:
                print_entries(changelog.full[:end])
            else:
                # Raises GentoolkitInvalidAtom here if invalid
                if query.is_ranged():
                    atom = Atom(str(query))
                else:
                    atom = '=' + str(match.cpv)
                print_entries(changelog.entries_matching_atom(atom)[:end])

        first_run = False

    if not got_match:
        sys.exit(1)
Beispiel #28
0
        os.fchdir(self.restore_fd)
        os.chroot(b".")
        os.chdir(self.working_dir)
        os.close(self.restore_fd)


pkg_size_map = defaultdict(int)

# Setup by caller; this is pure lazyness
root = u"size_mnt"

with open("all_pkgs") as f:
    for line in f:
        inos = {}  # dedupe inodes within a pkg
        pkg = portage.cpv_getkey(line)
        matches = Query(pkg).smart_find()
        for pkgv in matches:
            contents = pkgv.parsed_contents()
            for c in contents.keys():
                c = c.encode('utf-8')
                with chrooted(root):
                    if not os.path.islink(c) and os.path.isfile(c):
                        st = os.stat(c)
                        if st.st_ino in inos:
                            continue
                        inos[st.st_ino] = True
                        pkg_size_map[str(pkg)] += st.st_size

for k, v in pkg_size_map.iteritems():
    print str(v) + " " + str(k).strip()
Beispiel #29
0
def scan_upstream(query, on_progress=None):
    """
    Scans the upstream searching new versions for the given query
    """
    matches = []

    if query.endswith(".ebuild"):
        cpv = package_from_ebuild(query)
        reload_gentoolkit()
        if cpv:
            matches = [Package(cpv)]
    else:
        matches = Query(query).find(
            include_masked=True,
            in_installed=False,
        )

    if not matches:
        output.ewarn(pp.warn("No package matching '%s'" % pp.pkgquery(query)))
        return None

    matches = sorted(matches)
    pkg = matches.pop()

    while '9999' in pkg.version and len(matches):
        pkg = matches.pop()

    if not pkg:
        output.ewarn(
            pp.warn("Package '%s' only have a dev version (9999)" %
                    pp.pkgquery(pkg.cp)))
        return None

    # useful data only for formatted output
    start_time = datetime.now()
    output.metadata("datetime", start_time.isoformat(), show=False)
    output.metadata("cp", pkg.cp, show=False)
    output.metadata("cpv", pkg.cpv, show=False)

    if on_progress:
        on_progress(increment=10)

    if pkg.cp in BLACKLIST_PACKAGES:
        output.ewarn(
            pp.warn("Package '%s' is blacklisted" % pp.pkgquery(pkg.cp)))
        return None

    if not CONFIG['quiet']:
        if not CONFIG['format']:
            pp.uprint(" * %s [%s]" %
                      (pp.cpv(pkg.cpv), pp.section(pkg.repo_name())))
            pp.uprint()
        else:
            output.metadata("overlay", pp.section(pkg.repo_name()))

        ebuild_path = pkg.ebuild_path()
        if ebuild_path:
            output.metadata("ebuild", pp.path(os.path.normpath(ebuild_path)))

        uris, homepage, description = pkg.environment(
            ('SRC_URI', 'HOMEPAGE', 'DESCRIPTION'))

        output.metadata("repository", pkg.repo_name())
        output.metadata("homepage", homepage)
        output.metadata("description", description)
    else:
        uris = pkg.environment('SRC_URI')

    cpv = pkg.cpv

    uris = parse_src_uri(uris)
    uris_expanded = [
        from_mirror(uri) if 'mirror://' in uri else uri for uri in uris
    ]

    pkg._uris = uris
    pkg._uris_expanded = uris_expanded

    versions = handlers.scan(pkg, uris, on_progress)

    cp, ver, rev = portage.pkgsplit(pkg.cpv)

    result = filter_versions(cp, versions)

    if on_progress:
        on_progress(increment=10)

    # output scan time for formatted output
    scan_time = (datetime.now() - start_time).total_seconds()
    output.metadata("scan_time", scan_time, show=False)

    is_current_version_stable = is_version_stable(ver)
    if len(result) > 0:
        if not (CONFIG['format'] or CONFIG['quiet']):
            print("")
        for cp, url, version, handler, confidence in result:
            if CONFIG["ignore-pre-release"]:
                if not is_version_stable(version):
                    continue
            if CONFIG["ignore-pre-release-if-stable"]:
                if is_current_version_stable and \
                   not is_version_stable(version):
                    continue
            if CONFIG['progress']:
                print("", file=sys.stderr)
            output.result(cp, version, url, handler, confidence)

    return result
Beispiel #30
0
def main(input_args):
	"""Parse input and run the program"""

	short_opts = "hiIpoF:" # -i was option for default action
	# --installed is no longer needed, kept for compatibility (djanderson '09)
	long_opts = ('help', 'installed', 'exclude-installed', 'portage-tree',
		'overlay-tree', 'format=', 'package=')

	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)

	query_scope = QUERY_OPTS['package_filter'] or '*'
	matches = Query(query_scope).smart_find(**QUERY_OPTS)
	matches.sort()

	# split out the first query since it is suppose to be the env_var
	QUERY_OPTS['env_var'] = queries.pop(0)
	env_var = QUERY_OPTS['env_var']

	#
	# Output
	#

	if not queries:
		if not QUERY_OPTS['package_filter']:
			err = "Used ENV_VAR without match_expression or --package"
			raise errors.GentoolkitFatalError(err, is_serious=False)
		else:
			if len(matches) > 1:
				raise errors.AmbiguousPackageName(matches)
			for match in matches:
				env = QUERY_OPTS['env_var']
				print(match.environment(env))

	first_run = True
	got_match = False
	for query in queries:
		if not first_run:
			print()

		if CONFIG['verbose']:
			status = " * Searching for {0} {1} ... "
			pp.uprint(status.format(env_var, pp.emph(query)))

		for pkg in matches:
			if query_in_env(query, env_var, pkg):
				display_pkg(query, env_var, pkg)
				got_match = True
		first_run = False

	if not got_match:
		sys.exit(1)
Beispiel #31
0
def scan_upstream(query, on_progress=None):
    """
    Scans the upstream searching new versions for the given query
    """
    matches = []

    if query.endswith(".ebuild"):
        cpv = package_from_ebuild(query)
        reload_gentoolkit()
        if cpv:
            matches = [Package(cpv)]
    else:
        matches = Query(query).find(
            include_masked=True,
            in_installed=False,
        )

    if not matches:
        output.ewarn(
            pp.warn("No package matching '%s'" % pp.pkgquery(query))
        )
        return None

    matches = sorted(matches)
    pkg = matches.pop()

    while '9999' in pkg.version and len(matches):
        pkg = matches.pop()

    if not pkg:
        output.ewarn(
            pp.warn("Package '%s' only have a dev version (9999)"
                    % pp.pkgquery(pkg.cp))
        )
        return None

    # useful data only for formatted output
    start_time = datetime.now()
    output.metadata("datetime", start_time.isoformat(), show=False)
    output.metadata("cp", pkg.cp, show=False)
    output.metadata("cpv", pkg.cpv, show=False)

    if on_progress:
        on_progress(increment=10)

    if pkg.cp in BLACKLIST_PACKAGES:
        output.ewarn(
            pp.warn("Package '%s' is blacklisted" % pp.pkgquery(pkg.cp))
        )
        return None

    if not CONFIG['quiet']:
        if not CONFIG['format']:
            pp.uprint(
                " * %s [%s]" % (pp.cpv(pkg.cpv), pp.section(pkg.repo_name()))
            )
            pp.uprint()
        else:
            output.metadata("overlay", pp.section(pkg.repo_name()))

        ebuild_path = pkg.ebuild_path()
        if ebuild_path:
            output.metadata(
                "ebuild", pp.path(os.path.normpath(ebuild_path))
            )

        uris, homepage, description = pkg.environment(
            ('SRC_URI', 'HOMEPAGE', 'DESCRIPTION')
        )

        output.metadata("repository", pkg.repo_name())
        output.metadata("homepage", homepage)
        output.metadata("description", description)
    else:
        uris = pkg.environment('SRC_URI')

    cpv = pkg.cpv

    uris = parse_src_uri(uris)
    uris_expanded = [
        from_mirror(uri) if 'mirror://' in uri else uri for uri in uris
    ]

    pkg._uris = uris
    pkg._uris_expanded = uris_expanded

    versions = handlers.scan(pkg, uris, on_progress)

    cp, ver, rev = portage.pkgsplit(pkg.cpv)

    result = filter_versions(cp, versions)

    if on_progress:
        on_progress(increment=10)

    # output scan time for formatted output
    scan_time = (datetime.now() - start_time).total_seconds()
    output.metadata("scan_time", scan_time, show=False)

    is_current_version_stable = is_version_stable(ver)
    if len(result) > 0:
        if not (CONFIG['format'] or CONFIG['quiet']):
            print("")
        for cp, url, version, handler, confidence in result:
            if CONFIG["ignore-pre-release"]:
                if not is_version_stable(version):
                    continue
            if CONFIG["ignore-pre-release-if-stable"]:
                if is_current_version_stable and \
                   not is_version_stable(version):
                    continue
            if CONFIG['progress']:
                print("", file=sys.stderr)
            output.result(cp, version, url, handler, confidence)

    return result