Example #1
0
def main(input_args):
	"""Parse input and run the program"""

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

	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
Example #2
0
    def _format_values(self, key, values):
        """Format entry values ie. USE flags, keywords,...

        @type key: str
        @param key: a pre-formatted cpv
        @type values: list of pre-formatted strings
        @param values: ['flag1', 'flag2',...]
        @rtype: str
        @return: formatted options string
        """

        result = []
        if self.cpv_width > 1:
            _cpv = pp.cpv(key + "." * (self.cpv_width - len(key)))
            if not len(values):
                return _cpv
            self.twrap.initial_indent = _cpv
            self.twrap.subsequent_indent = " " * (self.cpv_width + 1)
        else:
            _cpv = pp.cpv(key + " ")
            if not len(values):
                return _cpv
            self.twrap.initial_indent = _cpv
            self.twrap.subsequent_indent = " " * (len(key) + 1)

        result.append(self.twrap.fill(values))
        return "\n".join(result)
Example #3
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
Example #4
0
def make_depgraph(pkg, printer_fn):
    """Create and display depgraph for each package."""

    print()
    if CONFIG["verbose"]:
        pp.uprint(" * " + pp.subsection("dependency graph for ") + pp.cpv(str(pkg.cpv)))
    else:
        pp.uprint("%s:" % pkg.cpv)

        # Print out the first package
    printer_fn(0, pkg, None, initial_pkg=True)

    deps = pkg.deps.graph_depends(
        max_depth=QUERY_OPTS["depth"],
        printer_fn=printer_fn,
        # Use this to set this pkg as the graph's root; better way?
        result=[(0, pkg)],
    )

    if CONFIG["verbose"]:
        pkgname = pp.cpv(str(pkg.cpv))
        n_packages = pp.number(str(len(deps)))
        max_seen = pp.number(str(max(x[0] for x in deps)))
        info = "[ %s stats: packages (%s), max depth (%s) ]"
        pp.uprint(info % (pkgname, n_packages, max_seen))
Example #5
0
File: out.py Project: EvaSDK/euscan
    def result(self, cp, version, urls, handler, confidence):
        from euscan.version import get_version_type

        cpv = '%s-%s' % (cp, version)
        urls = ' '.join(
            transform_url(self.config, cpv, url) for url in urls.split()
        )

        if self.config['format'] in ['json', 'dict']:
            _curr = self.queries[self.current_query]
            _curr["result"].append(
                {
                    "version": version,
                    "urls": urls.split(),
                    "handler": handler,
                    "confidence": confidence,
                    "type": get_version_type(version)
                }
            )
        else:
            if not self.config['quiet']:
                print "Upstream Version:", pp.number("%s" % version),
                print pp.path(" %s" % urls)
            else:
                print pp.cpv("%s-%s" % (cp, version)) + ":", pp.path(urls)
Example #6
0
	def _format_values(self, key, values):
		"""Format entry values ie. USE flags, keywords,...

		@type key: str
		@param key: a pre-formatted cpv
		@type values: list of pre-formatted strings
		@param values: ['flag1', 'flag2',...]
		@rtype: str
		@return: formatted options string
		"""

		result = []
		if self.cpv_width > 1:
			_cpv = pp.cpv(key+'.'*(self.cpv_width-len(key)))
			if not len(values):
				return _cpv
			self.twrap.initial_indent = _cpv
			self.twrap.subsequent_indent = " " * (self.cpv_width+1)
		else:
			_cpv = pp.cpv(key+' ')
			if not len(values):
				return _cpv
			self.twrap.initial_indent = _cpv
			self.twrap.subsequent_indent = " " * (len(key)+1)

		result.append(self.twrap.fill(values))
		return '\n'.join(result)
Example #7
0
def make_depgraph(pkg, printer_fn):
    """Create and display depgraph for each package."""

    print()
    if CONFIG['verbose']:
        pp.uprint(" * " + pp.subsection("dependency graph for ") +
                  pp.cpv(str(pkg.cpv)))
    else:
        pp.uprint("%s:" % pkg.cpv)

    # Print out the first package
    printer_fn(0, pkg, None, initial_pkg=True)

    deps = pkg.deps.graph_depends(
        max_depth=QUERY_OPTS['depth'],
        printer_fn=printer_fn,
        # Use this to set this pkg as the graph's root; better way?
        result=[(0, pkg)])

    if CONFIG['verbose']:
        pkgname = pp.cpv(str(pkg.cpv))
        n_packages = pp.number(str(len(deps)))
        max_seen = pp.number(str(max(x[0] for x in deps)))
        info = "[ %s stats: packages (%s), max depth (%s) ]"
        pp.uprint(info % (pkgname, n_packages, max_seen))
Example #8
0
    def print_keyword_verbose(key, stability, default, count, pkgs):
        """Verbosely prints a set of keywords info. including the pkgs
		using them.
		"""
        _pkgs = pkgs[:]
        _key = pp.keyword((stability + key), stable=(stability == " "), hard_masked=stability == "-")
        cpv = _pkgs.pop(0)
        print(_key, "." * (20 - len(key)), default, pp.number(count), pp.cpv(cpv))
        while _pkgs:
            cpv = _pkgs.pop(0)
            print(" " * 37 + pp.cpv(cpv))
