diff options
Diffstat (limited to 'pym/portage/util.py')
-rw-r--r-- | pym/portage/util.py | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/pym/portage/util.py b/pym/portage/util.py index 9f7c92828..f6f21f586 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -28,9 +28,9 @@ from portage import _encodings 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 @@ -293,27 +293,40 @@ def grabdict_package(myfilename, juststrings=0, recursive=0): # 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=[] |