Merged from trunk 10869:10875
authorFabian Groffen <grobian@gentoo.org>
Tue, 1 Jul 2008 17:32:45 +0000 (17:32 -0000)
committerFabian Groffen <grobian@gentoo.org>
Tue, 1 Jul 2008 17:32:45 +0000 (17:32 -0000)
   | 10870   | Py3k compatibility patch #1 by Ali Polatel <hawking@g.o>.    |
   | zmedico | Replace dict.has_key() calls with "in" and "not in"          |
   |         | operators..                                                  |

   | 10871   | Py3k compatibility patch #2 by Ali Polatel <hawking@g.o>.    |
   | zmedico | Replace dict.has_key() calls with "in" and "not in"          |
   |         | operators.                                                   |

   | 10872   | Py3k compatibility patch #3 by Ali Polatel <hawking@g.o>.    |
   | zmedico | Replace dict.has_key() calls with "in" and "not in"          |
   |         | operators.                                                   |

   | 10873   | Py3k compatibility patch #4 by Ali Polatel <hawking@g.o>.    |
   | zmedico | Replace dict.has_key() calls with "in" and "not in"          |
   |         | operators.                                                   |

   | 10874   | Py3k compatibility patch #5 by Ali Polatel <hawking@g.o>.    |
   | zmedico | Replace dict.has_key() calls with "in" and "not in"          |
   |         | operators.                                                   |

   | 10875   | Py3k compatibility patch #6 by Ali Polatel <hawking@g.o>.    |
   | zmedico | Replace dict.has_key() calls with "in" and "not in"          |
   |         | operators.                                                   |

svn path=/main/branches/prefix/; revision=10881

26 files changed:
bin/dispatch-conf
bin/dohtml
bin/glsa-check
bin/repoman
pym/_emerge/__init__.py
pym/portage/__init__.py
pym/portage/cache/mappings.py
pym/portage/cache/metadata_overlay.py
pym/portage/cache/sql_template.py
pym/portage/cache/template.py
pym/portage/cvstree.py
pym/portage/dbapi/__init__.py
pym/portage/dbapi/bintree.py
pym/portage/dbapi/vartree.py
pym/portage/dbapi/virtual.py
pym/portage/dispatch_conf.py
pym/portage/elog/__init__.py
pym/portage/elog/filtering.py
pym/portage/elog/messages.py
pym/portage/elog/mod_mail.py
pym/portage/elog/mod_mail_summary.py
pym/portage/getbinpkg.py
pym/portage/glsa.py
pym/portage/locks.py
pym/portage/manifest.py
pym/portage/util.py

index 28516c9dc792d3b23cf7c35175a708e80d69a74f..a8159cdc96a9be91003a89f5d4fa37d6831095d5 100755 (executable)
@@ -75,7 +75,7 @@ class dispatch:
 
         self.options = portage.dispatch_conf.read_config(MANDATORY_OPTS)
 
-        if self.options.has_key("log-file"):
+        if "log-file" in self.options:
             if os.path.isfile(self.options["log-file"]):
                 shutil.copy(self.options["log-file"], self.options["log-file"] + '.old')
             if os.path.isfile(self.options["log-file"]) \
@@ -273,7 +273,7 @@ class dispatch:
                     show_new_diff = 1
                     continue
                 elif c == 'e':
-                    if not os.environ.has_key('EDITOR'):
+                    if 'EDITOR' not in os.environ:
                         os.environ['EDITOR']='nano'
                     os.system(os.environ['EDITOR'] + ' ' + newconf)
                     continue
@@ -337,7 +337,7 @@ class dispatch:
             conf  = re.sub (r'\._cfg\d+_', '', nconf)
             dir   = re.match (r'^(.+)/', nconf).group (1)
 
-            if h.has_key (conf):
+            if conf in h:
                 mrgconf = re.sub(r'\._cfg', '._mrg', h[conf]['new'])
                 if os.path.exists(mrgconf):
                     os.unlink(mrgconf)
index d65a31a15c4dcf9935b06a5c65cb59769effb3e8..db5aaaba67a98c911f6b99de37d8d973e6f4fde1 100755 (executable)
@@ -86,11 +86,11 @@ class OptionsClass:
                self.ED = ""
                self.DOCDESTTREE = ""
                
-               if os.environ.has_key("PF"):
+               if "PF" in os.environ:
                        self.PF = os.environ["PF"]
                if os.environ.has_key("ED"):
                        self.ED = os.environ["ED"]
