Exemple #1
0
def cpv_all_diff_use(
    cpvs=None,
    system_flags=None,
    #  override-able for testing
    _get_flags=get_flags,
    _get_used=get_installed_use,
):
    """Data gathering and analysis function determines
    the difference between the current default USE flag settings
    and the currently installed pkgs recorded USE flag settings

    @type cpvs: list
    @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
                    defaults to entire installed pkg db
    @type: system_flags: list
    @param system_flags: the current default USE flags as defined
                    by portage.settings["USE"].split()
    @type _get_flags: function
    @param _get_flags: ovride-able for testing,
                    defaults to gentoolkit.enalyze.lib.get_flags
    @param _get_used: ovride-able for testing,
                    defaults to gentoolkit.enalyze.lib.get_installed_use
    @rtype dict. {cpv:['flag1', '-flag2',...]}
    """
    if cpvs is None:
        cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
    cpvs.sort()
    data = {}
    cp_counts = {}
    # pass them in to override for tests
    flags = FlagAnalyzer(
        system_flags,
        filter_defaults=True,
        target="USE",
        _get_flags=_get_flags,
        _get_used=get_installed_use,
    )
    for cpv in cpvs:
        plus, minus, unset = flags.analyse_cpv(cpv)
        atom = Atom("=" + cpv)
        atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(
            atom.cpv, ["SLOT"]
        )[0]
        for flag in minus:
            plus.add("-" + flag)
        if len(plus):
            if atom.cp not in data:
                data[atom.cp] = []
            if atom.cp not in cp_counts:
                cp_counts[atom.cp] = 0
            atom.use = list(plus)
            data[atom.cp].append(atom)
            cp_counts[atom.cp] += 1
    return data, cp_counts
Exemple #2
0
def cpv_all_diff_use(
		cpvs=None,
		system_flags=None,
		#  override-able for testing
		_get_flags=get_flags,
		_get_used=get_installed_use
		):
	"""Data gathering and analysis function determines
	the difference between the current default USE flag settings
	and the currently installed pkgs recorded USE flag settings

	@type cpvs: list
	@param cpvs: optional list of [cat/pkg-ver,...] to analyze or
			defaults to entire installed pkg db
	@type: system_flags: list
	@param system_flags: the current default USE flags as defined
			by portage.settings["USE"].split()
	@type _get_flags: function
	@param _get_flags: ovride-able for testing,
			defaults to gentoolkit.enalyze.lib.get_flags
	@param _get_used: ovride-able for testing,
			defaults to gentoolkit.enalyze.lib.get_installed_use
	@rtype dict. {cpv:['flag1', '-flag2',...]}
	"""
	if cpvs is None:
		cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
	cpvs.sort()
	data = {}
	cp_counts = {}
	# pass them in to override for tests
	flags = FlagAnalyzer(system_flags,
		filter_defaults=True,
		target="USE",
		_get_flags=_get_flags,
		_get_used=get_installed_use
	)
	for cpv in cpvs:
		plus, minus, unset = flags.analyse_cpv(cpv)
		atom = Atom("="+cpv)
		atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(atom.cpv, ["SLOT"])[0]
		for flag in minus:
			plus.add("-"+flag)
		if len(plus):
			if atom.cp not in data:
				data[atom.cp] = []
			if atom.cp not in cp_counts:
				cp_counts[atom.cp] = 0
			atom.use = list(plus)
			data[atom.cp].append(atom)
			cp_counts[atom.cp] += 1
	return data, cp_counts
