Esempio n. 1
0
def get_world_entries():
    '''
    Parse the world file for atoms.

    Return the set of atoms.
    '''
    f = open("/" + portage.WORLD_FILE, "r")
    atoms = set()
    for line in f.readlines():
        atom = line[:-1]
        if portage.isvalidatom(line[:-1]):
            atoms.add(atom)
    f.close()
    return atoms
Esempio n. 2
0
def get_world_entries():
    '''
    Parse the world file for atoms.

    Return the set of atoms.
    '''
    f = open("/" + portage.WORLD_FILE, "r")
    atoms = set()
    for line in f.readlines():
        atom = line[:-1]
        if portage.isvalidatom(line[:-1]):
            atoms.add(atom)
    f.close()
    return atoms
Esempio n. 3
0
def get_deps_both(cpv, depvars=DEPVARS):
    """
    Parses the dependency variables listed in depvars for cpv

    returns (set(dep_cps), set(dep_strs))
    """
    dep_cps = set()
    dep_strs = set()
    raw_deps = []
    try:
        raw_deps = portdb.aux_get(cpv, depvars)[0].split()
    except KeyError:
        return (dep_cps, dep_strs)
    for dep in portage.dep.use_reduce(" ".join(raw_deps), matchall=True, flat=True):
        # Ignore blockers, etc
        if portage.isvalidatom(dep):
            dep_strs.add(dep)
            dep_cps.add(portage.dep.dep_getkey(dep))
    return (dep_cps, dep_strs)
Esempio n. 4
0
def get_deps_both(cpv, depvars=DEPVARS):
    """
    Parses the dependency variables listed in depvars for cpv

    returns (set(dep_cps), set(dep_strs))
    """
    dep_cps = set()
    dep_strs = set()
    raw_deps = []
    try:
        raw_deps = portdb.aux_get(cpv, depvars)[0].split()
    except KeyError:
        return (dep_cps, dep_strs)
    for dep in portage.dep.use_reduce(' '.join(raw_deps),
                                      matchall=True,
                                      flat=True):
        # Ignore blockers, etc
        if portage.isvalidatom(dep):
            dep_strs.add(dep)
            dep_cps.add(portage.dep.dep_getkey(dep))
    return (dep_cps, dep_strs)
Esempio n. 5
0
	def _load(self):
		try:
			f = open(self._cache_filename, mode='rb')
			mypickle = pickle.Unpickler(f)
			try:
				mypickle.find_global = None
			except AttributeError:
				# TODO: If py3k, override Unpickler.find_class().
				pass
			self._cache_data = mypickle.load()
			f.close()
			del f
		except (SystemExit, KeyboardInterrupt):
			raise
		except Exception as e:
			if isinstance(e, EnvironmentError) and \
				getattr(e, 'errno', None) in (errno.ENOENT, errno.EACCES):
				pass
			else:
				writemsg("!!! Error loading '%s': %s\n" % \
					(self._cache_filename, str(e)), noiselevel=-1)
			del e

		cache_valid = self._cache_data and \
			isinstance(self._cache_data, dict) and \
			self._cache_data.get("version") == self._cache_version and \
			isinstance(self._cache_data.get("blockers"), dict)
		if cache_valid:
			# Validate all the atoms and counters so that
			# corruption is detected as soon as possible.
			invalid_items = set()
			for k, v in self._cache_data["blockers"].items():
				if not isinstance(k, basestring):
					invalid_items.add(k)
					continue
				try:
					if portage.catpkgsplit(k) is None:
						invalid_items.add(k)
						continue
				except portage.exception.InvalidData:
					invalid_items.add(k)
					continue
				if not isinstance(v, tuple) or \
					len(v) != 2:
					invalid_items.add(k)
					continue
				counter, atoms = v
				if not isinstance(counter, (int, long)):
					invalid_items.add(k)
					continue
				if not isinstance(atoms, (list, tuple)):
					invalid_items.add(k)
					continue
				invalid_atom = False
				for atom in atoms:
					if not isinstance(atom, basestring):
						invalid_atom = True
						break
					if atom[:1] != "!" or \
						not portage.isvalidatom(
						atom, allow_blockers=True):
						invalid_atom = True
						break
				if invalid_atom:
					invalid_items.add(k)
					continue

			for k in invalid_items:
				del self._cache_data["blockers"][k]
			if not self._cache_data["blockers"]:
				cache_valid = False

		if not cache_valid:
			self._cache_data = {"version":self._cache_version}
			self._cache_data["blockers"] = {}
		self._modified.clear()