-               if os.environ.has_key("_E_DOCDESTTREE_"):
+               if "_E_DOCDESTTREE_" in os.environ:
                        self.DOCDESTTREE = os.environ["_E_DOCDESTTREE_"]
                
                self.allowed_exts = [ 'htm', 'html', 'css', 'js',
index 09b07f49fed7cc84910eb085593dc4a0be321a4e..1e3533d1ea7f7aae7b47cd0253fe5aca8171a8a6 100644 (file)
@@ -295,12 +295,12 @@ if mode == "mail":
        # color doesn't make any sense for mail
        nocolor()
 
-       if portage.settings.has_key("PORTAGE_ELOG_MAILURI"):
+       if "PORTAGE_ELOG_MAILURI" in portage.settings:
                myrecipient = portage.settings["PORTAGE_ELOG_MAILURI"].split()[0]
        else:
                myrecipient = "root@localhost"
        
-       if portage.settings.has_key("PORTAGE_ELOG_MAILFROM"):
+       if "PORTAGE_ELOG_MAILFROM" in portage.settings:
                myfrom = portage.settings["PORTAGE_ELOG_MAILFROM"]
        else:
                myfrom = "glsa-check"
index 58f048725e72a1e9f3e0b75cbcf2a5cd2dd0a694..66eed48b7d1b01af2930a2bfaa0d54e2eb61d62b 100755 (executable)
@@ -660,7 +660,7 @@ if os.path.exists(descfile):
                if not os.path.isdir(portdir+"/profiles/"+arch[1]):
                        print "Invalid "+arch[2]+" profile ("+arch[1]+") for arch "+arch[0]
                        continue
-               if profiles.has_key(arch[0]):
+               if arch[0] in profiles:
                        profiles[arch[0]]+= [[arch[1], arch[2]]]
                else:
                        profiles[arch[0]] = [[arch[1], arch[2]]]
@@ -668,7 +668,7 @@ if os.path.exists(descfile):
        for x in repoman_settings.archlist():
                if x[0] == "~":
                        continue
-               if not profiles.has_key(x):
+               if x not in profiles:
                        print red("\""+x+"\" doesn't have a valid profile listed in profiles.desc.")
                        print red("You need to either \"cvs update\" your profiles dir or follow this")
                        print red("up with the "+x+" team.")
@@ -1333,7 +1333,7 @@ for x in scanlist:
 
                # uselist checks - local
                mykey = portage.dep_getkey(catpkg)
-               if luselist.has_key(mykey):
+               if mykey in luselist:
                        for mypos in range(len(myuse)-1,-1,-1):
                                if myuse[mypos] and (myuse[mypos] in luselist[mykey]):
                                        del myuse[mypos]
@@ -1378,7 +1378,7 @@ for x in scanlist:
                                if myskey not in kwlist:
                                        stats["KEYWORDS.invalid"] += 1
                                        fails["KEYWORDS.invalid"].append(x+"/"+y+".ebuild: %s" % mykey)
-                               elif not profiles.has_key(myskey):
+                               elif myskey not in profiles:
                                        stats["KEYWORDS.invalid"] += 1
                                        fails["KEYWORDS.invalid"].append(x+"/"+y+".ebuild: %s (profile invalid)" % mykey)
 
@@ -1418,7 +1418,7 @@ for x in scanlist:
 
                for keyword,arch,groups in arches:
 
-                       if not profiles.has_key(arch):
+                       if arch not in profiles:
                                # A missing profile will create an error further down
                                # during the KEYWORDS verification.
                                continue
@@ -1831,7 +1831,7 @@ else:
                if "PORTAGE_GPG_KEY" not in repoman_settings:
                        raise portage.exception.MissingParameter("PORTAGE_GPG_KEY is unset!")
                if "PORTAGE_GPG_DIR" not in repoman_settings:
-                       if os.environ.has_key("HOME"):
+                       if "HOME" in os.environ:
                                repoman_settings["PORTAGE_GPG_DIR"] = os.path.join(os.environ["HOME"], ".gnupg")
                                logging.info("Automatically setting PORTAGE_GPG_DIR to %s" % repoman_settings["PORTAGE_GPG_DIR"])
                        else:
@@ -1846,7 +1846,7 @@ else:
                                repoman_settings["PORTAGE_GPG_DIR"])
                gpgcmd = "gpg --sign --clearsign --yes "
                gpgcmd+= "--default-key "+repoman_settings["PORTAGE_GPG_KEY"]
-               if repoman_settings.has_key("PORTAGE_GPG_DIR"):
+               if "PORTAGE_GPG_DIR" in repoman_settings:
                        gpgcmd += " --homedir "+repoman_settings["PORTAGE_GPG_DIR"]
                if options.pretend:
                        print "("+gpgcmd+" "+filename+")"
index 65c01a6d80a936f42251b63dde829b030270a935..d3121aaa9116565b98b60c5ec15731e9b40d9abb 100644 (file)
@@ -7340,7 +7340,7 @@ class Scheduler(object):
                        emergelog(xterm_titles, " *** Finished. Cleaning up...")
 
                # We're out of the loop... We're done. Delete the resume data.
-               if mtimedb.has_key("resume"):
+               if "resume" in mtimedb:
                        del mtimedb["resume"]
                mtimedb.commit()
 
@@ -7578,7 +7578,7 @@ def unmerge(root_config, myopts, unmerge_action,
                                                # since we're pruning, we don't care about slots
                                                # and put all the pkgs in together
                                                myslot = 0
-                                       if not slotmap.has_key(myslot):
+                                       if myslot not in slotmap:
                                                slotmap[myslot] = {}
                                        slotmap[myslot][localtree.dbapi.cpv_counter(mypkg)] = mypkg
                                
@@ -8283,7 +8283,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
                        rsync_initial_timeout = 15
 
                try:
-                       if settings.has_key("RSYNC_RETRIES"):
+                       if "RSYNC_RETRIES" in settings:
                                print yellow("WARNING:")+" usage of RSYNC_RETRIES is deprecated, use PORTAGE_RSYNC_RETRIES instead"
                                maxretries=int(settings["RSYNC_RETRIES"])                               
                        else:
index d1c453133575c302d786bcb26ac5f708df685e4a..98342ebc1585579abc9bb60e01b28c93c1b42628 100644 (file)
@@ -30,6 +30,7 @@ try:
        import UserDict
        from itertools import chain, izip
        import platform
+       import warnings
 except ImportError, e:
        sys.stderr.write("\n\n")
        sys.stderr.write("!!! Failed to complete python imports. These are internal modules for\n")
@@ -161,7 +162,7 @@ def load_mod(name):
 
 def best_from_dict(key, top_dict, key_order, EmptyOnError=1, FullCopy=1, AllowEmpty=1):
        for x in key_order:
-               if top_dict.has_key(x) and top_dict[x].has_key(key):
+               if x in top_dict and key in top_dict[x]:
                        if FullCopy:
                                return copy.deepcopy(top_dict[x][key])
                        else:
@@ -195,7 +196,7 @@ cacheStale=0
 def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymlinks=True):
        global cacheHit,cacheMiss,cacheStale
        mypath = normalize_path(my_original_path)