Exemple #3
0
    def analyse_packages(self):
        """This will scan the installed packages db and analyze the
        USE flags used for installation and produce a report.

        @type target: string
        @param target: the target to be analyzed, one of ["use", "pkguse"]
        """
        system_use = portage.settings["USE"].split()
        if self.options["verbose"]:
            cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
            key_width = 45
        else:
            cpvs = get_installed_cpvs()
            key_width = 1

        self.printer = AnalysisPrinter(
            "packages",
            self.options["verbose"],
            key_width=key_width,
            width=self.options["width"],
            prepend=self.options["prepend"],
        )

        cpvs = sorted(cpvs)
        flags = FlagAnalyzer(system=system_use,
                             filter_defaults=False,
                             target="USE")

        if self.options["verbose"]:
            print("   cat/pkg-ver                             USE Flags")
            #   "app-emulation/emul-linux-x86-sdl-20100915 ...."
            # blankline = nl
        elif not self.options["quiet"]:
            print("   cat/pkg-ver                             USE Flags")
            # blankline = lambda: None
        for cpv in cpvs:
            (flag_plus, flag_neg, unset) = flags.analyse_cpv(cpv)
            if self.options["unset"]:
                self.printer(
                    cpv, "",
                    (sorted(flag_plus), sorted(flag_neg), sorted(unset)))
            else:
                self.printer(cpv, "",
                             (sorted(flag_plus), sorted(flag_neg), []))
        if not self.options["quiet"]:
            print("===================================================")
            print(
                "Total number of installed ebuilds =",
                pp.output.red(str(len([x for x in cpvs]))),
            )
            print()
Exemple #4
0
    def __init__(self, cpv):
        """
        Initialize the class with the cpv. All metadata are read from portage
        """
        self.repo, self.counter, self.build_time, self.size = VARDB.aux_get(cpv, ['repository', 'COUNTER', 'BUILD_TIME', 'SIZE'])

        system_use = portage.settings['USE'].split()
        fa = FlagAnalyzer(system=system_use)
        self.flags = fa.analyse_cpv(cpv)

        arch = portage.settings['ARCH']
        accept_keywords = portage.settings['ACCEPT_KEYWORDS'].split()
        ka = KeywordAnalyser(arch=arch, accept_keywords=accept_keywords)
        self.keyword = ka.get_inst_keyword_cpv(cpv)
Exemple #5
0
	def analyse_packages(self):
		"""This will scan the installed packages db and analyze the
		USE flags used for installation and produce a report.

		@type target: string
		@param target: the target to be analyzed, one of ["use", "pkguse"]
		"""
		system_use = portage.settings["USE"].split()
		if self.options["verbose"]:
			cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
			key_width = 45
		else:
			cpvs = get_installed_cpvs()
			key_width = 1

		self.printer = AnalysisPrinter(
				"packages",
				self.options["verbose"],
				key_width=key_width,
				width=self.options["width"],
				prepend=self.options["prepend"])

		cpvs = sorted(cpvs)
		flags = FlagAnalyzer(
					system=system_use,
					filter_defaults=False,
					target="USE"
					)

		if self.options["verbose"]:
			print("   cat/pkg-ver                             USE Flags")
				#   "app-emulation/emul-linux-x86-sdl-20100915 ...."
			blankline = nl
		elif not self.options['quiet']:
			print("   cat/pkg-ver                             USE Flags")
			blankline = lambda: None
		for cpv in cpvs:
			(flag_plus, flag_neg, unset) = flags.analyse_cpv(cpv)
			if self.options["unset"]:
				self.printer(cpv, "", (sorted(flag_plus), sorted(flag_neg),
					sorted(unset)))
			else:
				self.printer(cpv, "", (sorted(flag_plus), sorted(flag_neg), []))
		if not self.options['quiet']:
			print("===================================================")
			print("Total number of installed ebuilds =",
				pp.output.red(str(len([x for x in cpvs]))))
			print()