Esempio n. 6
0
def get_best_deps(cpv, kws, release=None):
    """
    Returns a list of the best deps of a cpv, optionally matching a release,
    and with max of the specified keywords
    """
    # Take raw dependency strings and convert it to a list of atoms
    atoms = portage.portdb.aux_get(cpv, ['DEPEND', 'RDEPEND', 'PDEPEND'])
    atoms = ' '.join(atoms).split()  # consolidate atoms
    atoms = list(set(atoms))  # de-duplicate

    deps = set()

    for atom in atoms:
        if not portage.isvalidatom(atom):
            continue

        cpvs = match_wanted_atoms(atom, release)
        if not cpvs:
            logger.debug('Encountered an irrelevant atom: %s', atom)
            continue

        best_cpv_kws = ['', []]
        for candidate_cpv in cpvs:
            if STABLE:
                # Check that this version has unstable keywords
                unstable_kws = make_unstable(kws)
                cur_unstable_kws = make_unstable(
                    get_kws(candidate_cpv, arches=kws | unstable_kws)
                )
                if cur_unstable_kws.intersection(unstable_kws) != unstable_kws:
                    best_cpv_kws[0] = 'none'
                    logger.debug('Insufficiant unstable keywords in: %s',
                                 candidate_cpv)
                    continue

            candidate_kws = get_kws(candidate_cpv, arches=kws)
            if candidate_kws == kws:
                # This dep already has all requested keywords
                best_cpv_kws[0] = 'alreadythere'
                break

            # Select the version which needs least new keywords
            if len(candidate_kws) > len(best_cpv_kws[1]):
                best_cpv_kws = [candidate_cpv, candidate_kws]
            elif not best_cpv_kws[0]:
                # This means that none of the versions have any of the stable
                # keywords that *we checked* (i.e. kws).
                best_cpv_kws = [candidate_cpv, []]

        if best_cpv_kws[0] == 'alreadythere':
            logger.debug('DEP %s is already %s, ignoring', atom,
                         'stable' if STABLE else 'keyworded')
            continue
        elif best_cpv_kws[0] == 'none':
            continue
        elif not best_cpv_kws[0]:
            # We get this when the if STABLE: block above rejects everything.
            # This means that this atom does not have any versions with
            # unstable keywords matching the unstable keywords of the cpv
            # that pulls it.
            # This mostly happens because an || or use dep exists. However, we
            # make such deps strict while parsing
            # XXX: We arbitrarily select the most recent version for this case
            deps.add(cpvs[0])
        elif not best_cpv_kws[1]:
            # This means that none of the versions have any of the stable
            # keywords that *we checked* (i.e. kws). Hence, we do another pass;
            # this time checking *all* keywords.
            #
            # XXX: We duplicate some of the things from the for loop above
            # We don't need to duplicate anything that caused a 'continue' or
            # a 'break' above
            cpvs = match_wanted_atoms(atom, release)
            best_cpv_kws = ['', []]
            for candidate_cpv in cpvs:
                cur_kws = get_kws(candidate_cpv)
                if len(cur_kws) > len(best_cpv_kws[1]):
                    best_cpv_kws = [candidate_cpv, cur_kws]
                elif not best_cpv_kws[0]:
                    # This means that none of the versions have any of
                    # the stable keywords *at all*. No choice but to
                    # arbitrarily select the latest version in that case.
                    best_cpv_kws = [candidate_cpv, []]

            deps.add(best_cpv_kws[0])
        else:
            deps.add(best_cpv_kws[0])

    return list(deps)
