from portage import _os_merge
from portage import _unicode_encode
from portage import _unicode_decode
-from portage.exception import PortageException, FileNotFound, \
+from portage.exception import InvalidAtom, PortageException, FileNotFound, \
OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem
-from portage.dep import isvalidatom
+from portage.dep import Atom, isvalidatom
from portage.localization import _
from portage.proxy.objectproxy import ObjectProxy
from portage.cache.mappings import UserDict
# We need to call keys() here in order to avoid the possibility of
# "RuntimeError: dictionary changed size during iteration"
# when an invalid atom is deleted.
- for x in pkgs.keys():
- if not isvalidatom(x):
- del(pkgs[x])
- writemsg(_("--- Invalid atom in %s: %s\n") % (myfilename, x),
+ atoms = {}
+ for k, v in pkgs.iteritems():
+ try:
+ k = Atom(k)
+ except InvalidAtom:
+ writemsg(_("--- Invalid atom in %s: %s\n") % (myfilename, k),
noiselevel=-1)
- return pkgs
+ else:
+ atoms[k] = v
+ return atoms
def grabfile_package(myfilename, compatlevel=0, recursive=0):
pkgs=grabfile(myfilename, compatlevel, recursive=recursive)
- for x in range(len(pkgs)-1, -1, -1):
- pkg = pkgs[x]
+ atoms = []
+ for pkg in pkgs:
+ pkg_orig = pkg
# for packages and package.mask files
if pkg[:1] == "-":
pkg = pkg[1:]
if pkg[:1] == "*":
pkg = pkg[1:]
- if not isvalidatom(pkg):
+ try:
+ pkg = Atom(pkg)
+ except InvalidAtom:
writemsg(_("--- Invalid atom in %s: %s\n") % (myfilename, pkgs[x]),
noiselevel=-1)
- del(pkgs[x])
- return pkgs
+ else:
+ if pkg_orig == str(pkg):
+ # normal atom, so return as Atom instance
+ atoms.append(pkg)
+ else:
+ # atom has special prefix, so return as string
+ atoms.append(pkg_orig)
+ return atoms
def grablines(myfilename,recursive=0):
mylines=[]