Example #9
0
	def print_keyword_verbose(self, key, stability, default, count, pkgs):
		"""Verbosely prints a set of keywords info. including the pkgs
		using them.
		"""
		_pkgs = pkgs[:]
		_key = (pp.keyword((stability+key),stable=(stability==" "),
			hard_masked=stability=="-"))
		cpv = _pkgs.pop(0)
		print(self.prepend + _key,'.'*(20-len(key)), default, pp.number(count),
			pp.cpv(cpv))
		while _pkgs:
			cpv = _pkgs.pop(0)
			print(' '*37 + pp.cpv(cpv))
Example #10
0
    def print_use_verbose(key, active, default, count, pkgs):
        """Verbosely prints a set of use flag info. including the pkgs
		using them.
		"""
        _pkgs = pkgs[:]
        if active in ["+", "-"]:
            _key = pp.useflag((active + key), active == "+")
        else:
            _key = " " + key
        cpv = _pkgs.pop(0)
        print(_key, "." * (35 - len(key)), default, pp.number(count), pp.cpv(cpv))
        while _pkgs:
            cpv = _pkgs.pop(0)
            print(" " * 52 + pp.cpv(cpv))
Example #11
0
    def print_use_verbose(key, active, default, count, pkgs):
        """Verbosely prints a set of use flag info. including the pkgs
		using them.
		"""
        _pkgs = pkgs[:]
        if active in ["+", "-"]:
            _key = pp.useflag((active + key), active == "+")
        else:
            _key = (" " + key)
        cpv = _pkgs.pop(0)
        print(_key, '.' * (35 - len(key)), default, pp.number(count),
              pp.cpv(cpv))
        while _pkgs:
            cpv = _pkgs.pop(0)
            print(' ' * 52 + pp.cpv(cpv))
Example #12
0
File: out.py Project: mgorny/euscan
    def result(self, cp, version, url, handler, confidence):
        from euscan.helpers import get_version_type

        if self.config['format']:
            _curr = self.queries[self.current_query]
            _curr["result"].append(
                {"version": version, "urls": [url], "handler": handler,
                 "confidence": confidence, "type": get_version_type(version)}
            )
        else:
            if not self.config['quiet']:
                print "Upstream Version:", pp.number("%s" % version),
                print pp.path(" %s" % url)
            else:
                print pp.cpv("%s-%s" % (cp, version)) + ":", pp.path(url)
Example #13
0
def display_size(match_set):
	"""Display the total size of all accessible files owned by packages.

	@type match_set: list
	@param match_set: package cat/pkg-ver strings
	"""

	for pkg in match_set:
		size, files, uncounted = pkg.size()

		if CONFIG['verbose']:
			pp.uprint(" * %s" % pp.cpv(str(pkg.cpv)))
			print("Total files : %s".rjust(25) % pp.number(str(files)))

			if uncounted:
				print(("Inaccessible files : %s".rjust(25) %
					pp.number(str(uncounted))))

			if QUERY_OPTS["size_in_bytes"]:
				size_str = pp.number(str(size))
			else:
				size_str = "%s %s" % format_bytes(size)

			print("Total size  : %s".rjust(25) % size_str)
		else:
			info = "%s: total(%d), inaccessible(%d), size(%s)"
			pp.uprint(info % (str(pkg.cpv), files, uncounted, size))
Example #14
0
    def result(self, cp, version, urls, handler, confidence):
        from euscan.version import get_version_type

        cpv = '%s-%s' % (cp, version)
        urls = ' '.join(
            transform_url(self.config, cpv, url) for url in urls.split()
        )

        if self.config['format'] in ['json', 'dict']:
            _curr = self.queries[self.current_query]
            _curr["result"].append(
                {
                    "version": version,
                    "urls": urls.split(),
                    "handler": handler,
                    "confidence": confidence,
                    "type": get_version_type(version)
                }
            )
        else:
            if not self.config['quiet']:
                print("Upstream Version:", pp.number("%s" % version), end=' ')
                print(pp.path(" %s" % urls))
            else:
                print(pp.cpv("%s-%s" % (cp, version)) + ":", pp.path(urls))