Esempio n. 7
0
	def _load(self):
		try:
			f = open(self._cache_filename, mode='rb')
			mypickle = pickle.Unpickler(f)
			try:
				mypickle.find_global = None
			except AttributeError:
				# TODO: If py3k, override Unpickler.find_class().
				pass
			self._cache_data = mypickle.load()
			f.close()
			del f
		except (SystemExit, KeyboardInterrupt):
			raise
		except Exception as e:
			if isinstance(e, EnvironmentError) and \
				getattr(e, 'errno', None) in (errno.ENOENT, errno.EACCES):
				pass
			else:
				writemsg("!!! Error loading '%s': %s\n" % \
					(self._cache_filename, str(e)), noiselevel=-1)
			del e

		cache_valid = self._cache_data and \
			isinstance(self._cache_data, dict) and \
			self._cache_data.get("version") == self._cache_version and \
			isinstance(self._cache_data.get("blockers"), dict)
		if cache_valid:
			# Validate all the atoms and counters so that
			# corruption is detected as soon as possible.
			invalid_items = set()
			for k, v in self._cache_data["blockers"].items():
				if not isinstance(k, str):
					invalid_items.add(k)
					continue
				try:
					if portage.catpkgsplit(k) is None:
						invalid_items.add(k)
						continue
				except portage.exception.InvalidData:
					invalid_items.add(k)
					continue
				if not isinstance(v, tuple) or \
					len(v) != 2:
					invalid_items.add(k)
					continue
				counter, atoms = v
				if not isinstance(counter, int):
					invalid_items.add(k)
					continue
				if not isinstance(atoms, (list, tuple)):
					invalid_items.add(k)
					continue
				invalid_atom = False
				for atom in atoms:
					if not isinstance(atom, str):
						invalid_atom = True
						break
					if atom[:1] != "!" or \
						not portage.isvalidatom(
						atom, allow_blockers=True):
						invalid_atom = True
						break
				if invalid_atom:
					invalid_items.add(k)
					continue

			for k in invalid_items:
				del self._cache_data["blockers"][k]
			if not self._cache_data["blockers"]:
				cache_valid = False

		if not cache_valid:
			self._cache_data = {"version":self._cache_version}
			self._cache_data["blockers"] = {}
		self._modified.clear()
Esempio n. 8
0
def get_best_deps(cpv, kws, release=None):
    """
    Returns a list of the best deps of a cpv, optionally matching a release,
    and with max of the specified keywords
    """
    # Take raw dependency strings and convert it to a list of atoms
    atoms = portage.portdb.aux_get(cpv, ['DEPEND', 'RDEPEND', 'PDEPEND'])
    atoms = ' '.join(atoms).split()  # consolidate atoms
    atoms = list(set(atoms))  # de-duplicate

    deps = set()

    for atom in atoms:
        if not portage.isvalidatom(atom):
            continue

        cpvs = match_wanted_atoms(atom, release)
        if not cpvs:
            logger.debug('Encountered an irrelevant atom: %s', atom)
            continue

        best_cpv_kws = ['', []]
        for candidate_cpv in cpvs:
            if STABLE:
                # Check that this version has unstable keywords
                unstable_kws = make_unstable(kws)
                cur_unstable_kws = make_unstable(
                    get_kws(candidate_cpv, arches=kws | unstable_kws))
                if cur_unstable_kws.intersection(unstable_kws) != unstable_kws:
                    best_cpv_kws[0] = 'none'
                    logger.debug('Insufficiant unstable keywords in: %s',
                                 candidate_cpv)
                    continue

            candidate_kws = get_kws(candidate_cpv, arches=kws)
            if candidate_kws == kws:
                # This dep already has all requested keywords
                best_cpv_kws[0] = 'alreadythere'
                break

            # Select the version which needs least new keywords
            if len(candidate_kws) > len(best_cpv_kws[1]):
                best_cpv_kws = [candidate_cpv, candidate_kws]
            elif not best_cpv_kws[0]:
                # This means that none of the versions have any of the stable
                # keywords that *we checked* (i.e. kws).
                best_cpv_kws = [candidate_cpv, []]

        if best_cpv_kws[0] == 'alreadythere':
            logger.debug('DEP %s is already %s, ignoring', atom,
                         'stable' if STABLE else 'keyworded')
            continue
        elif best_cpv_kws[0] == 'none':
            continue
        elif not best_cpv_kws[0]:
            # We get this when the if STABLE: block above rejects everything.
            # This means that this atom does not have any versions with
            # unstable keywords matching the unstable keywords of the cpv
            # that pulls it.
            # This mostly happens because an || or use dep exists. However, we
            # make such deps strict while parsing
            # XXX: We arbitrarily select the most recent version for this case
            deps.add(cpvs[0])
        elif not best_cpv_kws[1]:
            # This means that none of the versions have any of the stable
            # keywords that *we checked* (i.e. kws). Hence, we do another pass;
            # this time checking *all* keywords.
            #
            # XXX: We duplicate some of the things from the for loop above
            # We don't need to duplicate anything that caused a 'continue' or
            # a 'break' above
            cpvs = match_wanted_atoms(atom, release)
            best_cpv_kws = ['', []]
            for candidate_cpv in cpvs:
                cur_kws = get_kws(candidate_cpv)
                if len(cur_kws) > len(best_cpv_kws[1]):
                    best_cpv_kws = [candidate_cpv, cur_kws]
                elif not best_cpv_kws[0]:
                    # This means that none of the versions have any of
                    # the stable keywords *at all*. No choice but to
                    # arbitrarily select the latest version in that case.
                    best_cpv_kws = [candidate_cpv, []]

            deps.add(best_cpv_kws[0])
        else:
            deps.add(best_cpv_kws[0])

    return list(deps)