-       if dircache.has_key(mypath):
+       if mypath in dircache:
                cacheHit += 1
                cached_mtime, list, ftype = dircache[mypath]
        else:
@@ -220,7 +221,7 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli
                return None, None
        # Python retuns mtime in seconds, so if it was changed in the last few seconds, it could be invalid
        if mtime != cached_mtime or time.time() - mtime < 4:
-               if dircache.has_key(mypath):
+               if mypath in dircache:
                        cacheStale += 1
                try:
                        list = os.listdir(mypath)
@@ -852,7 +853,7 @@ def ExtractKernelVersion(base_dir):
 
        # Check the .config for a CONFIG_LOCALVERSION and append that too, also stripping whitespace
        kernelconfig = getconfig(base_dir+"/.config")
-       if kernelconfig and kernelconfig.has_key("CONFIG_LOCALVERSION"):
+       if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig:
                version += "".join(kernelconfig["CONFIG_LOCALVERSION"].split())
 
        return (version,None)
@@ -1225,7 +1226,7 @@ class config(object):
                        self.prevmaskdict={}
                        for x in self.packages:
                                mycatpkg=dep_getkey(x)
-                               if not self.prevmaskdict.has_key(mycatpkg):
+                               if mycatpkg not in self.prevmaskdict:
                                        self.prevmaskdict[mycatpkg]=[x]
                                else:
                                        self.prevmaskdict[mycatpkg].append(x)
@@ -1452,7 +1453,7 @@ class config(object):
                                        os.path.join(abs_user_config, "package.use"), recursive=1)
                                for key in pusedict.keys():
                                        cp = dep_getkey(key)
-                                       if not self.pusedict.has_key(cp):
+                                       if cp not in self.pusedict:
                                                self.pusedict[cp] = {}
                                        self.pusedict[cp][key] = pusedict[key]
 
@@ -1464,7 +1465,8 @@ class config(object):
                                        # default to ~arch if no specific keyword is given
                                        if not pkgdict[key]:
                                                mykeywordlist = []
-                                               if self.configdict["defaults"] and self.configdict["defaults"].has_key("ACCEPT_KEYWORDS"):
+                                               if self.configdict["defaults"] and \
+                                                       "ACCEPT_KEYWORDS" in self.configdict["defaults"]:
                                                        groups = self.configdict["defaults"]["ACCEPT_KEYWORDS"].split()
                                                else:
                                                        groups = []
@@ -1473,7 +1475,7 @@ class config(object):
                                                                mykeywordlist.append("~"+keyword)
                                                pkgdict[key] = mykeywordlist
                                        cp = dep_getkey(key)
-                                       if not self.pkeywordsdict.has_key(cp):
+                                       if cp not in self.pkeywordsdict:
                                                self.pkeywordsdict[cp] = {}
                                        self.pkeywordsdict[cp][key] = pkgdict[key]
                                
@@ -1494,7 +1496,7 @@ class config(object):
                                        recursive=1)
                                for x in pkgunmasklines:
                                        mycatpkg=dep_getkey(x)
-                                       if self.punmaskdict.has_key(mycatpkg):
+                                       if mycatpkg in self.punmaskdict:
                                                self.punmaskdict[mycatpkg].append(x)
                                        else:
                                                self.punmaskdict[mycatpkg]=[x]
@@ -1518,7 +1520,7 @@ class config(object):
                        self.pmaskdict = {}
                        for x in pkgmasklines:
                                mycatpkg=dep_getkey(x)
-                               if self.pmaskdict.has_key(mycatpkg):
+                               if mycatpkg in self.pmaskdict:
                                        self.pmaskdict[mycatpkg].append(x)
                                else:
                                        self.pmaskdict[mycatpkg]=[x]
@@ -1556,7 +1558,7 @@ class config(object):
                                if not x:
                                        continue
                                mycatpkg=dep_getkey(x)
-                               if self.pprovideddict.has_key(mycatpkg):
+                               if mycatpkg in self.pprovideddict:
                                        self.pprovideddict[mycatpkg].append(x)
                                else:
                                        self.pprovideddict[mycatpkg]=[x]
@@ -1822,7 +1824,7 @@ class config(object):
 
        def backup_changes(self,key=None):
                self.modifying()
-               if key and self.configdict["env"].has_key(key):
+               if key and key in self.configdict["env"]:
                        self.backupenv[key] = copy.deepcopy(self.configdict["env"][key])
                else:
                        raise KeyError, "No such key defined in environment: %s" % key
@@ -2666,7 +2668,7 @@ class config(object):
                if virts:
                        for x in virts:
                                vkeysplit = x.split("/")
-                               if not self.virts_p.has_key(vkeysplit[1]):
+                               if vkeysplit[1] not in self.virts_p:
                                        self.virts_p[vkeysplit[1]] = virts[x]
                return self.virts_p
 
@@ -2778,6 +2780,9 @@ class config(object):
                return v
 
        def has_key(self,mykey):
+               warnings.warn("portage.config.has_key() is deprecated, "
+                       "use the in operator instead",
+                       DeprecationWarning)
                return mykey in self
 
        def __contains__(self, mykey):