Example #15
0
def display_useflags(output):
    """Print USE flag descriptions and statuses.

	@type output: list
	@param output: [(inuse, inused, flag, desc, restrict), ...]
		inuse (int) = 0 or 1; if 1, flag is set in make.conf
		inused (int) = 0 or 1; if 1, package is installed with flag enabled
		flag (str) = the name of the USE flag
		desc (str) = the flag's description
		restrict (str) = corresponds to the text of restrict in metadata
	"""

    maxflag_len = len(max([t[2] for t in output], key=len))

    twrap = TextWrapper()
    twrap.width = CONFIG['termWidth']
    twrap.subsequent_indent = " " * (maxflag_len + 8)

    markers = ("-", "+")
    color = (partial(pp.useflag,
                     enabled=False), partial(pp.useflag, enabled=True))
    for in_makeconf, in_installed, flag, desc, restrict in output:
        if CONFIG['verbose']:
            flag_name = ""
            if in_makeconf != in_installed:
                flag_name += pp.emph(
                    " %s %s" % (markers[in_makeconf], markers[in_installed]))
            else:
                flag_name += (" %s %s" %
                              (markers[in_makeconf], markers[in_installed]))

            flag_name += " " + color[in_makeconf](flag.ljust(maxflag_len))
            flag_name += " : "

            # Strip initial whitespace at the start of the description
            # Bug 432530
            if desc:
                desc = desc.lstrip()

            # print description
            if restrict:
                restrict = "(%s %s)" % (pp.emph("Restricted to"),
                                        pp.cpv(restrict))
                twrap.initial_indent = flag_name
                pp.uprint(twrap.fill(restrict))
                if desc:
                    twrap.initial_indent = twrap.subsequent_indent
                    pp.uprint(twrap.fill(desc))
                else:
                    print(" : <unknown>")
            else:
                if desc:
                    twrap.initial_indent = flag_name
                    desc = twrap.fill(desc)
                    pp.uprint(desc)
                else:
                    twrap.initial_indent = flag_name
                    print(twrap.fill("<unknown>"))
        else:
            pp.uprint(markers[in_makeconf] + flag)
Example #16
0
def display_size(match_set):
    """Display the total size of all accessible files owned by packages.

	@type match_set: list
	@param match_set: package cat/pkg-ver strings
	"""

    for pkg in match_set:
        size, files, uncounted = pkg.size()

        if CONFIG['verbose']:
            pp.uprint(" * %s" % pp.cpv(str(pkg.cpv)))
            print("Total files : %s".rjust(25) % pp.number(str(files)))

            if uncounted:
                print(("Inaccessible files : %s".rjust(25) %
                       pp.number(str(uncounted))))

            if QUERY_OPTS["size_in_bytes"]:
                size_str = pp.number(str(size))
            else:
                size_str = "%s %s" % format_bytes(size)

            print("Total size  : %s".rjust(25) % size_str)
        else:
            info = "%s: total(%d), inaccessible(%d), size(%s)"
            pp.uprint(info % (str(pkg.cpv), files, uncounted, size))
Example #17
0
 def print_verbose(self, pkg, cfile):
     "Format for full output."
     file_str = pp.path(format_filetype(cfile, pkg.parsed_contents()[cfile]))
     if self.name_only:
         name = pkg.cp
     else:
         name = str(pkg.cpv)
     pp.uprint(pp.cpv(name), "(" + file_str + ")")
Example #18
0
	def print_verbose(self, pkg, cfile):
		"Format for full output."
		file_str = pp.path(format_filetype(cfile, pkg.parsed_contents()[cfile]))
		if self.name_only:
			name = pkg.cp
		else:
			name = str(pkg.cpv)
		pp.uprint(pp.cpv(name), "(" + file_str + ")")
Example #19
0
def depgraph_printer(depth,
                     pkg,
                     dep,
                     no_use=False,
                     no_atom=False,
                     no_indent=False,
                     initial_pkg=False,
                     no_mask=False):
    """Display L{gentoolkit.dependencies.Dependencies.graph_depends} results.

	@type depth: int
	@param depth: depth of indirection, used to calculate indent
	@type pkg: L{gentoolkit.package.Package}
	@param pkg: "best match" package matched by B{dep}
	@type dep: L{gentoolkit.atom.Atom}
	@param dep: dependency that matched B{pkg}
	@type no_use: bool
	@param no_use: don't output USE flags
	@type no_atom: bool
	@param no_atom: don't output dep atom
	@type no_indent: bool
	@param no_indent: don't output indent based on B{depth}
	@type initial_pkg: bool
	@param initial_pkg: somewhat of a hack used to print the root package of
		the graph with absolutely no indent
	"""
    indent = '' if no_indent or initial_pkg else ' ' + (' ' * depth)
    decorator = '[%3d] ' % depth if no_indent else '`-- '
    use = ''
    atom = ''
    mask = ''
    try:
        if not no_atom:
            if dep.operator == '=*':
                atom += ' (=%s*)' % dep.cpv
            else:
                atom += ' (%s%s)' % (dep.operator, dep.cpv)
        if not no_use and dep is not None and dep.use:
            use = ' [%s]' % ' '.join(
                pp.useflag(x, enabled=True) for x in dep.use.tokens)
    except AttributeError:
        # 'NoneType' object has no attribute 'atom'
        pass
    if pkg and not no_mask:
        mask = pkg.mask_status()
        if not mask:
            mask = [
                determine_keyword(portage.settings["ARCH"],
                                  portage.settings["ACCEPT_KEYWORDS"],
                                  pkg.environment('KEYWORDS'))
            ]
        mask = pp.masking(mask)
    try:
        pp.uprint(' '.join(
            (indent, decorator, pp.cpv(str(pkg.cpv)), atom, mask, use)))
    except AttributeError:
        # 'NoneType' object has no attribute 'cpv'
        pp.uprint(''.join((indent, decorator, "(no match for %r)" % dep.atom)))