Exemple #6
0
def gather_flags_info(
		cpvs=None,
		system_flags=None,
		include_unset=False,
		target="USE",
		use_portage=False,
		#  override-able for testing
		_get_flags=get_flags,
		_get_used=get_installed_use
		):
	"""Analyze the installed pkgs USE flags for frequency of use

	@type cpvs: list
	@param cpvs: optional list of [cat/pkg-ver,...] to analyze or
			defaults to entire installed pkg db
	@type: system_flags: list
	@param system_flags: the current default USE flags as defined
			by portage.settings["USE"].split()
	@type include_unset: bool
	@param include_unset: controls the inclusion of unset USE flags in the report.
	@type target: string
	@param target: the environment variable being analyzed
			one of ["USE", "PKGUSE"]
	@type _get_flags: function
	@param _get_flags: ovride-able for testing,
			defaults to gentoolkit.enalyze.lib.get_flags
	@param _get_used: ovride-able for testing,
			defaults to gentoolkit.enalyze.lib.get_installed_use
	@rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unset":[]}
	"""
	if cpvs is None:
		cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
	# pass them in to override for tests
	flags = FlagAnalyzer(system_flags,
		filter_defaults=False,
		target=target,
		_get_flags=_get_flags,
		_get_used=get_installed_use
	)
	flag_users = {}
	for cpv in cpvs:
		if cpv.startswith("virtual"):
			continue
		if use_portage:
			plus, minus, unset = flags.analyse_cpv(cpv)
		else:
			pkg = Package(cpv)
			plus, minus, unset = flags.analyse_pkg(pkg)
		for flag in plus:
			if flag in flag_users:
				flag_users[flag]["+"].append(cpv)
			else:
				flag_users[flag] = {"+": [cpv], "-": []}
		for flag in minus:
			if flag in flag_users:
				flag_users[flag]["-"].append(cpv)
			else:
				flag_users[flag] = {"+":[], "-": [cpv]}
		if include_unset:
			for flag in unset:
				if flag in flag_users:
					if "unset" in flag_users[flag]:
						flag_users[flag]["unset"].append(cpv)
					else:
						flag_users[flag]["unset"] = [cpv]
				else:
					flag_users[flag] = {"+": [], "-": [], "unset": [cpv]}
	return flag_users
Exemple #7
0
def gather_flags_info(
    cpvs=None,
    system_flags=None,
    include_unset=False,
    target="USE",
    use_portage=False,
    #  override-able for testing
    _get_flags=get_flags,
    _get_used=get_installed_use,
):
    """Analyze the installed pkgs USE flags for frequency of use

	@type cpvs: list
	@param cpvs: optional list of [cat/pkg-ver,...] to analyze or
			defaults to entire installed pkg db
	@type: system_flags: list
	@param system_flags: the current default USE flags as defined
			by portage.settings["USE"].split()
	@type include_unset: bool
	@param include_unset: controls the inclusion of unset USE flags in the report.
	@type target: string
	@param target: the environment variable being analyzed
			one of ["USE", "PKGUSE"]
	@type _get_flags: function
	@param _get_flags: ovride-able for testing,
			defaults to gentoolkit.enalyze.lib.get_flags
	@param _get_used: ovride-able for testing,
			defaults to gentoolkit.enalyze.lib.get_installed_use
	@rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unset":[]}
	"""
    if cpvs is None:
        cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
        # pass them in to override for tests
    flags = FlagAnalyzer(
        system_flags, filter_defaults=False, target=target, _get_flags=_get_flags, _get_used=get_installed_use
    )
    flag_users = {}
    for cpv in cpvs:
        if cpv.startswith("virtual"):
            continue
        if use_portage:
            plus, minus, unset = flags.analyse_cpv(cpv)
        else:
            pkg = Package(cpv)
            plus, minus, unset = flags.analyse_pkg(pkg)
        for flag in plus:
            if flag in flag_users:
                flag_users[flag]["+"].append(cpv)
            else:
                flag_users[flag] = {"+": [cpv], "-": []}
        for flag in minus:
            if flag in flag_users:
                flag_users[flag]["-"].append(cpv)
            else:
                flag_users[flag] = {"+": [], "-": [cpv]}
        if include_unset:
            for flag in unset:
                if flag in flag_users:
                    if "unset" in flag_users[flag]:
                        flag_users[flag]["unset"].append(cpv)
                    else:
                        flag_users[flag]["unset"] = [cpv]
                else:
                    flag_users[flag] = {"+": [], "-": [], "unset": [cpv]}
    return flag_users