@@ -2839,7 +2844,7 @@ class config(object):
                                # remain unset.
                                continue
                        mydict[x] = myvalue
-               if not mydict.has_key("HOME") and mydict.has_key("BUILD_PREFIX"):
+               if "HOME" not in mydict and "BUILD_PREFIX" in mydict:
                        writemsg("*** HOME not set. Setting to "+mydict["BUILD_PREFIX"]+"\n")
                        mydict["HOME"]=mydict["BUILD_PREFIX"][:]
 
@@ -3321,7 +3326,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
 #                      use_locks = 0
 
        # local mirrors are always added
-       if custommirrors.has_key("local"):
+       if "local" in custommirrors:
                mymirrors += custommirrors["local"]
 
        if "nomirror" in restrict or \
@@ -3368,7 +3373,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
        primaryuri_dict = {}
        for myuri in myuris:
                myfile=os.path.basename(myuri)
-               if not filedict.has_key(myfile):
+               if myfile not in filedict:
                        filedict[myfile]=[]
                        for y in range(0,len(locations)):
                                filedict[myfile].append(locations[y]+"/distfiles/"+myfile)
@@ -3378,14 +3383,14 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                mirrorname = myuri[9:eidx]
 
                                # Try user-defined mirrors first
-                               if custommirrors.has_key(mirrorname):
+                               if mirrorname in custommirrors:
                                        for cmirr in custommirrors[mirrorname]:
                                                filedict[myfile].append(cmirr+"/"+myuri[eidx+1:])
                                                # remove the mirrors we tried from the list of official mirrors
                                                if cmirr.strip() in thirdpartymirrors[mirrorname]:
                                                        thirdpartymirrors[mirrorname].remove(cmirr)
                                # now try the official mirrors
-                               if thirdpartymirrors.has_key(mirrorname):
+                               if mirrorname in thirdpartymirrors:
                                        shuffle(thirdpartymirrors[mirrorname])
 
                                        for locmirr in thirdpartymirrors[mirrorname]:
@@ -3402,7 +3407,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                continue
                        if "primaryuri" in restrict:
                                # Use the source site first.
-                               if primaryuri_indexes.has_key(myfile):
+                               if myfile in primaryuri_indexes:
                                        primaryuri_indexes[myfile] += 1
                                else:
                                        primaryuri_indexes[myfile] = 0
@@ -3713,11 +3718,11 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                        continue
                                # allow different fetchcommands per protocol
                                protocol = loc[0:loc.find("://")]
-                               if mysettings.has_key("FETCHCOMMAND_"+protocol.upper()):
+                               if "FETCHCOMMAND_" + protocol.upper() in mysettings:
                                        fetchcommand=mysettings["FETCHCOMMAND_"+protocol.upper()]
                                else:
                                        fetchcommand=mysettings["FETCHCOMMAND"]
-                               if mysettings.has_key("RESUMECOMMAND_"+protocol.upper()):
+                               if "RESUMECOMMAND_" + protocol.upper() in mysettings:
                                        resumecommand=mysettings["RESUMECOMMAND_"+protocol.upper()]
                                else:
                                        resumecommand=mysettings["RESUMECOMMAND"]
@@ -3834,7 +3839,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                        except EnvironmentError:
                                                pass
 
-                                       if mydigests!=None and mydigests.has_key(myfile):
+                                       if mydigests is not None and myfile in mydigests:
                                                try:
                                                        mystat = os.stat(myfile_path)
                                                except OSError, e:
@@ -4428,7 +4433,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m
        ebuild_path = os.path.abspath(myebuild)
        pkg_dir     = os.path.dirname(ebuild_path)
 
-       if mysettings.configdict["pkg"].has_key("CATEGORY"):
+       if "CATEGORY" in mysettings.configdict["pkg"]:
                cat = mysettings.configdict["pkg"]["CATEGORY"]
        else:
                cat = os.path.basename(normalize_path(os.path.join(pkg_dir, "..")))
@@ -4531,7 +4536,7 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m
        else:
                mysettings["PVR"]=mysplit[1]+"-"+mysplit[2]
 
-       if mysettings.has_key("PATH"):
+       if "PATH" in mysettings:
                mysplit=mysettings["PATH"].split(":")
        else:
                mysplit=[]
@@ -6240,7 +6245,7 @@ def dep_wordreduce(mydeplist,mysettings,mydbapi,mode,use_cache=1):
                        pass
                else:
                        mykey = dep_getkey(deplist[mypos])
-                       if mysettings and mysettings.pprovideddict.has_key(mykey) and \
+                       if mysettings and mykey in mysettings.pprovideddict and \
                                match_from_list(deplist[mypos], mysettings.pprovideddict[mykey]):
                                deplist[mypos]=True
                        elif mydbapi is None:
@@ -6291,12 +6296,13 @@ def key_expand(mykey, mydb=None, use_cache=1, settings=None):
                        for x in mydb.categories:
                                if mydb.cp_list(x+"/"+mykey,use_cache=use_cache):
                                        return x+"/"+mykey
-                       if virts_p.has_key(mykey):
+                       if mykey in virts_p:
                                return(virts_p[mykey][0])
                return "null/"+mykey
        elif mydb:
                if hasattr(mydb, "cp_list"):
-                       if (not mydb.cp_list(mykey,use_cache=use_cache)) and virts and virts.has_key(mykey):
+                       if not mydb.cp_list(mykey, use_cache=use_cache) and \
+                               virts and mykey in virts:
                                return virts[mykey][0]
                return mykey
 