Example #20
0
	def format_cpv(self, attr=None):
		if attr is None:
			value = self.pkg.cpv
		else:
			value = getattr(self.pkg, attr)
		if self._do_format:
			return pp.cpv(value)
		else:
			return value
Example #21
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)
Example #22
0
 def format_cpv(self, attr=None):
     if attr is None:
         value = self.pkg.cpv
     else:
         value = getattr(self.pkg, attr)
     if self._do_format:
         return pp.cpv(value)
     else:
         return value
Example #23
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
Example #24
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
Example #25
0
def depgraph_printer(depth, pkg, dep, no_use=False, no_atom=False, no_indent=False, initial_pkg=False, no_mask=False):
    """Display L{gentoolkit.dependencies.Dependencies.graph_depends} results.

	@type depth: int
	@param depth: depth of indirection, used to calculate indent
	@type pkg: L{gentoolkit.package.Package}
	@param pkg: "best match" package matched by B{dep}
	@type dep: L{gentoolkit.atom.Atom}
	@param dep: dependency that matched B{pkg}
	@type no_use: bool
	@param no_use: don't output USE flags
	@type no_atom: bool
	@param no_atom: don't output dep atom
	@type no_indent: bool
	@param no_indent: don't output indent based on B{depth}
	@type initial_pkg: bool
	@param initial_pkg: somewhat of a hack used to print the root package of
		the graph with absolutely no indent
	"""
    indent = "" if no_indent or initial_pkg else " " + (" " * depth)
    decorator = "[%3d] " % depth if no_indent else "`-- "
    use = ""
    atom = ""
    mask = ""
    try:
        if not no_atom:
            if dep.operator == "=*":
                atom += " (=%s*)" % dep.cpv
            else:
                atom += " (%s%s)" % (dep.operator, dep.cpv)
        if not no_use and dep is not None and dep.use:
            use = " [%s]" % " ".join(pp.useflag(x, enabled=True) for x in dep.use.tokens)
    except AttributeError:
        # 'NoneType' object has no attribute 'atom'
        pass
    if pkg and not no_mask:
        mask = pkg.mask_status()
        if not mask:
            mask = [
                determine_keyword(
                    portage.settings["ARCH"], portage.settings["ACCEPT_KEYWORDS"], pkg.environment("KEYWORDS")
                )
            ]
        mask = pp.masking(mask)
    try:
        pp.uprint(" ".join((indent, decorator, pp.cpv(str(pkg.cpv)), atom, mask, use)))
    except AttributeError:
        # 'NoneType' object has no attribute 'cpv'
        pp.uprint("".join((indent, decorator, "(no match for %r)" % dep.atom)))
Example #26
0
def display_useflags(output):
	"""Print USE flag descriptions and statuses.

	@type output: list
	@param output: [(inuse, inused, flag, desc, restrict), ...]
		inuse (int) = 0 or 1; if 1, flag is set in make.conf
		inused (int) = 0 or 1; if 1, package is installed with flag enabled
		flag (str) = the name of the USE flag
		desc (str) = the flag's description
		restrict (str) = corresponds to the text of restrict in metadata
	"""

	maxflag_len = len(max([t[2] for t in output], key=len))

	twrap = TextWrapper()
	twrap.width = CONFIG['termWidth']
	twrap.subsequent_indent = " " * (maxflag_len + 8)

	markers = ("-", "+")
	color = (
		partial(pp.useflag, enabled=False), partial(pp.useflag, enabled=True)
	)
	for in_makeconf, in_installed, flag, desc, restrict in output:
		if CONFIG['verbose']:
			flag_name = ""
			if in_makeconf != in_installed:
				flag_name += pp.emph(" %s %s" %
					(markers[in_makeconf], markers[in_installed]))
			else:
				flag_name += (" %s %s" %
					(markers[in_makeconf], markers[in_installed]))

			flag_name += " " + color[in_makeconf](flag.ljust(maxflag_len))
			flag_name += " : "

			# Strip initial whitespace at the start of the description
			# Bug 432530
			if desc:
				desc = desc.lstrip()

			# print description
			if restrict:
				restrict = "(%s %s)" % (pp.emph("Restricted to"),
					pp.cpv(restrict))
				twrap.initial_indent = flag_name
				pp.uprint(twrap.fill(restrict))
				if desc:
					twrap.initial_indent = twrap.subsequent_indent
					pp.uprint(twrap.fill(desc))
				else:
					print(" : <unknown>")
			else:
				if desc:
					twrap.initial_indent = flag_name
					desc = twrap.fill(desc)
					pp.uprint(desc)
				else:
					twrap.initial_indent = flag_name
					print(twrap.fill("<unknown>"))
		else:
			pp.uprint(markers[in_makeconf] + flag)
