def findAtomForPackage(self, pkg, modified_use=None): """Return the best match for a given package from the arguments, or None if there are no matches. This matches virtual arguments against the PROVIDE metadata. This can raise an InvalidDependString exception if an error occurs while parsing PROVIDE.""" if modified_use is not None and modified_use is not pkg.use.enabled: pkg = pkg.copy() pkg._metadata["USE"] = " ".join(modified_use) # Atoms matched via PROVIDE must be temporarily transformed since # match_from_list() only works correctly when atom.cp == pkg.cp. rev_transform = {} for atom in self.iterAtomsForPackage(pkg): if atom.cp == pkg.cp: rev_transform[atom] = atom else: rev_transform[Atom( atom.replace(atom.cp, pkg.cp, 1), allow_wildcard=True, allow_repo=True, )] = atom best_match = best_match_to_list(pkg, iter(rev_transform)) if best_match: return rev_transform[best_match] return None
def ordered_by_atom_specificity(cpdict, pkg, repo=None): """ Return a list of matched values from the given cpdict, in ascending order by atom specificity. The rationale for this order is that package.* config files are typically written in ChangeLog like fashion, so it's most friendly if the order that the atoms are written does not matter. Therefore, settings from more specific atoms override those of less specific atoms. Without this behavior, settings from relatively unspecific atoms would (somewhat confusingly) override the settings of more specific atoms, requiring people to make adjustments to the order that atoms are listed in the config file in order to achieve desired results (and thus corrupting the ChangeLog like ordering of the file). """ if repo and repo != Package.UNKNOWN_REPO: pkg = pkg + _repo_separator + repo results = [] keys = list(cpdict) while keys: bestmatch = best_match_to_list(pkg, keys) if bestmatch: keys.remove(bestmatch) results.append(cpdict[bestmatch]) else: break if results: # reverse, so the most specific atoms come last results.reverse() return results
def best_match_to_list_wrapper(self, mypkg, mylist): """ This function uses best_match_to_list to create sorted list of matching atoms. """ ret = [] while mylist: m = best_match_to_list(mypkg, mylist) if m is not None: ret.append(m) mylist.remove(m) else: break return ret
def findAtomForPackage(self, pkg): """Return the best match for a given package from the arguments, or None if there are no matches. This matches virtual arguments against the PROVIDE metadata. This can raise an InvalidDependString exception if an error occurs while parsing PROVIDE.""" # Atoms matched via PROVIDE must be temporarily transformed since # match_from_list() only works correctly when atom.cp == pkg.cp. rev_transform = {} for atom in self.iterAtomsForPackage(pkg): if atom.cp == pkg.cp: rev_transform[atom] = atom else: rev_transform[Atom(atom.replace(atom.cp, pkg.cp, 1))] = atom best_match = best_match_to_list(pkg, iter(rev_transform)) if best_match: return rev_transform[best_match] return None
def findAtomForPackage(self, pkg, modified_use=None): """Return the best match for a given package from the arguments, or None if there are no matches. This matches virtual arguments against the PROVIDE metadata. This can raise an InvalidDependString exception if an error occurs while parsing PROVIDE.""" if modified_use is not None and modified_use is not pkg.use.enabled: pkg = pkg.copy() pkg._metadata["USE"] = " ".join(modified_use) # Atoms matched via PROVIDE must be temporarily transformed since # match_from_list() only works correctly when atom.cp == pkg.cp. rev_transform = {} for atom in self.iterAtomsForPackage(pkg): if atom.cp == pkg.cp: rev_transform[atom] = atom else: rev_transform[Atom(atom.replace(atom.cp, pkg.cp, 1), allow_wildcard=True, allow_repo=True)] = atom best_match = best_match_to_list(pkg, iter(rev_transform)) if best_match: return rev_transform[best_match] return None