@@ -6370,7 +6376,7 @@ def cpv_expand(mycpv, mydb=None, use_cache=1, settings=None):
                        mykey=matches[0]
 
                if not mykey and not isinstance(mydb, list):
-                       if virts_p.has_key(myp):
+                       if myp in virts_p:
                                mykey=virts_p[myp][0]
                        #again, we only perform virtual expansion if we have a dbapi (not a list)
                if not mykey:
@@ -6418,7 +6424,7 @@ def getmaskingreason(mycpv, metadata=None, settings=None, portdb=None, return_lo
        locations.reverse()
        pmasklists = [(x, grablines(os.path.join(x, "package.mask"), recursive=1)) for x in locations]
 
-       if settings.pmaskdict.has_key(mycp):
+       if mycp in settings.pmaskdict:
                for x in settings.pmaskdict[mycp]:
                        if match_from_list(x, cpv_slot_list):
                                comment = ""
@@ -6836,7 +6842,7 @@ def commit_mtimedb(mydict=None, filename=None):
 
 def portageexit():
        global uid,portage_gid,portdb,db
-       if secpass and not os.environ.has_key("SANDBOX_ACTIVE"):
+       if secpass and os.environ.get("SANDBOX_ON") != "1":
                close_portdbapi_caches()
                commit_mtimedb()
 
index 2ccc96b05c87844bc4ea69bf4c1856f84e20ccc8..d0ca487f07dca8376512b8178c984bd6bff728c4 100644 (file)
@@ -4,6 +4,7 @@
 # $Id$
 
 import UserDict
+import warnings
 import weakref
 
 class ProtectedDict(UserDict.DictMixin):
@@ -55,9 +56,14 @@ class ProtectedDict(UserDict.DictMixin):
                return list(self.__iter__())
 
 
-       def has_key(self, key):
+       def __contains__(self, key):
                return key in self.new or (key not in self.blacklist and key in self.orig)
 
+       def has_key(self, key):
+               warnings.warn("portage.cache.mapping.ProtectedDict.has_key() is"
+                       " deprecated, use the in operator instead",
+                       DeprecationWarning)
+               return key in self
 
 class LazyLoad(UserDict.DictMixin):
        """
@@ -91,6 +97,9 @@ class LazyLoad(UserDict.DictMixin):
 
 
        def has_key(self, key):
+               warnings.warn("portage.cache.mappings.LazyLoad.has_key() is "
+                       "deprecated, use the in operator instead",
+                       DeprecationWarning)
                return key in self
 
 
index 13d12787e17e27d2733ae3a0457a050fe81d5b28..e25759c4a33a4ffc224400681ef65908d239162c 100644 (file)
@@ -61,7 +61,7 @@ class database(template.database):
 
        def _delitem(self, cpv):
                value = self[cpv] # validates whiteout and/or raises a KeyError when necessary
-               if self.db_ro.has_key(cpv):
+               if cpv in self.db_ro:
                        self.db_rw[cpv] = self._create_whiteout(value)
                else:
                        del self.db_rw[cpv]
index f32a7284447bb6855f14f02d146b207db5f42d28..196039c74950cd24ca7675bff20b05aa6f7da8c6 100644 (file)
@@ -150,7 +150,7 @@ class SQLDatabase(template.database):
                        # so we store only what's handed to us and is a known key
                        db_values = []
                        for key in self._known_keys:
-                               if values.has_key(key) and values[key] != '':
+                               if key in values and values[key]:
                                        db_values.append({"key":key, "value":values[key]})
 
                        if len(db_values) > 0:
index d5a07528c6766ce05d03c685951687e5ad81d43e..891a5821f715df8e7906b2a746d628982f876c1e 100644 (file)
@@ -6,6 +6,7 @@
 from portage.cache import cache_errors
 from portage.cache.cache_errors import InvalidRestriction
 from portage.cache.mappings import ProtectedDict
+import warnings
 
 class database(object):
        # this is for metadata/cache transfer.
@@ -121,6 +122,9 @@ class database(object):
                if self.has_key is database.has_key:
                        # prevent a possible recursive loop
                        raise NotImplementedError
+               warnings.warn("portage.cache.template.database.has_key() is "
+                       "deprecated, override __contains__ instead",
+                       DeprecationWarning)
                return self.has_key(cpv)
 
        def __iter__(self):
index f74ecd4acdca2f16ff651220923be8f7a8628fb1..d283fb47f46cafa25467187326aad2e170eff629 100644 (file)
@@ -17,13 +17,13 @@ def pathdata(entries, path):
        mytarget=mysplit[-1]
        mysplit=mysplit[:-1]
        for mys in mysplit:
-               if myentries["dirs"].has_key(mys):
+               if mys in myentries["dirs"]:
                        myentries=myentries["dirs"][mys]
                else:
                        return None
-       if myentries["dirs"].has_key(mytarget):
+       if mytarget in myentries["dirs"]:
                return myentries["dirs"][mytarget]
-       elif myentries["files"].has_key(mytarget):
+       elif mytarget in myentries["files"]:
                return myentries["files"][mytarget]
        else:
                return None
@@ -242,9 +242,9 @@ def getentries(mydir,recursive=0):
                if file=="digest-framerd-2.4.3":
                        print mydir,file
                if os.path.isdir(mydir+"/"+file):
-                       if not entries["dirs"].has_key(file):
+                       if file not in entries["dirs"]:
                                entries["dirs"][file]={"dirs":{},"files":{}}
-                       if entries["dirs"][file].has_key("status"):
+                       if "status" in entries["dirs"][file]:
                                if "exists" not in entries["dirs"][file]["status"]:
                                        entries["dirs"][file]["status"]+=["exists"]
                        else:
@@ -252,9 +252,9 @@ def getentries(mydir,recursive=0):
                elif os.path.isfile(mydir+"/"+file):
                        if file=="digest-framerd-2.4.3":
                                print "isfile"
-                       if not entries["files"].has_key(file):
+                       if file not in entries["files"]:
                                entries["files"][file]={"revision":"","date":"","flags":"","tags":""}
-                       if entries["files"][file].has_key("status"):
+                       if "status" in entries["files"][file]:
                                if file=="digest-framerd-2.4.3":
                                        print "has status"
                                if "exists" not in entries["files"][file]["status"]:
@@ -270,7 +270,7 @@ def getentries(mydir,recursive=0):
                                        print "stat'ing"
                                mystat=os.stat(mydir+"/"+file)
                                mytime=time.asctime(time.gmtime(mystat[ST_MTIME]))
-                               if not entries["files"][file].has_key("status"):
+                               if "status" not in entries["files"][file]:
                                        if file=="digest-framerd-2.4.3":
                                                print "status not set"
                                        entries["files"][file]["status"]=[]
index 54ce7afc328955dfb147652d66f288b37d065042..0900fcfa8013a430d3567e6afb3764ea8c54f2fe 100644 (file)
@@ -173,7 +173,7 @@ class dbapi(object):
 
        def invalidentry(self, mypath):
                if mypath.endswith('portage_lockfile'):
-                       if not os.environ.has_key("PORTAGE_MASTER_PID"):
+                       if "PORTAGE_MASTER_PID" not in os.environ:
                                writemsg("Lockfile removed: %s\n" % mypath, 1)
                                unlockfile((mypath, None, None))
                        else:
index 05ff9cd9746fbe1af3f18df725fcc77143ed0c5e..dd6ab5aadf42e541c086ce48c97e7dcd1d72bf70 100644 (file)
@@ -706,7 +706,7 @@ class binarytree(object):
                        #writemsg(green("  -- DONE!\n\n"))
 
                        for mypkg in self.remotepkgs.keys():
-                               if not self.remotepkgs[mypkg].has_key("CATEGORY"):
+                               if "CATEGORY" not in self.remotepkgs[mypkg]:
                                        #old-style or corrupt package
                                        writemsg("!!! Invalid remote binary package: "+mypkg+"\n",
                                                noiselevel=-1)
index 760eeb98697af0e8b0791c81fcaca764dae2f3cd..bd016cedff1f625f3f431ba1a214b254b51fee32 100644 (file)
@@ -89,7 +89,7 @@ class PreservedLibsRegistry(object):
                """
                cp = "/".join(catpkgsplit(cpv)[:2])
                cps = cp+":"+slot
-               if len(paths) == 0 and self._data.has_key(cps) \
+               if len(paths) == 0 and cps in self._data \
                                and self._data[cps][0] == cpv and int(self._data[cps][1]) == int(counter):
                        del self._data[cps]
                elif len(paths) > 0:
@@ -603,7 +603,7 @@ class vardbapi(dbapi):
                        mystat = os.stat(self.getpath(mysplit[0]))[stat.ST_MTIME]
                except OSError:
                        mystat = 0
-               if use_cache and self.cpcache.has_key(mycp):
+               if use_cache and mycp in self.cpcache:
                        cpc = self.cpcache[mycp]
                        if cpc[0] == mystat:
                                return cpc[1][:]
@@ -631,7 +631,7 @@ class vardbapi(dbapi):
                self._cpv_sort_ascending(returnme)
                if use_cache:
                        self.cpcache[mycp] = [mystat, returnme[:]]
-               elif self.cpcache.has_key(mycp):
+               elif mycp in self.cpcache:
                        del self.cpcache[mycp]
                return returnme
 
@@ -727,7 +727,7 @@ class vardbapi(dbapi):
                mykey = dep_getkey(mydep)
                mycat = catsplit(mykey)[0]
                if not use_cache:
-                       if self.matchcache.has_key(mycat):
+                       if mycat in self.matchcache:
                                del self.mtdircache[mycat]
                                del self.matchcache[mycat]
                        return list(self._iter_match(mydep,
@@ -737,11 +737,12 @@ class vardbapi(dbapi):
                except (IOError, OSError):
                        curmtime=0
 
-               if not self.matchcache.has_key(mycat) or not self.mtdircache[mycat]==curmtime:
+               if mycat not in self.matchcache or \
+                       self.mtdircache[mycat] != curmtime:
                        # clear cache entry
                        self.mtdircache[mycat] = curmtime
                        self.matchcache[mycat] = {}
-               if not self.matchcache[mycat].has_key(mydep):
+               if mydep not in self.matchcache[mycat]:
                        mymatch = list(self._iter_match(mydep,
                                self.cp_list(mydep.cp, use_cache=use_cache)))
                        self.matchcache[mycat][mydep] = mymatch
@@ -1302,7 +1303,7 @@ class vartree(object):
                myprovides = {}
                for node in self.getallcpv():
                        for mykey in self.get_provide(node):
-                               if myprovides.has_key(mykey):
+                               if mykey in myprovides:
                                        myprovides[mykey] += [node]
                                else:
                                        myprovides[mykey] = [node]
@@ -2736,7 +2737,7 @@ class dblink(object):
                #if we have a file containing previously-merged config file md5sums, grab it.
                conf_mem_file = os.path.join(destroot, CONFIG_MEMORY_FILE)
                cfgfiledict = grabdict(conf_mem_file)
-               if self.settings.has_key("NOCONFMEM"):
+               if "NOCONFMEM" in self.settings:
                        cfgfiledict["IGNORE"]=1
                else:
                        cfgfiledict["IGNORE"]=0
index 444b5363a0e0c3ef91d707b12c11166a2ce5d4a8..bf90f305bfcd3c144693a741e12a4c3e901159df 100644 (file)
@@ -40,7 +40,7 @@ class fakedbapi(dbapi):
                return result[:]
 
        def cpv_exists(self, mycpv):
-               return self.cpvdict.has_key(mycpv)
+               return mycpv in self.cpvdict
 
        def cp_list(self, mycp, use_cache=1):
                cachelist = self._match_cache.get(mycp)
@@ -94,9 +94,9 @@ class fakedbapi(dbapi):
                """Removes a cpv from the list of available packages."""
                self._clear_cache()
                mycp = cpv_getkey(mycpv)
-               if self.cpvdict.has_key(mycpv):
+               if mycpv in self.cpvdict:
                        del     self.cpvdict[mycpv]
-               if not self.cpdict.has_key(mycp):
+               if mycp not in self.cpdict:
                        return
                while mycpv in self.cpdict[mycp]:
                        del self.cpdict[mycp][self.cpdict[mycp].index(mycpv)]
@@ -129,4 +129,4 @@ class testdbapi(object):
                fake_api = dir(dbapi)
                for call in fake_api:
                        if not hasattr(self, call):
-                               setattr(self, call, f)
\ No newline at end of file
+                               setattr(self, call, f)
index df256dc7776bcbf5dc5ffc5e2b4bf95c1ffbeb77..541bced02412ceda8c50c659a24b523f4821fe9a 100644 (file)
@@ -31,7 +31,7 @@ def read_config(mandatory_opts):
         sys.exit(1)
 
     for key in mandatory_opts:
-        if not opts.has_key(key):
+        if key not in opts:
             if key == "merge":
                 opts["merge"] = "sdiff --suppress-common-lines --output='%s' '%s' '%s'"
             else:
index 3039370a3c0a41c214712b465752c1eb9a9e2fbe..ea81e841188b8f5a16908d57c21aaf0e7ac3abaa 100644 (file)
@@ -73,13 +73,13 @@ def elog_process(cpv, mysettings, phasefilter=None):
 
        ebuild_logentries = collect_ebuild_messages(os.path.join(mysettings["T"], "logging"))
        all_logentries = collect_messages()
-       if all_logentries.has_key(cpv):
+       if cpv in all_logentries:
                all_logentries[cpv] = _merge_logentries(ebuild_logentries, all_logentries[cpv])
        else:
                all_logentries[cpv] = ebuild_logentries
 
        for key in _preserve_logentries.keys():
-               if all_logentries.has_key(key):
+               if key in all_logentries:
                        all_logentries[key] = _merge_logentries(_preserve_logentries[key], all_logentries[key])
                else:
                        all_logentries[key] = _preserve_logentries[key]
index c93085c611f44d0409dd48e3028647e00d28e7ff..d33d312374d53a4eb4cc8426a36cc397374d0621 100644 (file)
@@ -12,7 +12,7 @@ def filter_loglevels(logentries, loglevels):
        for phase in logentries:
                for msgtype, msgcontent in logentries[phase]:
                        if msgtype.upper() in loglevels or "*" in loglevels:
-                               if not rValue.has_key(phase):
+                               if phase not in rValue:
                                        rValue[phase] = []
                                rValue[phase].append((msgtype, msgcontent))
        return rValue
index 2daacd1031bc52adfe2ea0286c0798f476fbee48..ac8d701601a9246fe2142ec575f8697cf8de316e 100644 (file)
@@ -76,9 +76,9 @@ def _elog_base(level, msg, phase="other", key=None, color=None):
        if color == None:
                color = "GOOD"
        print colorize(color, " * ")+msg
-       if not _msgbuffer.has_key(key):
+       if key not in _msgbuffer:
                _msgbuffer[key] = {}
-       if not _msgbuffer[key].has_key(phase):
+       if phase not in _msgbuffer[key]:
                _msgbuffer[key][phase] = []
        _msgbuffer[key][phase].append((level, msg))
 
index 09e3db22dcd7d321c23de5fe1db152ce23ac7757..d6383a4eb06b7bf2457cef5c7923a58c0d13eb16 100644 (file)
@@ -8,7 +8,7 @@ from portage.exception import PortageException
 from portage.util import writemsg
 
 def process(mysettings, key, logentries, fulltext):
-       if mysettings.has_key("PORTAGE_ELOG_MAILURI"):
+       if "PORTAGE_ELOG_MAILURI" in mysettings:
                myrecipient = mysettings["PORTAGE_ELOG_MAILURI"].split()[0]
        else:
                myrecipient = "root@localhost"
index 8f7f8621795d1698cb7e11e28016b3b756a41492..ed5147313ffbe567994731e873152dd1809eb358 100644 (file)
@@ -33,7 +33,7 @@ def _finalize(mysettings, items):
                count = "one package"
        else:
                count = "multiple packages"
-       if mysettings.has_key("PORTAGE_ELOG_MAILURI"):
+       if "PORTAGE_ELOG_MAILURI" in mysettings:
                myrecipient = mysettings["PORTAGE_ELOG_MAILURI"].split()[0]
        else:
                myrecipient = "root@localhost"
index 34ad243be2b1e04149525ea0d32cffa3abc5dff6..b8e44fdaef6d4735b827a4c758f6506def941589 100644 (file)
@@ -479,15 +479,15 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                metadatafile.close()
        except (cPickle.UnpicklingError, OSError, IOError, EOFError):
                metadata = {}
-       if not metadata.has_key(baseurl):
+       if baseurl not in metadata:
                metadata[baseurl]={}
-       if not metadata[baseurl].has_key("indexname"):
+       if "indexname" not in metadata[baseurl]:
                metadata[baseurl]["indexname"]=""
-       if not metadata[baseurl].has_key("timestamp"):
+       if "timestamp" not in metadata[baseurl]:
                metadata[baseurl]["timestamp"]=0
-       if not metadata[baseurl].has_key("unmodified"):
+       if "unmodified" not in metadata[baseurl]:
                metadata[baseurl]["unmodified"]=0
-       if not metadata[baseurl].has_key("data"):
+       if "data" not in metadata[baseurl]:
                metadata[baseurl]["data"]={}
 
        if not os.access(cache_path, os.W_OK):
@@ -649,7 +649,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
        out.flush()
 
        try:
-               if metadata[baseurl].has_key("modified") and metadata[baseurl]["modified"]:
+               if "modified" in metadata[baseurl] and metadata[baseurl]["modified"]:
                        metadata[baseurl]["timestamp"] = int(time.time())
                        metadatafile = open(CACHE_PATH+"/remote_metadata.pickle", "w+")
                        cPickle.dump(metadata,metadatafile)
index 2d2f27b3039ac405e560ea7d640e35dc700553e7..4dc05f7e120cdbff85ae1ebbcd87f30557644631 100644 (file)
@@ -92,7 +92,7 @@ def get_glsa_list(myconfig):
        """
        rValue = []
 
-       if myconfig.has_key("GLSA_DIR"):
+       if "GLSA_DIR" in myconfig:
                repository = myconfig["GLSA_DIR"]
        else:
                repository = os.path.join(myconfig["PORTDIR"], "metadata", "glsa")
@@ -407,7 +407,7 @@ class Glsa:
                @rtype:         None
                @return:        None
                """
-               if self.config.has_key("GLSA_DIR"):
+               if "GLSA_DIR" in self.config:
                        repository = "file://" + self.config["GLSA_DIR"]+"/"
                else:
                        repository = "file://" + self.config["PORTDIR"] + "/metadata/glsa/"
@@ -470,7 +470,7 @@ class Glsa:
                self.packages = {}
                for p in self.affected.getElementsByTagName("package"):
                        name = p.getAttribute("name")
-                       if not self.packages.has_key(name):
+                       if name not in self.packages:
                                self.packages[name] = []
                        tmp = {}
                        tmp["arch"] = p.getAttribute("arch")
index f3e090f6bcab71ee45fc043f79b5718a6fed4244..dd3df102586594496397d5fd3f5de9b8e6e01422 100644 (file)
@@ -290,9 +290,9 @@ def hardlock_cleanup(path, remove_all_locks=False):
                                host  = "-".join(hostpid[:-1])
                                pid   = hostpid[-1]
                                
-                               if not mylist.has_key(filename):
+                               if filename not in mylist:
                                        mylist[filename] = {}
-                               if not mylist[filename].has_key(host):
+                               if host not in mylist[filename]:
                                        mylist[filename][host] = []
                                mylist[filename][host].append(pid)
 
@@ -302,7 +302,7 @@ def hardlock_cleanup(path, remove_all_locks=False):
        results.append("Found %(count)s locks" % {"count":mycount})
        
        for x in mylist:
-               if mylist[x].has_key(myhost) or remove_all_locks:
+               if myhost in mylist[x] or remove_all_locks:
                        mylockname = hardlock_name(path+"/"+x)
                        if hardlink_is_mine(mylockname, path+"/"+x) or \
                           not os.path.exists(path+"/"+x) or \
index 9c8ab371a224984fff6c35adcd820fc7c2cbf499..50ed2f52fd07f1d30aa7bf0cf24e61f2b9e895b4 100644 (file)
@@ -419,9 +419,9 @@ class Manifest(object):
                """ Regenerate hashes for the given file """
                if checkExisting:
                        self.checkFileHashes(ftype, fname, ignoreMissing=ignoreMissing)
-               if not ignoreMissing and not self.fhashdict[ftype].has_key(fname):
+               if not ignoreMissing and fname not in self.fhashdict[ftype]:
                        raise FileNotInManifestException(fname)
-               if not self.fhashdict[ftype].has_key(fname):
+               if fname not in self.fhashdict[ftype]:
                        self.fhashdict[ftype][fname] = {}
                myhashkeys = list(self.hashes)
                if reuseExisting:
index bb3b42e0dbdb717c251c020499908d35d95772de..7b2f262cf0048910867cf4fa3e8adfaee1482ff5 100644 (file)
@@ -175,7 +175,7 @@ def stack_dicts(dicts, incremental=0, incrementals=[], ignore_none=0):
                        final_dict = {}
                for y in mydict.keys():
                        if True:
-                               if final_dict.has_key(y) and (incremental or (y in incrementals)):
+                               if y in final_dict and (incremental or (y in incrementals)):
                                        final_dict[y] += " "+mydict[y][:]
                                else:
                                        final_dict[y]  = mydict[y][:]
@@ -494,7 +494,7 @@ def varexpand(mystring, mydict={}):
                                        cexpand[mystring]=""
                                        return ""
                                numvars=numvars+1
-                               if mydict.has_key(myvarname):
+                               if myvarname in mydict:
                                        newstring=newstring+mydict[myvarname] 
                        else:
                                newstring=newstring+mystring[pos]