Example #27
0
def call_format_functions(best_match, matches):
    """Call information gathering functions and display the results."""

    if CONFIG['verbose']:
        repo = best_match.repo_name()
        pp.uprint(" * %s [%s]" % (pp.cpv(best_match.cp), pp.section(repo)))

    got_opts = False
    if any(QUERY_OPTS.values()):
        # Specific information requested, less formatting
        got_opts = True

    if QUERY_OPTS["herd"] or not got_opts:
        herds = best_match.metadata.herds(include_email=True)
        if any(not h[0] for h in herds):
            print(pp.warn("The packages metadata.xml has an empty <herd> tag"),
                  file=sys.stderr)
            herds = [x for x in herds if x[0]]
        herds = format_herds(herds)
        if QUERY_OPTS["herd"]:
            print_sequence(format_list(herds))
        else:
            for herd in herds:
                pp.uprint(format_line(herd, "Herd:        ", " " * 13))

    if QUERY_OPTS["maintainer"] or not got_opts:
        maints = format_maintainers(best_match.metadata.maintainers())
        if QUERY_OPTS["maintainer"]:
            print_sequence(format_list(maints))
        else:
            if not maints:
                pp.uprint(format_line([], "Maintainer:  ", " " * 13))
            else:
                for maint in maints:
                    pp.uprint(format_line(maint, "Maintainer:  ", " " * 13))

    if QUERY_OPTS["upstream"] or not got_opts:
        upstream = format_upstream(best_match.metadata.upstream())
        homepage = format_homepage(best_match.environment("HOMEPAGE"))
        if QUERY_OPTS["upstream"]:
            upstream = format_list(upstream)
        else:
            upstream = format_list(upstream, "Upstream:    ", " " * 13)
        print_sequence(upstream)
        print_sequence(homepage)

    if not got_opts:
        pkg_loc = best_match.package_path()
        pp.uprint(format_line(pkg_loc, "Location:    ", " " * 13))

    if QUERY_OPTS["keywords"] or not got_opts:
        # Get {<Package 'dev-libs/glib-2.20.5'>: [u'ia64', u'm68k', ...], ...}
        keyword_map = filter_keywords(matches)

        for match in matches:
            slot = match.environment('SLOT')
            verstr_len = len(match.fullversion) + len(slot)
            fmtd_keywords = format_keywords(keyword_map[match])
            keywords_line = format_keywords_line(match, fmtd_keywords, slot,
                                                 verstr_len)
            if QUERY_OPTS["keywords"]:
                pp.uprint(keywords_line)
            else:
                indent = " " * (16 + verstr_len)
                pp.uprint(format_line(keywords_line, "Keywords:    ", indent))

    if QUERY_OPTS["description"]:
        desc = best_match.metadata.descriptions()
        print_sequence(format_list(desc))

    if QUERY_OPTS["useflags"]:
        useflags = format_useflags(best_match.metadata.use())
        print_sequence(format_list(useflags))

    if QUERY_OPTS["license"] or not got_opts:
        _license = best_match.environment(["LICENSE"])
        if QUERY_OPTS["license"]:
            _license = format_list(_license)
        else:
            _license = format_list(_license, "License:     ", " " * 13)
        print_sequence(_license)

    if QUERY_OPTS["stablereq"]:
        # Get {<Package 'dev-libs/glib-2.20.5'>: [u'ia64', u'm68k', ...], ...}
        stablereq_map = stablereq(matches)
        for match in matches:
            slot = match.environment('SLOT')
            verstr_len = len(match.fullversion) + len(slot)
            fmtd_ccs = ','.join(sorted(stablereq_map[match]))
            stablereq_line = format_stablereq_line(match, fmtd_ccs, slot)
            #print("STABLEREQ:", )
            pp.uprint(stablereq_line)

    if QUERY_OPTS["xml"]:
        print_file(os.path.join(best_match.package_path(), 'metadata.xml'))
