Make parse_updates() and update_dbentry() use Atom instances.
authorZac Medico <zmedico@gentoo.org>
Sat, 12 Sep 2009 16:09:40 +0000 (16:09 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 12 Sep 2009 16:09:40 +0000 (16:09 -0000)
svn path=/main/trunk/; revision=14230

pym/portage/update.py

index 56e6709c0626bd4e1f45c0f647ea60f2e3d26832..9b51eb75fac24e0d381ecb9c2ac568053ada5ae1 100644 (file)
@@ -13,7 +13,7 @@ from portage import _unicode_decode
 from portage import _unicode_encode
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
-       'portage.dep:dep_getkey,get_operator,isvalidatom,isjustname,remove_slot',
+       'portage.dep:Atom,dep_getkey,get_operator,isvalidatom,remove_slot',
        'portage.util:ConfigProtect,grabfile,new_protect_filename,' + \
                'normalize_path,write_atomic,writemsg',
        'portage.versions:ververify'
@@ -27,8 +27,9 @@ ignored_dbentries = ("CONTENTS", "environment.bz2")
 
 def update_dbentry(update_cmd, mycontent):
        if update_cmd[0] == "move":
-               old_value, new_value = update_cmd[1], update_cmd[2]
+               old_value = str(update_cmd[1])
                if old_value in mycontent:
+                       new_value = str(update_cmd[2])
                        old_value = re.escape(old_value);
                        mycontent = re.sub(old_value+"(:|$|\\s)", new_value+"\\1", mycontent)
                        def myreplace(matchobj):
@@ -41,7 +42,7 @@ def update_dbentry(update_cmd, mycontent):
                                else:
                                        return "".join(matchobj.groups())
                        mycontent = re.sub("(%s-)(\\S*)" % old_value, myreplace, mycontent)
-       elif update_cmd[0] == "slotmove" and get_operator(update_cmd[1]) is None:
+       elif update_cmd[0] == "slotmove" and update_cmd[1].operator is None:
                pkg, origslot, newslot = update_cmd[1:]
                old_value = "%s:%s" % (pkg, origslot)
                if old_value in mycontent:
@@ -137,21 +138,38 @@ def parse_updates(mycontent):
                        if len(mysplit) != 3:
                                errors.append(_("ERROR: Update command invalid '%s'") % myline)
                                continue
-                       orig_value, new_value = mysplit[1], mysplit[2]
-                       for cp in (orig_value, new_value):
-                               if not (isvalidatom(cp) and isjustname(cp)):
+                       for i in (1, 2):
+                               try:
+                                       atom = Atom(mysplit[i])
+                               except InvalidAtom:
+                                       atom = None
+                               else:
+                                       if atom.blocker or atom != atom.cp:
+                                               atom = None
+                               if atom is not None:
+                                       mysplit[i] = atom
+                               else:
                                        errors.append(
                                                _("ERROR: Malformed update entry '%s'") % myline)
-                                       continue
+                                       break
                if mysplit[0] == "slotmove":
                        if len(mysplit)!=4:
                                errors.append(_("ERROR: Update command invalid '%s'") % myline)
                                continue
                        pkg, origslot, newslot = mysplit[1], mysplit[2], mysplit[3]
-                       if not isvalidatom(pkg):
+                       try:
+                               atom = Atom(pkg)
+                       except InvalidAtom:
+                               atom = None
+                       else:
+                               if atom.blocker:
+                                       atom = None
+                       if atom is not None:
+                               mysplit[1] = atom
+                       else:
                                errors.append(_("ERROR: Malformed update entry '%s'") % myline)
                                continue
-               
+
                # The list of valid updates is filtered by continue statements above.
                myupd.append(mysplit)
        return myupd, errors