Esempio n. 9
0
    Given a key, returns a reverse-dependency list of that key using the tinderbox rindex
    list will be a sorted list of unique cpvs
    """
    import urllib2

    RINDEX = "http://tinderbox.dev.gentoo.org/misc/rindex"
    revdeps = set()
    try:
        rdeps_raw = urllib2.urlopen("/".join([RINDEX, key])).read().split()
    except urllib2.HTTPError, e:
        if e.getcode() == 404:
            return revdeps
        raise
    for i in rdeps_raw:
        cpv = i.split(":")[0]
        if portage.isvalidatom("=" + cpv):
            revdeps.add(cpv)
    revdeps = list(revdeps)
    revdeps.sort()
    return revdeps


def get_revdeps_portage(key):
    """
    Given a key, returns a reverse-dependency list of that key using portage API
    list will be a sorted list of unique cpvs
    """
    revdeps = set()
    for cp in portdb.cp_all():
        cpvrs = portdb.xmatch("match-all", cp)
        for cpvr in cpvrs:
Esempio n. 10
0
    """
    Given a key, returns a reverse-dependency list of that key using the tinderbox rindex
    list will be a sorted list of unique cpvs
    """
    import urllib2
    RINDEX = "http://tinderbox.dev.gentoo.org/misc/rindex"
    revdeps = set()
    try:
        rdeps_raw = urllib2.urlopen('/'.join([RINDEX, key])).read().split()
    except urllib2.HTTPError, e:
        if e.getcode() == 404:
            return revdeps
        raise
    for i in rdeps_raw:
        cpv = i.split(':')[0]
        if portage.isvalidatom('=' + cpv):
            revdeps.add(cpv)
    revdeps = list(revdeps)
    revdeps.sort()
    return revdeps


def get_revdeps_portage(key):
    """
    Given a key, returns a reverse-dependency list of that key using portage API
    list will be a sorted list of unique cpvs
    """
    revdeps = set()
    for cp in portdb.cp_all():
        cpvrs = portdb.xmatch('match-all', cp)
        for cpvr in cpvrs:
Esempio n. 11
0
#!/usr/bin/env python

import os
import sys
import portage

if len(sys.argv) != 2 or not portage.isvalidatom(sys.argv[1]):
	sys.stderr.write("usage: %s <atom>\n" % os.path.basename(sys.argv[0]))
	sys.exit(1)

input_atom = portage.dep.Atom(sys.argv[1])
settings = portage.config(config_profile_path="",
	local_config=False)
settings["ACCEPT_KEYWORDS"] = "**"
settings.backup_changes("ACCEPT_KEYWORDS")
settings.lock()
porttree = portage.portagetree(settings=settings)
portdb = porttree.dbapi
trees = {"/" : {"porttree":porttree}}
dep_keys = ("DEPEND", "RDEPEND", "PDEPEND")

for cp in portdb.cp_all():
	for cpv in portdb.cp_list(cp):
		metadata = dict(zip(dep_keys,
			portdb.aux_get(cpv, dep_keys)))
		dep_str = " ".join(metadata[k] for k in dep_keys)
		success, atoms = portage.dep_check(dep_str,
			None, settings, use="all",
			trees=trees, myroot=settings["ROOT"])

		if not success:
Esempio n. 12
0
def is_valid_package_atom(x):
	if "/" not in x:
		alphanum = re.search(r'\w', x)
		if alphanum:
			x = x[:alphanum.start()] + "cat/" + x[alphanum.start():]
	return portage.isvalidatom(x, allow_blockers=False)
def is_valid_package_atom(x):
    if "/" not in x:
        alphanum = re.search(r"\w", x)
        if alphanum:
            x = x[: alphanum.start()] + "cat/" + x[alphanum.start() :]
    return portage.isvalidatom(x, allow_blockers=False)