Example #28
0
def call_format_functions(best_match, matches):
	"""Call information gathering functions and display the results."""

	if CONFIG['verbose']:
		repo = best_match.repo_name()
		pp.uprint(" * %s [%s]" % (pp.cpv(best_match.cp), pp.section(repo)))

	got_opts = False
	if any(QUERY_OPTS.values()):
		# Specific information requested, less formatting
		got_opts = True

	if QUERY_OPTS["herd"] or not got_opts:
		herds = best_match.metadata.herds(include_email=True)
		if any(not h[0] for h in herds):
			print(pp.warn("The packages metadata.xml has an empty <herd> tag"),
				file = sys.stderr)
			herds = [x for x in herds if x[0]]
		herds = format_herds(herds)
		if QUERY_OPTS["herd"]:
			print_sequence(format_list(herds))
		else:
			for herd in herds:
				pp.uprint(format_line(herd, "Herd:        ", " " * 13))

	if QUERY_OPTS["maintainer"] or not got_opts:
		maints = format_maintainers(best_match.metadata.maintainers())
		if QUERY_OPTS["maintainer"]:
			print_sequence(format_list(maints))
		else:
			if not maints:
				pp.uprint(format_line([], "Maintainer:  ", " " * 13))
			else:
				for maint in maints:
					pp.uprint(format_line(maint, "Maintainer:  ", " " * 13))

	if QUERY_OPTS["upstream"] or not got_opts:
		upstream = format_upstream(best_match.metadata.upstream())
		homepage = format_homepage(best_match.environment("HOMEPAGE"))
		if QUERY_OPTS["upstream"]:
			upstream = format_list(upstream)
		else:
			upstream = format_list(upstream, "Upstream:    ", " " * 13)
		print_sequence(upstream)
		print_sequence(homepage)

	if not got_opts:
		pkg_loc = best_match.package_path()
		pp.uprint(format_line(pkg_loc, "Location:    ", " " * 13))

	if QUERY_OPTS["keywords"] or not got_opts:
		# Get {<Package 'dev-libs/glib-2.20.5'>: [u'ia64', u'm68k', ...], ...}
		keyword_map = filter_keywords(matches)

		for match in matches:
			slot = match.environment('SLOT')
			verstr_len = len(match.fullversion) + len(slot)
			fmtd_keywords = format_keywords(keyword_map[match])
			keywords_line = format_keywords_line(
				match, fmtd_keywords, slot, verstr_len
			)
			if QUERY_OPTS["keywords"]:
				pp.uprint(keywords_line)
			else:
				indent = " " * (16 + verstr_len)
				pp.uprint(format_line(keywords_line, "Keywords:    ", indent))

	if QUERY_OPTS["description"]:
		desc = best_match.metadata.descriptions()
		print_sequence(format_list(desc))

	if QUERY_OPTS["useflags"]:
		useflags = format_useflags(best_match.metadata.use())
		print_sequence(format_list(useflags))

	if QUERY_OPTS["stablereq"]:
		# Get {<Package 'dev-libs/glib-2.20.5'>: [u'ia64', u'm68k', ...], ...}
		stablereq_map = stablereq(matches)
		for match in matches:
			slot = match.environment('SLOT')
			verstr_len = len(match.fullversion) + len(slot)
			fmtd_ccs = ','.join(sorted(stablereq_map[match]))
			stablereq_line = format_stablereq_line(
				match, fmtd_ccs, slot
			)
			#print("STABLEREQ:", )
			pp.uprint(stablereq_line)

	if QUERY_OPTS["xml"]:
		print_file(os.path.join(best_match.package_path(), 'metadata.xml'))
Example #29
0
    def analyse_keywords(self, keywords=None):
        """This will scan the installed packages db and analyze the
		keywords used for installation and produce a report on them.
		"""
        print()
        system_keywords = portage.settings["ACCEPT_KEYWORDS"]
        arch = portage.settings["ARCH"]
        if self.options["prefix"]:
            # build a new keyword for testing
            system_keywords = "~" + arch + "-linux"
        if self.options["verbose"] or self.options["prefix"]:
            print("Current system ARCH =", arch)
            print("Current system ACCEPT_KEYWORDS =", system_keywords)
        system_keywords = system_keywords.split()
        self.printer = AnalysisPrinter("keywords", self.options["verbose"], system_keywords)
        self.analyser = KeywordAnalyser(arch, system_keywords, portage.db[portage.root]["vartree"].dbapi)
        # self.analyser.set_order(portage.settings["USE"].split())
        # only for testing
        test_use = portage.settings["USE"].split()
        if self.options["prefix"] and "prefix" not in test_use:
            print("ANALYSE_KEYWORDS() 'prefix' flag not found in system", "USE flags!!!  appending for testing")
            print()
            test_use.append("prefix")
        self.analyser.set_order(test_use)
        # /end testing

        if self.options["verbose"]:
            cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
            # print "Total number of installed ebuilds =", len(cpvs)
            keyword_users = gather_keywords_info(
                cpvs=cpvs,
                system_keywords=system_keywords,
                use_portage=self.options["portage"],
                keywords=keywords,
                analyser=self.analyser,
            )
            blankline = nl
        else:
            keyword_users = gather_keywords_info(
                system_keywords=system_keywords,
                use_portage=self.options["portage"],
                keywords=keywords,
                analyser=self.analyser,
            )
            blankline = lambda: None
            # print keyword_users
        keyword_keys = sorted(keyword_users)
        if self.options["verbose"]:
            print(" Keyword               System  #pkgs   cat/pkg-ver")
        elif not self.options["quiet"]:
            print(" Keyword               System  #pkgs")
        for keyword in keyword_keys:
            kwd_stable = keyword_users[keyword]["stable"]
            if len(kwd_stable):
                self.printer(keyword, " ", kwd_stable)
                blankline()
            kwd_testing = keyword_users[keyword]["testing"]
            if len(kwd_testing):
                self.printer(keyword, "~", kwd_testing)
                blankline()
            kwd_missing = keyword_users[keyword]["missing"]
            if len(kwd_missing):
                self.printer(keyword, "-", kwd_missing)
                blankline
        if not self.options["quiet"]:
            if self.analyser.mismatched:
                print("_________________________________________________")
                print(
                    (
                        "The following packages were found to have a \n"
                        + "different recorded ARCH than the current system ARCH"
                    )
                )
                for cpv in self.analyser.mismatched:
                    print("\t", pp.cpv(cpv))
            print("===================================================")
            print("Total number of keywords in report =", pp.output.red(str(len(keyword_keys))))
            if self.options["verbose"]:
                print("Total number of installed ebuilds =", pp.output.red(str(len(cpvs))))
            print()
