Ejemplo n.º 1
0
def cpv_all_diff_keywords(
    cpvs=None,
    system_keywords=None,
    use_portage=False,
    #  override-able for testing
    keywords=portage.settings["ACCEPT_KEYWORDS"],
    analyser=None,
):
    """Analyze the installed pkgs 'keywords' for difference from ACCEPT_KEYWORDS

    @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
                    defaults to entire installed pkg db
    @param system_keywords: list of the system keywords
    @param keywords: user defined list of keywords to check and report on
                    or reports on all relevant keywords found to have been used.
    @param _get_kwds: overridable function for testing
    @param _get_used: overridable function for testing
    @rtype dict. {keyword:{"stable":[cat/pkg-ver,...],
                                               "testing":[cat/pkg-ver,...]}
    """
    if cpvs is None:
        cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
    keyword_users = {}
    cp_counts = {}
    for cpv in cpvs:
        if cpv.startswith("virtual"):
            continue
        if use_portage:
            keyword = analyser.get_inst_keyword_cpv(cpv)
        else:
            pkg = Package(cpv)
            keyword = analyser.get_inst_keyword_pkg(pkg)
        # print "returned keyword =", cpv, keyword, keyword[0]
        key = keyword[0]
        if key in ["~", "-"] and keyword not in system_keywords:
            atom = Atom("=" + cpv)
            if atom.cp not in keyword_users:
                keyword_users[atom.cp] = []
            if atom.cp not in cp_counts:
                cp_counts[atom.cp] = 0
            if key in ["~"]:
                atom.keyword = keyword
                atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(
                    atom.cpv, ["SLOT"]
                )[0]
                keyword_users[atom.cp].append(atom)
                cp_counts[atom.cp] += 1
            elif key in ["-"]:
                # print "adding cpv to missing:", cpv
                atom.keyword = "**"
                atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(
                    atom.cpv, ["SLOT"]
                )[0]
                keyword_users[atom.cp].append(atom)
                cp_counts[atom.cp] += 1
    return keyword_users, cp_counts
Ejemplo n.º 2
0
def cpv_all_diff_keywords(
		cpvs=None,
		system_keywords=None,
		use_portage=False,
		#  override-able for testing
		keywords=portage.settings["ACCEPT_KEYWORDS"],
		analyser = None
		):
	"""Analyze the installed pkgs 'keywords' for difference from ACCEPT_KEYWORDS

	@param cpvs: optional list of [cat/pkg-ver,...] to analyze or
			defaults to entire installed pkg db
	@param system_keywords: list of the system keywords
	@param keywords: user defined list of keywords to check and report on
			or reports on all relevant keywords found to have been used.
	@param _get_kwds: overridable function for testing
	@param _get_used: overridable function for testing
	@rtype dict. {keyword:{"stable":[cat/pkg-ver,...],
						   "testing":[cat/pkg-ver,...]}
	"""
	if cpvs is None:
		cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
	keyword_users = {}
	cp_counts = {}
	for cpv in cpvs:
		if cpv.startswith("virtual"):
			continue
		if use_portage:
			keyword = analyser.get_inst_keyword_cpv(cpv)
		else:
			pkg = Package(cpv)
			keyword = analyser.get_inst_keyword_pkg(pkg)
		#print "returned keyword =", cpv, keyword, keyword[0]
		key = keyword[0]
		if key in ["~", "-"] and keyword not in system_keywords:
			atom = Atom("="+cpv)
			if atom.cp not in keyword_users:
				keyword_users[atom.cp] = []
			if atom.cp not in cp_counts:
				cp_counts[atom.cp] = 0
			if key in ["~"]:
				atom.keyword = keyword
				atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(atom.cpv, ["SLOT"])[0]
				keyword_users[atom.cp].append(atom)
				cp_counts[atom.cp] += 1
			elif key in ["-"]:
				#print "adding cpv to missing:", cpv
				atom.keyword = "**"
				atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(atom.cpv, ["SLOT"])[0]
				keyword_users[atom.cp].append(atom)
				cp_counts[atom.cp] += 1
	return keyword_users, cp_counts
Ejemplo n.º 3
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
Ejemplo n.º 4
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