Example #30
0
	def rebuild_keywords(self):
		#print("Module action not yet available")
		#print()
		"""This will scan the installed packages db and analyze the
		keywords used for installation and produce a report on them.
		"""
		system_keywords = portage.settings["ACCEPT_KEYWORDS"].split()
		output = RebuildPrinter(
			"keywords", self.options["pretend"], self.options["exact"],
			self.options['slot'])
		arch = portage.settings["ARCH"]
		if self.options["prefix"]:
			# build a new keyword for testing
			system_keywords = "~" + arch + "-linux"
		if self.options["verbose"] or self.options["prefix"]:
			print("Current system ARCH =", arch)
			print("Current system ACCEPT_KEYWORDS =", system_keywords)
		self.analyser = KeywordAnalyser( arch, system_keywords, portage.db[portage.root]["vartree"].dbapi)
		#self.analyser.set_order(portage.settings["USE"].split())
		# only for testing
		test_use = portage.settings["USE"].split()
		if self.options['prefix'] and 'prefix' not in test_use:
			print("REBUILD_KEYWORDS() 'prefix' flag not found in system",
				"USE flags!!!  appending for testing")
			print()
			test_use.append('prefix')
		self.analyser.set_order(test_use)
		# /end testing

		cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
		#print "Total number of installed ebuilds =", len(cpvs)
		pkgs, cp_counts = cpv_all_diff_keywords(
			cpvs=cpvs,
			system_keywords=system_keywords,
			use_portage=self.options['portage'],
			analyser = self.analyser
			)
		#print([pkgs[p][0].cpv for p in pkgs])
		pkg_keys = []
		if pkgs:
			pkg_keys = sorted(pkgs)
			#print(len(pkgs))
			if self.options["pretend"] and not self.options["quiet"]:
				print()
				print(pp.globaloption(
					"  -- These are the installed packages & keywords " +
					"that were detected"))
				print(pp.globaloption("     to need keyword settings other " +
					"than the defaults."))
				print()
			elif not self.options["quiet"]:
				print("  -- preparing pkgs for file entries")
			for pkg in pkg_keys:
				output(pkg, pkgs[pkg], cp_counts[pkg])
		if not self.options['quiet']:
			if self.analyser.mismatched:
				print("_________________________________________________")
				print(("The following packages were found to have a \n" +
					"different recorded ARCH than the current system ARCH"))
				for cpv in self.analyser.mismatched:
					print("\t", pp.cpv(cpv))
			print("===================================================")
			print("Total number of entries in report =",
				pp.output.red(str(len(pkg_keys))))
			if self.options["verbose"]:
				print("Total number of installed ebuilds =",
					pp.output.red(str(len(cpvs))))
			print()
			if not self.options["pretend"]:
				filepath = os.path.expanduser('~/package.keywords.test')
				self.save_file(filepath, output.lines)
Example #31
0
    def rebuild_keywords(self):
        # print("Module action not yet available")
        # print()
        """This will scan the installed packages db and analyze the
        keywords used for installation and produce a report on them.
        """
        system_keywords = portage.settings["ACCEPT_KEYWORDS"].split()
        output = RebuildPrinter(
            "keywords",
            self.options["pretend"],
            self.options["exact"],
            self.options["slot"],
        )
        arch = portage.settings["ARCH"]
        if self.options["prefix"]:
            # build a new keyword for testing
            system_keywords = "~" + arch + "-linux"
        if self.options["verbose"] or self.options["prefix"]:
            print("Current system ARCH =", arch)
            print("Current system ACCEPT_KEYWORDS =", system_keywords)
        self.analyser = KeywordAnalyser(
            arch, system_keywords, portage.db[portage.root]["vartree"].dbapi
        )
        # self.analyser.set_order(portage.settings["USE"].split())
        # only for testing
        test_use = portage.settings["USE"].split()
        if self.options["prefix"] and "prefix" not in test_use:
            print(
                "REBUILD_KEYWORDS() 'prefix' flag not found in system",
                "USE flags!!!  appending for testing",
            )
            print()
            test_use.append("prefix")
        self.analyser.set_order(test_use)
        # /end testing

        cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
        # print "Total number of installed ebuilds =", len(cpvs)
        pkgs, cp_counts = cpv_all_diff_keywords(
            cpvs=cpvs,
            system_keywords=system_keywords,
            use_portage=self.options["portage"],
            analyser=self.analyser,
        )
        # print([pkgs[p][0].cpv for p in pkgs])
        pkg_keys = []
        if pkgs:
            pkg_keys = sorted(pkgs)
            # print(len(pkgs))
            if self.options["pretend"] and not self.options["quiet"]:
                print()
                print(
                    pp.globaloption(
                        "  -- These are the installed packages & keywords "
                        + "that were detected"
                    )
                )
                print(
                    pp.globaloption(
                        "     to need keyword settings other " + "than the defaults."
                    )
                )
                print()
            elif not self.options["quiet"]:
                print("  -- preparing pkgs for file entries")
            for pkg in pkg_keys:
                output(pkg, pkgs[pkg], cp_counts[pkg])
        if not self.options["quiet"]:
            if self.analyser.mismatched:
                print("_________________________________________________")
                print(
                    (
                        "The following packages were found to have a \n"
                        + "different recorded ARCH than the current system ARCH"
                    )
                )
                for cpv in self.analyser.mismatched:
                    print("\t", pp.cpv(cpv))
            print("===================================================")
            print(
                "Total number of entries in report =", pp.output.red(str(len(pkg_keys)))
            )
            if self.options["verbose"]:
                print(
                    "Total number of installed ebuilds =", pp.output.red(str(len(cpvs)))
                )
            print()
            if not self.options["pretend"]:
                filepath = os.path.expanduser("~/package.keywords.test")
                self.save_file(filepath, output.lines)
Example #32
0
	def analyse_keywords(self, keywords=None):
		"""This will scan the installed packages db and analyze the
		keywords used for installation and produce a report on them.
		"""
		print()
		system_keywords = portage.settings["ACCEPT_KEYWORDS"]
		arch = portage.settings["ARCH"]
		if self.options["prefix"]:
			# build a new keyword for testing
			system_keywords = "~" + arch + "-linux"
		if self.options["verbose"] or self.options["prefix"]:
			print("Current system ARCH =", arch)
			print("Current system ACCEPT_KEYWORDS =", system_keywords)
		system_keywords = system_keywords.split()
		self.printer = AnalysisPrinter(
				"keywords",
				self.options["verbose"],
				system_keywords,
				width=self.options["width"],
				prepend=self.options["prepend"])
		self.analyser = KeywordAnalyser( arch, system_keywords, portage.db[portage.root]["vartree"].dbapi)
		#self.analyser.set_order(portage.settings["USE"].split())
		# only for testing
		test_use = portage.settings["USE"].split()
		if self.options['prefix'] and 'prefix' not in test_use:
			print("ANALYSE_KEYWORDS() 'prefix' flag not found in system",
				"USE flags!!!  appending for testing")
			print()
			test_use.append('prefix')
		self.analyser.set_order(test_use)
		# /end testing

		if self.options["verbose"]:
			cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
			#print "Total number of installed ebuilds =", len(cpvs)
			keyword_users = gather_keywords_info(
				cpvs=cpvs,
				system_keywords=system_keywords,
				use_portage=self.options['portage'],
				keywords=keywords, analyser = self.analyser
				)
			blankline = nl
		else:
			keyword_users = gather_keywords_info(
				system_keywords=system_keywords,
				use_portage=self.options['portage'],
				keywords=keywords,
				analyser = self.analyser
				)
			blankline = lambda: None
		#print keyword_users
		keyword_keys = sorted(keyword_users)
		if self.options["verbose"]:
			print(" Keyword               System  #pkgs   cat/pkg-ver")
		elif not self.options['quiet']:
			print(" Keyword               System  #pkgs")
		for keyword in keyword_keys:
			kwd_stable = keyword_users[keyword]["stable"]
			if len(kwd_stable):
				self.printer(keyword, " ", kwd_stable)
				blankline()
			kwd_testing = keyword_users[keyword]["testing"]
			if len(kwd_testing):
				self.printer(keyword, "~", kwd_testing)
				blankline()
			kwd_missing = keyword_users[keyword]["missing"]
			if len(kwd_missing):
				self.printer(keyword, "-", kwd_missing)
				blankline
		if not self.options['quiet']:
			if self.analyser.mismatched:
				print("_________________________________________________")
				print(("The following packages were found to have a \n" +
					"different recorded ARCH than the current system ARCH"))
				for cpv in self.analyser.mismatched:
					print("\t", pp.cpv(cpv))
			print("===================================================")
			print("Total number of keywords in report =",
				pp.output.red(str(len(keyword_keys))))
			if self.options["verbose"]:
				print("Total number of installed ebuilds =",
					pp.output.red(str(len(cpvs))))
			print()
Example #33
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
Example #34
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
Example #35
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
Example #36
0
def pmsg(package, msg):
    print(pp.cpv(str(package)) + ": " + msg)
Example #37
0
    def print_verbose(indent, cpv, use_conditional, depatom):
        """Verbosely prints a set of dep strings."""

        sep = ' ? ' if (depatom and use_conditional) else ''
        pp.uprint(indent + pp.cpv(cpv),
                  "(" + use_conditional + sep + depatom + ")")
Example #38
0
	def print_verbose(indent, cpv, use_conditional, depatom):
		"""Verbosely prints a set of dep strings."""

		sep = ' ? ' if (depatom and use_conditional) else ''
		pp.uprint(indent + pp.cpv(cpv), "(" + use_conditional +
			sep + depatom + ")")