From d2eb7ae20c1bbadc5ca8a896f8c3e2de9aff099f Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 7 Dec 2012 22:14:02 -0800 Subject: [PATCH] Use 'in' instead of deprecated has_key() Since Python 2.2 'in' has been preferred to has_key() since it is shorter, more readable, and faster. has_key() has been deprecated since 2.6 and was removed in 3.0. See: http://www.python.org/dev/peps/pep-0290/#testing-dictionary-membership Mostly scripted with sed -i -e 's/if \(not \)\?\(.*\)\.has_key(\(.*\))/if \3 \1in \2/' --- catalyst | 24 +-- modules/catalyst/config.py | 2 +- modules/catalyst_lock.py | 20 +-- modules/catalyst_support.py | 6 +- modules/embedded_target.py | 2 +- modules/generic_stage_target.py | 254 ++++++++++++++++---------------- modules/grp_target.py | 8 +- modules/livecd_stage1_target.py | 8 +- modules/livecd_stage2_target.py | 16 +- modules/netboot2_target.py | 24 +-- modules/netboot_target.py | 16 +- modules/snapshot_target.py | 4 +- modules/stage1_target.py | 10 +- modules/stage2_target.py | 12 +- modules/stage3_target.py | 2 +- modules/stage4_target.py | 6 +- 16 files changed, 205 insertions(+), 209 deletions(-) diff --git a/catalyst b/catalyst index 3d315998..93114e94 100755 --- a/catalyst +++ b/catalyst @@ -100,7 +100,7 @@ def parse_config(myconfig): # now, load up the values into conf_values so that we can use them for x in confdefaults.keys(): - if myconf.has_key(x): + if x in myconf: print "Setting",x,"to config file value \""+myconf[x]+"\"" conf_values[x]=myconf[x] else: @@ -156,19 +156,19 @@ def parse_config(myconfig): # print "Tarball creation enabled." # conf_values["TARBALL"]="1" - if myconf.has_key("digests"): + if "digests" in myconf: conf_values["digests"]=myconf["digests"] - if myconf.has_key("contents"): + if "contents" in myconf: conf_values["contents"]=myconf["contents"] - if myconf.has_key("envscript"): + if "envscript" in myconf: print "Envscript support enabled." conf_values["ENVSCRIPT"]=myconf["envscript"] - if myconf.has_key("var_tmpfs_portage"): + if "var_tmpfs_portage" in myconf: conf_values["var_tmpfs_portage"]=myconf["var_tmpfs_portage"]; - if myconf.has_key("port_logdir"): + if "port_logdir" in myconf: conf_values["port_logdir"]=myconf["port_logdir"]; def import_modules(): @@ -206,7 +206,7 @@ def import_modules(): def build_target(addlargs, targetmap): try: - if not targetmap.has_key(addlargs["target"]): + if addlargs["target"] not in targetmap: raise CatalystError,"Target \""+addlargs["target"]+"\" not available." mytarget=targetmap[addlargs["target"]](conf_values, addlargs) @@ -324,9 +324,9 @@ if __name__ == "__main__": # Start checking that digests are valid now that the hash_map was imported # from catalyst_support - if conf_values.has_key("digests"): + if "digests" in conf_values: for i in conf_values["digests"].split(): - if not hash_map.has_key(i): + if i not in hash_map: print print i+" is not a valid digest entry" print "Valid digest entries:" @@ -342,8 +342,8 @@ if __name__ == "__main__": print print "Catalyst aborting...." sys.exit(2) - if conf_values.has_key("hash_function"): - if not hash_map.has_key(conf_values["hash_function"]): + if "hash_function" in conf_values: + if conf_values["hash_function"] not in hash_map: print print conf_values["hash_function"]+\ " is not a valid hash_function entry" @@ -379,7 +379,7 @@ if __name__ == "__main__": print "!!! catalyst: Could not parse commandline, exiting." sys.exit(1) - if not addlargs.has_key("target"): + if "target" not in addlargs: raise CatalystError, "Required value \"target\" not specified." # everything is setup, so the build is a go diff --git a/modules/catalyst/config.py b/modules/catalyst/config.py index 4e9d69c1..00da3439 100644 --- a/modules/catalyst/config.py +++ b/modules/catalyst/config.py @@ -63,7 +63,7 @@ class ParserBase: mobjs[1] = mobjs[1].strip().strip('"') # # Check that this key doesn't exist already in the spec -# if values.has_key(mobjs[0]): +# if mobjs[0] in values: # raise Exception("You have a duplicate key (" + mobjs[0] + ") in your spec. Please fix it") # Start a new array using the first element of mobjs diff --git a/modules/catalyst_lock.py b/modules/catalyst_lock.py index 960b10ca..5311cf84 100644 --- a/modules/catalyst_lock.py +++ b/modules/catalyst_lock.py @@ -57,7 +57,7 @@ class LockDir: def set_gid(self,gid): if not self.islocked(): -# if self.settings.has_key("DEBUG"): +# if "DEBUG" in self.settings: # print "setting gid to", gid self.gid=gid @@ -69,7 +69,7 @@ class LockDir: if lockdir[-1] == "/": lockdir=lockdir[:-1] self.lockdir=normpath(lockdir) -# if self.settings.has_key("DEBUG"): +# if "DEBUG" in self.settings: # print "setting lockdir to", self.lockdir else: raise "the lock object needs a path to a dir" @@ -77,13 +77,13 @@ class LockDir: def set_lockfilename(self,lockfilename): if not self.islocked(): self.lockfilename=lockfilename -# if self.settings.has_key("DEBUG"): +# if "DEBUG" in self.settings: # print "setting lockfilename to", self.lockfilename def set_lockfile(self): if not self.islocked(): self.lockfile=normpath(self.lockdir+'/'+self.lockfilename) -# if self.settings.has_key("DEBUG"): +# if "DEBUG" in self.settings: # print "setting lockfile to", self.lockfile def read_lock(self): @@ -208,7 +208,7 @@ class LockDir: os.unlink(self.lockfile) os.close(self.myfd) self.myfd=None -# if self.settings.has_key("DEBUG"): +# if "DEBUG" in self.settings: # print "Unlinked lockfile..." except SystemExit, e: raise @@ -257,7 +257,7 @@ class LockDir: except SystemExit, e: raise except Exception, e: -# if self.settings.has_key("DEBUG"): +# if "DEBUG" in self.settings: # print "lockfile(): Hardlink: Link failed." # print "Exception: ",e pass @@ -297,7 +297,7 @@ class LockDir: self.hardlock_paths[self.lockdir]=self.myhardlock def remove_hardlock_file_from_cleanup(self): - if self.hardlock_paths.has_key(self.lockdir): + if self.lockdir in self.hardlock_paths: del self.hardlock_paths[self.lockdir] print self.hardlock_paths @@ -356,10 +356,10 @@ class LockDir: hostpid = parts[1].split("-") 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) mycount += 1 @@ -370,7 +370,7 @@ class LockDir: results.append("Found %(count)s locks" % {"count":mycount}) for x in mylist.keys(): - if mylist[x].has_key(myhost): + if myhost in mylist[x]: mylockname = self.hardlock_name(x) if self.hardlink_is_mine(mylockname, self.lockfile) or \ not os.path.exists(self.lockfile): diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py index 6dbcfb78..316dfa3d 100644 --- a/modules/catalyst_support.py +++ b/modules/catalyst_support.py @@ -295,7 +295,7 @@ def spawn_bash(mycommand,env={},debug=False,opt_name=None,**keywords): args=[BASH_BINARY] if not opt_name: opt_name=mycommand.split()[0] - if not env.has_key("BASH_ENV"): + if "BASH_ENV" not in env: env["BASH_ENV"] = "/etc/spork/is/not/valid/profile.env" if debug: args.append("-x") @@ -558,7 +558,7 @@ def file_locate(settings,filelist,expand=1): #if expand=1, non-absolute paths will be accepted and # expanded to os.getcwd()+"/"+localpath if file exists for myfile in filelist: - if not settings.has_key(myfile): + if myfile not in settings: #filenames such as cdtar are optional, so we don't assume the variable is defined. pass else: @@ -680,7 +680,7 @@ def addl_arg_parse(myspec,addlargs,requiredspec,validspec): myspec[x]=addlargs[x] for x in requiredspec: - if not myspec.has_key(x): + if x not in myspec: messages.append("Required argument \""+x+"\" not specified.") if messages: diff --git a/modules/embedded_target.py b/modules/embedded_target.py index 6d34a576..f38ea00d 100644 --- a/modules/embedded_target.py +++ b/modules/embedded_target.py @@ -24,7 +24,7 @@ class embedded_target(generic_stage_target): self.valid_values=[] self.valid_values.extend(["embedded/empty","embedded/rm","embedded/unmerge","embedded/fs-prepare","embedded/fs-finish","embedded/mergeroot","embedded/packages","embedded/fs-type","embedded/runscript","boot/kernel","embedded/linuxrc"]) self.valid_values.extend(["embedded/use"]) - if addlargs.has_key("embedded/fs-type"): + if "embedded/fs-type" in addlargs: self.valid_values.append("embedded/fs-ops") generic_stage_target.__init__(self,spec,addlargs) diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py index 35976809..0a473ef6 100644 --- a/modules/generic_stage_target.py +++ b/modules/generic_stage_target.py @@ -78,21 +78,21 @@ class generic_stage_target(generic_target): msg("Can't find/load "+x+".py plugin in "+\ self.settings["sharedir"]+"/arch/") - if self.settings.has_key("chost"): + if "chost" in self.settings: hostmachine = self.settings["chost"].split("-")[0] - if not machinemap.has_key(hostmachine): + if hostmachine not in machinemap: raise CatalystError, "Unknown host machine type "+hostmachine self.settings["hostarch"]=machinemap[hostmachine] else: hostmachine = self.settings["subarch"] - if machinemap.has_key(hostmachine): + if hostmachine in machinemap: hostmachine = machinemap[hostmachine] self.settings["hostarch"]=hostmachine - if self.settings.has_key("cbuild"): + if "cbuild" in self.settings: buildmachine = self.settings["cbuild"].split("-")[0] else: buildmachine = os.uname()[4] - if not machinemap.has_key(buildmachine): + if buildmachine not in machinemap: raise CatalystError, "Unknown build machine type "+buildmachine self.settings["buildarch"]=machinemap[buildmachine] self.settings["crosscompile"]=(self.settings["hostarch"]!=\ @@ -169,11 +169,11 @@ class generic_stage_target(generic_target): file_locate(self.settings,["source_path","snapshot_path","distdir"],\ expand=0) """ If we are using portage_confdir, check that as well. """ - if self.settings.has_key("portage_confdir"): + if "portage_confdir" in self.settings: file_locate(self.settings,["portage_confdir"],expand=0) """ Setup our mount points """ - if self.settings.has_key("SNAPCACHE"): + if "SNAPCACHE" in self.settings: self.mounts=["/proc","/dev","/usr/portage","/usr/portage/distfiles","/var/tmp/portage"] self.mountmap={"/proc":"/proc","/dev":"/dev","/dev/pts":"/dev/pts",\ "/usr/portage":self.settings["snapshot_cache_path"]+"/portage",\ @@ -191,7 +191,7 @@ class generic_stage_target(generic_target): Configure any user specified options (either in catalyst.conf or on the command line). """ - if self.settings.has_key("PKGCACHE"): + if "PKGCACHE" in self.settings: self.set_pkgcache_path() print "Location of the package cache is "+\ self.settings["pkgcache_path"] @@ -199,15 +199,15 @@ class generic_stage_target(generic_target): self.mountmap["/usr/portage/packages"]=\ self.settings["pkgcache_path"] - if self.settings.has_key("KERNCACHE"): + if "KERNCACHE" in self.settings: self.set_kerncache_path() print "Location of the kerncache is "+\ self.settings["kerncache_path"] self.mounts.append("/tmp/kerncache") self.mountmap["/tmp/kerncache"]=self.settings["kerncache_path"] - if self.settings.has_key("CCACHE"): - if os.environ.has_key("CCACHE_DIR"): + if "CCACHE" in self.settings: + if "CCACHE_DIR" in os.environ: ccdir=os.environ["CCACHE_DIR"] del os.environ["CCACHE_DIR"] else: @@ -221,39 +221,39 @@ class generic_stage_target(generic_target): """ for the chroot: """ self.env["CCACHE_DIR"]="/var/tmp/ccache" - if self.settings.has_key("ICECREAM"): + if "ICECREAM" in self.settings: self.mounts.append("/var/cache/icecream") self.mountmap["/var/cache/icecream"]="/var/cache/icecream" self.env["PATH"]="/usr/lib/icecc/bin:"+self.env["PATH"] - if self.settings.has_key("port_logdir"): + if "port_logdir" in self.settings: self.mounts.append("/var/log/portage") self.mountmap["/var/log/portage"]=self.settings["port_logdir"] self.env["PORT_LOGDIR"]="/var/log/portage" self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete' def override_cbuild(self): - if self.makeconf.has_key("CBUILD"): + if "CBUILD" in self.makeconf: self.settings["CBUILD"]=self.makeconf["CBUILD"] def override_chost(self): - if self.makeconf.has_key("CHOST"): + if "CHOST" in self.makeconf: self.settings["CHOST"]=self.makeconf["CHOST"] def override_cflags(self): - if self.makeconf.has_key("CFLAGS"): + if "CFLAGS" in self.makeconf: self.settings["CFLAGS"]=self.makeconf["CFLAGS"] def override_cxxflags(self): - if self.makeconf.has_key("CXXFLAGS"): + if "CXXFLAGS" in self.makeconf: self.settings["CXXFLAGS"]=self.makeconf["CXXFLAGS"] def override_ldflags(self): - if self.makeconf.has_key("LDFLAGS"): + if "LDFLAGS" in self.makeconf: self.settings["LDFLAGS"]=self.makeconf["LDFLAGS"] def set_install_mask(self): - if self.settings.has_key("install_mask"): + if "install_mask" in self.settings: if type(self.settings["install_mask"])!=types.StringType: self.settings["install_mask"]=\ string.join(self.settings["install_mask"]) @@ -275,7 +275,7 @@ class generic_stage_target(generic_target): "source_subpath should have been a string. Perhaps you have something wrong in your spec file?" def set_pkgcache_path(self): - if self.settings.has_key("pkgcache_path"): + if "pkgcache_path" in self.settings: if type(self.settings["pkgcache_path"])!=types.StringType: self.settings["pkgcache_path"]=\ normpath(string.join(self.settings["pkgcache_path"])) @@ -285,7 +285,7 @@ class generic_stage_target(generic_target): self.settings["target_subpath"]+"/") def set_kerncache_path(self): - if self.settings.has_key("kerncache_path"): + if "kerncache_path" in self.settings: if type(self.settings["kerncache_path"])!=types.StringType: self.settings["kerncache_path"]=\ normpath(string.join(self.settings["kerncache_path"])) @@ -296,7 +296,7 @@ class generic_stage_target(generic_target): def set_target_path(self): self.settings["target_path"]=normpath(self.settings["storedir"]+\ "/builds/"+self.settings["target_subpath"]+".tar.bz2") - if self.settings.has_key("AUTORESUME")\ + if "AUTORESUME" in self.settings\ and os.path.exists(self.settings["autoresume_path"]+\ "setup_target_path"): print \ @@ -316,31 +316,31 @@ class generic_stage_target(generic_target): os.makedirs(self.settings["storedir"]+"/builds/") def set_fsscript(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/fsscript"): + if self.settings["spec_prefix"]+"/fsscript" in self.settings: self.settings["fsscript"]=\ self.settings[self.settings["spec_prefix"]+"/fsscript"] del self.settings[self.settings["spec_prefix"]+"/fsscript"] def set_rcadd(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/rcadd"): + if self.settings["spec_prefix"]+"/rcadd" in self.settings: self.settings["rcadd"]=\ self.settings[self.settings["spec_prefix"]+"/rcadd"] del self.settings[self.settings["spec_prefix"]+"/rcadd"] def set_rcdel(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/rcdel"): + if self.settings["spec_prefix"]+"/rcdel" in self.settings: self.settings["rcdel"]=\ self.settings[self.settings["spec_prefix"]+"/rcdel"] del self.settings[self.settings["spec_prefix"]+"/rcdel"] def set_cdtar(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/cdtar"): + if self.settings["spec_prefix"]+"/cdtar" in self.settings: self.settings["cdtar"]=\ normpath(self.settings[self.settings["spec_prefix"]+"/cdtar"]) del self.settings[self.settings["spec_prefix"]+"/cdtar"] def set_iso(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/iso"): + if self.settings["spec_prefix"]+"/iso" in self.settings: if self.settings[self.settings["spec_prefix"]+"/iso"].startswith('/'): self.settings["iso"]=\ normpath(self.settings[self.settings["spec_prefix"]+"/iso"]) @@ -353,12 +353,12 @@ class generic_stage_target(generic_target): del self.settings[self.settings["spec_prefix"]+"/iso"] def set_fstype(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/fstype"): + if self.settings["spec_prefix"]+"/fstype" in self.settings: self.settings["fstype"]=\ self.settings[self.settings["spec_prefix"]+"/fstype"] del self.settings[self.settings["spec_prefix"]+"/fstype"] - if not self.settings.has_key("fstype"): + if "fstype" not in self.settings: self.settings["fstype"]="normal" for x in self.valid_values: if x == self.settings["spec_prefix"]+"/fstype": @@ -366,15 +366,15 @@ class generic_stage_target(generic_target): "/fstype is being set to the default of \"normal\"\n" def set_fsops(self): - if self.settings.has_key("fstype"): + if "fstype" in self.settings: self.valid_values.append("fsops") - if self.settings.has_key(self.settings["spec_prefix"]+"/fsops"): + if self.settings["spec_prefix"]+"/fsops" in self.settings: self.settings["fsops"]=\ self.settings[self.settings["spec_prefix"]+"/fsops"] del self.settings[self.settings["spec_prefix"]+"/fsops"] def set_source_path(self): - if self.settings.has_key("SEEDCACHE")\ + if "SEEDCACHE" in self.settings\ and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+\ self.settings["source_subpath"]+"/")): self.settings["source_path"]=normpath(self.settings["storedir"]+\ @@ -398,7 +398,7 @@ class generic_stage_target(generic_target): self.settings["source_subpath"]+".tar.bz2\n") def set_dest_path(self): - if self.settings.has_key("root_path"): + if "root_path" in self.settings: self.settings["destpath"]=normpath(self.settings["chroot_path"]+\ self.settings["root_path"]) else: @@ -426,7 +426,7 @@ class generic_stage_target(generic_target): hash_function=self.settings["hash_function"],verbose=False) def set_snapcache_path(self): - if self.settings.has_key("SNAPCACHE"): + if "SNAPCACHE" in self.settings: self.settings["snapshot_cache_path"]=\ normpath(self.settings["snapshot_cache"]+"/"+\ self.settings["snapshot"]+"/") @@ -448,7 +448,7 @@ class generic_stage_target(generic_target): "/tmp/"+self.settings["rel_type"]+"/"+".autoresume-"+\ self.settings["target"]+"-"+self.settings["subarch"]+"-"+\ self.settings["version_stamp"]+"/") - if self.settings.has_key("AUTORESUME"): + if "AUTORESUME" in self.settings: print "The autoresume path is " + self.settings["autoresume_path"] if not os.path.exists(self.settings["autoresume_path"]): os.makedirs(self.settings["autoresume_path"],0755) @@ -459,7 +459,7 @@ class generic_stage_target(generic_target): "-controller.sh") def set_iso_volume_id(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/volid"): + if self.settings["spec_prefix"]+"/volid" in self.settings: self.settings["iso_volume_id"]=\ self.settings[self.settings["spec_prefix"]+"/volid"] if len(self.settings["iso_volume_id"])>32: @@ -474,18 +474,18 @@ class generic_stage_target(generic_target): "setup_confdir","portage_overlay",\ "base_dirs","bind","chroot_setup","setup_environment",\ "run_local","preclean","unbind","clean"] -# if self.settings.has_key("TARBALL") or \ -# not self.settings.has_key("FETCH"): - if not self.settings.has_key("FETCH"): +# if "TARBALL" in self.settings or \ +# "FETCH" not in self.settings: + if "FETCH" not in self.settings: self.settings["action_sequence"].append("capture") self.settings["action_sequence"].append("clear_autoresume") def set_use(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/use"): + if self.settings["spec_prefix"]+"/use" in self.settings: self.settings["use"]=\ self.settings[self.settings["spec_prefix"]+"/use"] del self.settings[self.settings["spec_prefix"]+"/use"] - if not self.settings.has_key("use"): + if "use" not in self.settings: self.settings["use"]="" if type(self.settings["use"])==types.StringType: self.settings["use"]=self.settings["use"].split() @@ -503,14 +503,14 @@ class generic_stage_target(generic_target): pass def set_rm(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/rm"): + if self.settings["spec_prefix"]+"/rm" in self.settings: if type(self.settings[self.settings["spec_prefix"]+\ "/rm"])==types.StringType: self.settings[self.settings["spec_prefix"]+"/rm"]=\ self.settings[self.settings["spec_prefix"]+"/rm"].split() def set_linuxrc(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/linuxrc"): + if self.settings["spec_prefix"]+"/linuxrc" in self.settings: if type(self.settings[self.settings["spec_prefix"]+\ "/linuxrc"])==types.StringType: self.settings["linuxrc"]=\ @@ -518,7 +518,7 @@ class generic_stage_target(generic_target): del self.settings[self.settings["spec_prefix"]+"/linuxrc"] def set_busybox_config(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/busybox_config"): + if self.settings["spec_prefix"]+"/busybox_config" in self.settings: if type(self.settings[self.settings["spec_prefix"]+\ "/busybox_config"])==types.StringType: self.settings["busybox_config"]=\ @@ -526,7 +526,7 @@ class generic_stage_target(generic_target): del self.settings[self.settings["spec_prefix"]+"/busybox_config"] def set_portage_overlay(self): - if self.settings.has_key("portage_overlay"): + if "portage_overlay" in self.settings: if type(self.settings["portage_overlay"])==types.StringType: self.settings["portage_overlay"]=\ self.settings["portage_overlay"].split() @@ -534,7 +534,7 @@ class generic_stage_target(generic_target): string.join(self.settings["portage_overlay"])+"\"" def set_overlay(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/overlay"): + if self.settings["spec_prefix"]+"/overlay" in self.settings: if type(self.settings[self.settings["spec_prefix"]+\ "/overlay"])==types.StringType: self.settings[self.settings["spec_prefix"]+"/overlay"]=\ @@ -542,7 +542,7 @@ class generic_stage_target(generic_target): "/overlay"].split() def set_root_overlay(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/root_overlay"): + if self.settings["spec_prefix"]+"/root_overlay" in self.settings: if type(self.settings[self.settings["spec_prefix"]+\ "/root_overlay"])==types.StringType: self.settings[self.settings["spec_prefix"]+"/root_overlay"]=\ @@ -554,7 +554,7 @@ class generic_stage_target(generic_target): self.settings["root_path"]="/" def set_valid_build_kernel_vars(self,addlargs): - if addlargs.has_key("boot/kernel"): + if "boot/kernel" in addlargs: if type(addlargs["boot/kernel"])==types.StringType: loopy=[addlargs["boot/kernel"]] else: @@ -573,14 +573,14 @@ class generic_stage_target(generic_target): self.valid_values.append("boot/kernel/"+x+"/softlevel") self.valid_values.append("boot/kernel/"+x+"/use") self.valid_values.append("boot/kernel/"+x+"/packages") - if addlargs.has_key("boot/kernel/"+x+"/packages"): + if "boot/kernel/"+x+"/packages" in addlargs: if type(addlargs["boot/kernel/"+x+\ "/packages"])==types.StringType: addlargs["boot/kernel/"+x+"/packages"]=\ [addlargs["boot/kernel/"+x+"/packages"]] def set_build_kernel_vars(self): - if self.settings.has_key(self.settings["spec_prefix"]+"/gk_mainargs"): + if self.settings["spec_prefix"]+"/gk_mainargs" in self.settings: self.settings["gk_mainargs"]=\ self.settings[self.settings["spec_prefix"]+"/gk_mainargs"] del self.settings[self.settings["spec_prefix"]+"/gk_mainargs"] @@ -634,7 +634,7 @@ class generic_stage_target(generic_target): clst_unpack_hash=read_from_clst(self.settings["autoresume_path"]+\ "unpack") - if self.settings.has_key("SEEDCACHE"): + if "SEEDCACHE" in self.settings: if os.path.isdir(self.settings["source_path"]): """ SEEDCACHE Is a directory, use rsync """ unpack_cmd="rsync -a --delete "+self.settings["source_path"]+\ @@ -676,7 +676,7 @@ class generic_stage_target(generic_target): error_msg="Tarball extraction of "+self.settings["source_path"]+\ " to "+self.settings["chroot_path"]+" failed." - if self.settings.has_key("AUTORESUME"): + if "AUTORESUME" in self.settings: if os.path.isdir(self.settings["source_path"]) \ and os.path.exists(self.settings["autoresume_path"]+"unpack"): """ Autoresume is valid, SEEDCACHE is valid """ @@ -703,7 +703,7 @@ class generic_stage_target(generic_target): invalid_snapshot=True else: """ No autoresume, SEEDCACHE """ - if self.settings.has_key("SEEDCACHE"): + if "SEEDCACHE" in self.settings: """ SEEDCACHE so let's run rsync and let it clean up """ if os.path.isdir(self.settings["source_path"]): unpack=True @@ -727,7 +727,7 @@ class generic_stage_target(generic_target): self.mount_safety_check() if invalid_snapshot: - if self.settings.has_key("AUTORESUME"): + if "AUTORESUME" in self.settings: print "No Valid Resume point detected, cleaning up..." self.clear_autoresume() @@ -739,18 +739,18 @@ class generic_stage_target(generic_target): if not os.path.exists(self.settings["chroot_path"]+"/tmp"): os.makedirs(self.settings["chroot_path"]+"/tmp",1777) - if self.settings.has_key("PKGCACHE"): + if "PKGCACHE" in self.settings: if not os.path.exists(self.settings["pkgcache_path"]): os.makedirs(self.settings["pkgcache_path"],0755) - if self.settings.has_key("KERNCACHE"): + if "KERNCACHE" in self.settings: if not os.path.exists(self.settings["kerncache_path"]): os.makedirs(self.settings["kerncache_path"],0755) print display_msg cmd(unpack_cmd,error_msg,env=self.env) - if self.settings.has_key("source_path_hash"): + if "source_path_hash" in self.settings: myf=open(self.settings["autoresume_path"]+"unpack","w") myf.write(self.settings["source_path_hash"]) myf.close() @@ -764,7 +764,7 @@ class generic_stage_target(generic_target): snapshot_hash=read_from_clst(self.settings["autoresume_path"]+\ "unpack_portage") - if self.settings.has_key("SNAPCACHE"): + if "SNAPCACHE" in self.settings: snapshot_cache_hash=\ read_from_clst(self.settings["snapshot_cache_path"]+\ "catalyst-hash") @@ -796,7 +796,7 @@ class generic_stage_target(generic_target): self.settings["chroot_path"]+"/usr" unpack_errmsg="Error unpacking snapshot" - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["chroot_path"]+\ "/usr/portage/") \ and os.path.exists(self.settings["autoresume_path"]\ @@ -807,7 +807,7 @@ class generic_stage_target(generic_target): unpack=False if unpack: - if self.settings.has_key("SNAPCACHE"): + if "SNAPCACHE" in self.settings: self.snapshot_lock_object.write_lock() if os.path.exists(destdir): print cleanup_msg @@ -819,7 +819,7 @@ class generic_stage_target(generic_target): print "Unpacking portage tree (This can take a long time) ..." cmd(unpack_cmd,unpack_errmsg,env=self.env) - if self.settings.has_key("SNAPCACHE"): + if "SNAPCACHE" in self.settings: myf=open(self.settings["snapshot_cache_path"]+"catalyst-hash","w") myf.write(self.settings["snapshot_path_hash"]) myf.close() @@ -829,11 +829,11 @@ class generic_stage_target(generic_target): myf.write(self.settings["snapshot_path_hash"]) myf.close() - if self.settings.has_key("SNAPCACHE"): + if "SNAPCACHE" in self.settings: self.snapshot_lock_object.unlock() def config_profile_link(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+\ "config_profile_link"): print \ @@ -852,12 +852,12 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"config_profile_link") def setup_confdir(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+\ "setup_confdir"): print "Resume point detected, skipping setup_confdir operation..." else: - if self.settings.has_key("portage_confdir"): + if "portage_confdir" in self.settings: print "Configuring /etc/portage..." cmd("rsync -a "+self.settings["portage_confdir"]+"/ "+\ self.settings["chroot_path"]+"/etc/portage/",\ @@ -866,7 +866,7 @@ class generic_stage_target(generic_target): def portage_overlay(self): """ We copy the contents of our overlays to /usr/local/portage """ - if self.settings.has_key("portage_overlay"): + if "portage_overlay" in self.settings: for x in self.settings["portage_overlay"]: if os.path.exists(x): print "Copying overlay dir " +x @@ -879,7 +879,7 @@ class generic_stage_target(generic_target): def root_overlay(self): """ Copy over the root_overlay """ - if self.settings.has_key(self.settings["spec_prefix"]+"/root_overlay"): + if self.settings["spec_prefix"]+"/root_overlay" in self.settings: for x in self.settings[self.settings["spec_prefix"]+\ "/root_overlay"]: if os.path.exists(x): @@ -902,7 +902,7 @@ class generic_stage_target(generic_target): os.makedirs(self.mountmap[x],0755) src=self.mountmap[x] - if self.settings.has_key("SNAPCACHE") and x == "/usr/portage": + if "SNAPCACHE" in self.settings and x == "/usr/portage": self.snapshot_lock_object.read_lock() if os.uname()[0] == "FreeBSD": if src == "/dev": @@ -913,7 +913,7 @@ class generic_stage_target(generic_target): self.settings["chroot_path"]+x) else: if src == "tmpfs": - if self.settings.has_key("var_tmpfs_portage"): + if "var_tmpfs_portage" in self.settings: retval=os.system("mount -t tmpfs -o size="+\ self.settings["var_tmpfs_portage"]+"G "+src+" "+\ self.settings["chroot_path"]+x) @@ -951,7 +951,7 @@ class generic_stage_target(generic_target): ouch=1 warn("Couldn't umount bind mount: "+mypath+x) - if self.settings.has_key("SNAPCACHE") and x == "/usr/portage": + if "SNAPCACHE" in self.settings and x == "/usr/portage": try: """ It's possible the snapshot lock object isn't created yet. @@ -978,7 +978,7 @@ class generic_stage_target(generic_target): self.override_cflags() self.override_cxxflags() self.override_ldflags() - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"chroot_setup"): print "Resume point detected, skipping chroot_setup operation..." else: @@ -990,7 +990,7 @@ class generic_stage_target(generic_target): "Could not copy resolv.conf into place.",env=self.env) """ Copy over the envscript, if applicable """ - if self.settings.has_key("ENVSCRIPT"): + if "ENVSCRIPT" in self.settings: if not os.path.exists(self.settings["ENVSCRIPT"]): raise CatalystError,\ "Can't find envscript "+self.settings["ENVSCRIPT"] @@ -1025,9 +1025,9 @@ class generic_stage_target(generic_target): myf=open(self.settings["chroot_path"]+"/etc/portage/make.conf","w") myf.write("# These settings were set by the catalyst build script that automatically\n# built this stage.\n") myf.write("# Please consult /usr/share/portage/config/make.conf.example for a more\n# detailed example.\n") - if self.settings.has_key("CFLAGS"): + if "CFLAGS" in self.settings: myf.write('CFLAGS="'+self.settings["CFLAGS"]+'"\n') - if self.settings.has_key("CXXFLAGS"): + if "CXXFLAGS" in self.settings: if self.settings["CXXFLAGS"]!=self.settings["CFLAGS"]: myf.write('CXXFLAGS="'+self.settings["CXXFLAGS"]+'"\n') else: @@ -1035,10 +1035,10 @@ class generic_stage_target(generic_target): else: myf.write('CXXFLAGS="${CFLAGS}"\n') - if self.settings.has_key("LDFLAGS"): + if "LDFLAGS" in self.settings: myf.write("# LDFLAGS is unsupported. USE AT YOUR OWN RISK!\n") myf.write('LDFLAGS="'+self.settings["LDFLAGS"]+'"\n') - if self.settings.has_key("CBUILD"): + if "CBUILD" in self.settings: myf.write("# This should not be changed unless you know exactly what you are doing. You\n# should probably be using a different stage, instead.\n") myf.write('CBUILD="'+self.settings["CBUILD"]+'"\n') @@ -1047,10 +1047,10 @@ class generic_stage_target(generic_target): """ Figure out what our USE vars are for building """ myusevars=[] - if self.settings.has_key("HOSTUSE"): + if "HOSTUSE" in self.settings: myusevars.extend(self.settings["HOSTUSE"]) - if self.settings.has_key("use"): + if "use" in self.settings: myusevars.extend(self.settings["use"]) if myusevars: @@ -1064,7 +1064,7 @@ class generic_stage_target(generic_target): print "\tpackage.use in the profile and portage_confdir. You've been warned!" """ Setup the portage overlay """ - if self.settings.has_key("portage_overlay"): + if "portage_overlay" in self.settings: myf.write('PORTDIR_OVERLAY="/usr/local/portage"\n') myf.close() @@ -1074,18 +1074,18 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"chroot_setup") def fsscript(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"fsscript"): print "Resume point detected, skipping fsscript operation..." else: - if self.settings.has_key("fsscript"): + if "fsscript" in self.settings: if os.path.exists(self.settings["controller_file"]): cmd("/bin/bash "+self.settings["controller_file"]+\ " fsscript","fsscript script failed.",env=self.env) touch(self.settings["autoresume_path"]+"fsscript") def rcupdate(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"rcupdate"): print "Resume point detected, skipping rcupdate operation..." else: @@ -1095,7 +1095,7 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"rcupdate") def clean(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"clean"): print "Resume point detected, skipping clean operation..." else: @@ -1130,11 +1130,11 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"clean") def empty(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"empty"): print "Resume point detected, skipping empty operation..." else: - if self.settings.has_key(self.settings["spec_prefix"]+"/empty"): + if self.settings["spec_prefix"]+"/empty" in self.settings: if type(self.settings[self.settings["spec_prefix"]+\ "/empty"])==types.StringType: self.settings[self.settings["spec_prefix"]+"/empty"]=\ @@ -1158,11 +1158,11 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"empty") def remove(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"remove"): print "Resume point detected, skipping remove operation..." else: - if self.settings.has_key(self.settings["spec_prefix"]+"/rm"): + if self.settings["spec_prefix"]+"/rm" in self.settings: for x in self.settings[self.settings["spec_prefix"]+"/rm"]: """ We're going to shell out for all these cleaning @@ -1180,7 +1180,7 @@ class generic_stage_target(generic_target): raise def preclean(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"preclean"): print "Resume point detected, skipping preclean operation..." else: @@ -1195,7 +1195,7 @@ class generic_stage_target(generic_target): raise CatalystError, "Build failed, could not execute preclean" def capture(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"capture"): print "Resume point detected, skipping capture operation..." else: @@ -1220,7 +1220,7 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"capture") def run_local(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"run_local"): print "Resume point detected, skipping run_local operation..." else: @@ -1257,7 +1257,7 @@ class generic_stage_target(generic_target): self.env[varname]="true" else: self.env[varname]="false" - if self.settings.has_key("makeopts"): + if "makeopts" in self.settings: self.env["MAKEOPTS"]=self.settings["makeopts"] def run(self): @@ -1269,18 +1269,18 @@ class generic_stage_target(generic_target): """ Check for mounts right away and abort if we cannot unmount them """ self.mount_safety_check() - if self.settings.has_key("CLEAR_AUTORESUME"): + if "CLEAR_AUTORESUME" in self.settings: self.clear_autoresume() - if self.settings.has_key("PURGETMPONLY"): + if "PURGETMPONLY" in self.settings: self.purge() return - if self.settings.has_key("PURGEONLY"): + if "PURGEONLY" in self.settings: self.purge() return - if self.settings.has_key("PURGE"): + if "PURGE" in self.settings: self.purge() for x in self.settings["action_sequence"]: @@ -1295,11 +1295,11 @@ class generic_stage_target(generic_target): self.chroot_lock.unlock() def unmerge(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"unmerge"): print "Resume point detected, skipping unmerge operation..." else: - if self.settings.has_key(self.settings["spec_prefix"]+"/unmerge"): + if self.settings["spec_prefix"]+"/unmerge" in self.settings: if type(self.settings[self.settings["spec_prefix"]+\ "/unmerge"])==types.StringType: self.settings[self.settings["spec_prefix"]+"/unmerge"]=\ @@ -1327,7 +1327,7 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"unmerge") def target_setup(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"target_setup"): print "Resume point detected, skipping target_setup operation..." else: @@ -1338,11 +1338,11 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"target_setup") def setup_overlay(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"): print "Resume point detected, skipping setup_overlay operation..." else: - if self.settings.has_key(self.settings["spec_prefix"]+"/overlay"): + if self.settings["spec_prefix"]+"/overlay" in self.settings: for x in self.settings[self.settings["spec_prefix"]+"/overlay"]: if os.path.exists(x): cmd("rsync -a "+x+"/ "+\ @@ -1352,12 +1352,12 @@ class generic_stage_target(generic_target): touch(self.settings["autoresume_path"]+"setup_overlay") def create_iso(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"create_iso"): print "Resume point detected, skipping create_iso operation..." else: """ Create the ISO """ - if self.settings.has_key("iso"): + if "iso" in self.settings: cmd("/bin/bash "+self.settings["controller_file"]+" iso "+\ self.settings["iso"],"ISO creation script failed.",\ env=self.env) @@ -1369,13 +1369,13 @@ class generic_stage_target(generic_target): print "An ISO Image will not be created." def build_packages(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+\ "build_packages"): print "Resume point detected, skipping build_packages operation..." else: - if self.settings.has_key(self.settings["spec_prefix"]+"/packages"): - if self.settings.has_key("AUTORESUME") \ + if self.settings["spec_prefix"]+"/packages" in self.settings: + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+\ "build_packages"): print "Resume point detected, skipping build_packages operation..." @@ -1394,11 +1394,11 @@ class generic_stage_target(generic_target): "build aborting due to error." def build_kernel(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"build_kernel"): print "Resume point detected, skipping build_kernel operation..." else: - if self.settings.has_key("boot/kernel"): + if "boot/kernel" in self.settings: try: mynames=self.settings["boot/kernel"] if type(mynames)==types.StringType: @@ -1411,7 +1411,7 @@ class generic_stage_target(generic_target): env=self.env) for kname in mynames: - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]\ +"build_kernel_"+kname): print "Resume point detected, skipping build_kernel for "+kname+" operation..." @@ -1444,8 +1444,7 @@ class generic_stage_target(generic_target): If we need to pass special options to the bootloader for this kernel put them into the environment """ - if self.settings.has_key("boot/kernel/"+kname+\ - "/kernelopts"): + if "boot/kernel/"+kname+"/kernelopts" in self.settings: myopts=self.settings["boot/kernel/"+kname+\ "/kernelopts"] @@ -1456,8 +1455,7 @@ class generic_stage_target(generic_target): else: self.env[kname+"_kernelopts"]="" - if not self.settings.has_key("boot/kernel/"+kname+\ - "/extraversion"): + if "boot/kernel/"+kname+"/extraversion" not in self.settings: self.settings["boot/kernel/"+kname+\ "/extraversion"]="" @@ -1465,8 +1463,7 @@ class generic_stage_target(generic_target): self.settings["boot/kernel/"+kname+\ "/extraversion"] - if self.settings.has_key("boot/kernel/"+kname+\ - "/initramfs_overlay"): + if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings: if os.path.exists(self.settings["boot/kernel/"+\ kname+"/initramfs_overlay"]): print "Copying initramfs_overlay dir "+\ @@ -1491,8 +1488,7 @@ class generic_stage_target(generic_target): " kernel "+kname,\ "Runscript kernel build failed",env=self.env) - if self.settings.has_key("boot/kernel/"+kname+\ - "/initramfs_overlay"): + if "boot/kernel/"+kname+"/initramfs_overlay" in self.settings: if os.path.exists(self.settings["chroot_path"]+\ "/tmp/initramfs_overlay/"): print "Cleaning up temporary overlay dir" @@ -1518,7 +1514,7 @@ class generic_stage_target(generic_target): "build aborting due to kernel build error." def bootloader(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"bootloader"): print "Resume point detected, skipping bootloader operation..." else: @@ -1532,7 +1528,7 @@ class generic_stage_target(generic_target): raise CatalystError,"Script aborting due to error." def livecd_update(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+\ "livecd_update"): print "Resume point detected, skipping build_packages operation..." @@ -1565,7 +1561,7 @@ class generic_stage_target(generic_target): os.chmod(myemp,mystat[ST_MODE]) def clear_packages(self): - if self.settings.has_key("PKGCACHE"): + if "PKGCACHE" in self.settings: print "purging the pkgcache ..." myemp=self.settings["pkgcache_path"] @@ -1583,7 +1579,7 @@ class generic_stage_target(generic_target): os.chmod(myemp,mystat[ST_MODE]) def clear_kerncache(self): - if self.settings.has_key("KERNCACHE"): + if "KERNCACHE" in self.settings: print "purging the kerncache ..." myemp=self.settings["kerncache_path"] @@ -1602,11 +1598,11 @@ class generic_stage_target(generic_target): def clear_autoresume(self): """ Clean resume points since they are no longer needed """ - if self.settings.has_key("AUTORESUME"): + if "AUTORESUME" in self.settings: print "Removing AutoResume Points: ..." myemp=self.settings["autoresume_path"] if os.path.isdir(myemp): - if self.settings.has_key("AUTORESUME"): + if "AUTORESUME" in self.settings: print "Emptying directory",myemp """ stat the dir, delete the dir, recreate the dir and set @@ -1626,7 +1622,7 @@ class generic_stage_target(generic_target): def gen_contents_file(self,file): if os.path.exists(file+".CONTENTS"): os.remove(file+".CONTENTS") - if self.settings.has_key("contents"): + if "contents" in self.settings: if os.path.exists(file): myf=open(file+".CONTENTS","w") keys={} @@ -1636,7 +1632,7 @@ class generic_stage_target(generic_target): array.sort() for j in array: contents=generate_contents(file,contents_function=j,\ - verbose=self.settings.has_key("VERBOSE")) + verbose="VERBOSE" in self.settings) if contents: myf.write(contents) myf.close() @@ -1644,7 +1640,7 @@ class generic_stage_target(generic_target): def gen_digest_file(self,file): if os.path.exists(file+".DIGESTS"): os.remove(file+".DIGESTS") - if self.settings.has_key("digests"): + if "digests" in self.settings: if os.path.exists(file): myf=open(file+".DIGESTS","w") keys={} @@ -1657,25 +1653,25 @@ class generic_stage_target(generic_target): if "all" in array: for k in hash_map.keys(): hash=generate_hash(f,hash_function=k,verbose=\ - self.settings.has_key("VERBOSE")) + "VERBOSE" in self.settings) myf.write(hash) else: for j in array: hash=generate_hash(f,hash_function=j,verbose=\ - self.settings.has_key("VERBOSE")) + "VERBOSE" in self.settings) myf.write(hash) myf.close() def purge(self): countdown(10,"Purging Caches ...") - if self.settings.has_key("PURGE") or self.settings.has_key("PURGEONLY") or self.settings.has_key("PURGETMPONLY"): + if any(k in self.settings for k in ("PURGE","PURGEONLY","PURGETMPONLY")): print "clearing autoresume ..." self.clear_autoresume() print "clearing chroot ..." self.clear_chroot() - if not self.settings.has_key("PURGETMPONLY"): + if "PURGETMPONLY" not in self.settings: print "clearing package cache ..." self.clear_packages() diff --git a/modules/grp_target.py b/modules/grp_target.py index 12eab08c..654b5e5c 100644 --- a/modules/grp_target.py +++ b/modules/grp_target.py @@ -17,14 +17,14 @@ class grp_target(generic_stage_target): self.valid_values=self.required_values[:] self.valid_values.extend(["grp/use"]) - if not addlargs.has_key("grp"): + if "grp" not in addlargs: raise CatalystError,"Required value \"grp\" not specified in spec." self.required_values.extend(["grp"]) if type(addlargs["grp"])==types.StringType: addlargs["grp"]=[addlargs["grp"]] - if addlargs.has_key("grp/use"): + if "grp/use" in addlargs: if type(addlargs["grp/use"])==types.StringType: addlargs["grp/use"]=[addlargs["grp/use"]] @@ -36,7 +36,7 @@ class grp_target(generic_stage_target): def set_target_path(self): self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): print "Resume point detected, skipping target path setup operation..." else: @@ -63,7 +63,7 @@ class grp_target(generic_stage_target): def set_use(self): generic_stage_target.set_use(self) - if self.settings.has_key("use"): + if "use" in self.settings: self.settings["use"].append("bindist") else: self.settings["use"]=["bindist"] diff --git a/modules/livecd_stage1_target.py b/modules/livecd_stage1_target.py index 17254bb1..5b552b9b 100644 --- a/modules/livecd_stage1_target.py +++ b/modules/livecd_stage1_target.py @@ -25,7 +25,7 @@ class livecd_stage1_target(generic_stage_target): def set_target_path(self): self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]) - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): print "Resume point detected, skipping target path setup operation..." else: @@ -46,7 +46,7 @@ class livecd_stage1_target(generic_stage_target): def set_use(self): generic_stage_target.set_use(self) - if self.settings.has_key("use"): + if "use" in self.settings: self.settings["use"].append("livecd") self.settings["use"].append("bindist") else: @@ -55,14 +55,14 @@ class livecd_stage1_target(generic_stage_target): def set_packages(self): generic_stage_target.set_packages(self) - if self.settings.has_key(self.settings["spec_prefix"]+"/packages"): + if self.settings["spec_prefix"]+"/packages" in self.settings: if type(self.settings[self.settings["spec_prefix"]+"/packages"]) == types.StringType: self.settings[self.settings["spec_prefix"]+"/packages"] = \ self.settings[self.settings["spec_prefix"]+"/packages"].split() self.settings[self.settings["spec_prefix"]+"/packages"].append("app-misc/livecd-tools") def set_pkgcache_path(self): - if self.settings.has_key("pkgcache_path"): + if "pkgcache_path" in self.settings: if type(self.settings["pkgcache_path"]) != types.StringType: self.settings["pkgcache_path"]=normpath(string.join(self.settings["pkgcache_path"])) else: diff --git a/modules/livecd_stage2_target.py b/modules/livecd_stage2_target.py index 4fbd645e..f816b214 100644 --- a/modules/livecd_stage2_target.py +++ b/modules/livecd_stage2_target.py @@ -27,7 +27,7 @@ class livecd_stage2_target(generic_stage_target): "gamecd/conf","livecd/xdm","livecd/xsession","livecd/volid"]) generic_stage_target.__init__(self,spec,addlargs) - if not self.settings.has_key("livecd/type"): + if "livecd/type" not in self.settings: self.settings["livecd/type"] = "generic-livecd" file_locate(self.settings, ["cdtar","controller_file"]) @@ -46,7 +46,7 @@ class livecd_stage2_target(generic_stage_target): def set_target_path(self): self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["target_subpath"]+"/") - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): print "Resume point detected, skipping target path setup operation..." else: @@ -60,7 +60,7 @@ class livecd_stage2_target(generic_stage_target): def run_local(self): # what modules do we want to blacklist? - if self.settings.has_key("livecd/modblacklist"): + if "livecd/modblacklist" in self.settings: try: myf=open(self.settings["chroot_path"]+"/etc/modprobe.d/blacklist.conf","a") except: @@ -85,12 +85,12 @@ class livecd_stage2_target(generic_stage_target): error_msg="Rsync of "+self.settings["source_path"]+" to "+self.settings["chroot_path"]+" failed." invalid_snapshot=False - if self.settings.has_key("AUTORESUME"): + if "AUTORESUME" in self.settings: if os.path.isdir(self.settings["source_path"]) and \ os.path.exists(self.settings["autoresume_path"]+"unpack"): print "Resume point detected, skipping unpack operation..." unpack=False - elif self.settings.has_key("source_path_hash"): + elif "source_path_hash" in self.settings: if self.settings["source_path_hash"] != clst_unpack_hash: invalid_snapshot=True @@ -109,7 +109,7 @@ class livecd_stage2_target(generic_stage_target): if not os.path.exists(self.settings["chroot_path"]+"/tmp"): os.makedirs(self.settings["chroot_path"]+"/tmp",1777) - if self.settings.has_key("PKGCACHE"): + if "PKGCACHE" in self.settings: if not os.path.exists(self.settings["pkgcache_path"]): os.makedirs(self.settings["pkgcache_path"],0755) @@ -119,7 +119,7 @@ class livecd_stage2_target(generic_stage_target): print display_msg cmd(unpack_cmd,error_msg,env=self.env) - if self.settings.has_key("source_path_hash"): + if "source_path_hash" in self.settings: myf=open(self.settings["autoresume_path"]+"unpack","w") myf.write(self.settings["source_path_hash"]) myf.close() @@ -131,7 +131,7 @@ class livecd_stage2_target(generic_stage_target): "config_profile_link","setup_confdir","portage_overlay",\ "bind","chroot_setup","setup_environment","run_local",\ "build_kernel"] - if not self.settings.has_key("FETCH"): + if "FETCH" not in self.settings: self.settings["action_sequence"] += ["bootloader","preclean",\ "livecd_update","root_overlay","fsscript","rcupdate","unmerge",\ "unbind","remove","empty","target_setup",\ diff --git a/modules/netboot2_target.py b/modules/netboot2_target.py index ebc3be03..1ab7e7da 100644 --- a/modules/netboot2_target.py +++ b/modules/netboot2_target.py @@ -27,7 +27,7 @@ class netboot2_target(generic_stage_target): ]) try: - if addlargs.has_key("netboot2/packages"): + if "netboot2/packages" in addlargs: if type(addlargs["netboot2/packages"]) == types.StringType: loopy=[addlargs["netboot2/packages"]] else: @@ -45,7 +45,7 @@ class netboot2_target(generic_stage_target): def set_target_path(self): self.settings["target_path"]=normpath(self.settings["storedir"]+"/builds/"+\ self.settings["target_subpath"]+"/") - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_target_path"): print "Resume point detected, skipping target path setup operation..." else: @@ -63,24 +63,24 @@ class netboot2_target(generic_stage_target): myfiles=[] # check for autoresume point - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"copy_files_to_image"): print "Resume point detected, skipping target path setup operation..." else: - if self.settings.has_key("netboot2/packages"): + if "netboot2/packages" in self.settings: if type(self.settings["netboot2/packages"]) == types.StringType: loopy=[self.settings["netboot2/packages"]] else: loopy=self.settings["netboot2/packages"] for x in loopy: - if self.settings.has_key("netboot2/packages/"+x+"/files"): + if "netboot2/packages/"+x+"/files" in self.settings: if type(self.settings["netboot2/packages/"+x+"/files"]) == types.ListType: myfiles.extend(self.settings["netboot2/packages/"+x+"/files"]) else: myfiles.append(self.settings["netboot2/packages/"+x+"/files"]) - if self.settings.has_key("netboot2/extra_files"): + if "netboot2/extra_files" in self.settings: if type(self.settings["netboot2/extra_files"]) == types.ListType: myfiles.extend(self.settings["netboot2/extra_files"]) else: @@ -96,11 +96,11 @@ class netboot2_target(generic_stage_target): touch(self.settings["autoresume_path"]+"copy_files_to_image") def setup_overlay(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"setup_overlay"): print "Resume point detected, skipping setup_overlay operation..." else: - if self.settings.has_key("netboot2/overlay"): + if "netboot2/overlay" in self.settings: for x in self.settings["netboot2/overlay"]: if os.path.exists(x): cmd("rsync -a "+x+"/ "+\ @@ -120,11 +120,11 @@ class netboot2_target(generic_stage_target): raise CatalystError,"Failed to move kernel images!" def remove(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"remove"): print "Resume point detected, skipping remove operation..." else: - if self.settings.has_key(self.settings["spec_prefix"]+"/rm"): + if self.settings["spec_prefix"]+"/rm" in self.settings: for x in self.settings[self.settings["spec_prefix"]+"/rm"]: # we're going to shell out for all these cleaning operations, # so we get easy glob handling @@ -132,11 +132,11 @@ class netboot2_target(generic_stage_target): os.system("rm -rf " + self.settings["chroot_path"] + self.settings["merge_path"] + x) def empty(self): - if self.settings.has_key("AUTORESUME") \ + if "AUTORESUME" in self.settings \ and os.path.exists(self.settings["autoresume_path"]+"empty"): print "Resume point detected, skipping empty operation..." else: - if self.settings.has_key("netboot2/empty"): + if "netboot2/empty" in self.settings: if type(self.settings["netboot2/empty"])==types.StringType: self.settings["netboot2/empty"]=self.settings["netboot2/empty"].split() for x in self.settings["netboot2/empty"]: diff --git a/modules/netboot_target.py b/modules/netboot_target.py index de7ff36a..ff2c81fb 100644 --- a/modules/netboot_target.py +++ b/modules/netboot_target.py @@ -25,7 +25,7 @@ class netboot_target(generic_stage_target): self.required_values=[] try: - if addlargs.has_key("netboot/packages"): + if "netboot/packages" in addlargs: if type(addlargs["netboot/packages"]) == types.StringType: loopy=[addlargs["netboot/packages"]] else: @@ -38,7 +38,7 @@ class netboot_target(generic_stage_target): generic_stage_target.__init__(self,spec,addlargs) self.set_build_kernel_vars(addlargs) - if addlargs.has_key("netboot/busybox_config"): + if "netboot/busybox_config" in addlargs: file_locate(self.settings, ["netboot/busybox_config"]) # Custom Kernel Tarball --- use that instead ... @@ -46,7 +46,7 @@ class netboot_target(generic_stage_target): # unless the user wants specific CFLAGS/CXXFLAGS, let's use -Os for envvar in "CFLAGS", "CXXFLAGS": - if not os.environ.has_key(envvar) and not addlargs.has_key(envvar): + if envvar not in os.environ and envvar not in addlargs: self.settings[envvar] = "-Os -pipe" def set_root_path(self): @@ -56,7 +56,7 @@ class netboot_target(generic_stage_target): # def build_packages(self): # # build packages -# if self.settings.has_key("netboot/packages"): +# if "netboot/packages" in self.settings: # mypack=list_bashify(self.settings["netboot/packages"]) # try: # cmd("/bin/bash "+self.settings["controller_file"]+" packages "+mypack,env=self.env) @@ -66,7 +66,7 @@ class netboot_target(generic_stage_target): def build_busybox(self): # build busybox - if self.settings.has_key("netboot/busybox_config"): + if "netboot/busybox_config" in self.settings: mycmd = self.settings["netboot/busybox_config"] else: mycmd = "" @@ -79,20 +79,20 @@ class netboot_target(generic_stage_target): def copy_files_to_image(self): # create image myfiles=[] - if self.settings.has_key("netboot/packages"): + if "netboot/packages" in self.settings: if type(self.settings["netboot/packages"]) == types.StringType: loopy=[self.settings["netboot/packages"]] else: loopy=self.settings["netboot/packages"] for x in loopy: - if self.settings.has_key("netboot/packages/"+x+"/files"): + if "netboot/packages/"+x+"/files" in self.settings: if type(self.settings["netboot/packages/"+x+"/files"]) == types.ListType: myfiles.extend(self.settings["netboot/packages/"+x+"/files"]) else: myfiles.append(self.settings["netboot/packages/"+x+"/files"]) - if self.settings.has_key("netboot/extra_files"): + if "netboot/extra_files" in self.settings: if type(self.settings["netboot/extra_files"]) == types.ListType: myfiles.extend(self.settings["netboot/extra_files"]) else: diff --git a/modules/snapshot_target.py b/modules/snapshot_target.py index 81ab083f..e93a86a5 100644 --- a/modules/snapshot_target.py +++ b/modules/snapshot_target.py @@ -31,11 +31,11 @@ class snapshot_target(generic_stage_target): pass def run(self): - if self.settings.has_key("PURGEONLY"): + if "PURGEONLY" in self.settings: self.purge() return - if self.settings.has_key("PURGE"): + if "PURGE" in self.settings: self.purge() self.setup() diff --git a/modules/stage1_target.py b/modules/stage1_target.py index 6a439eca..aa439266 100644 --- a/modules/stage1_target.py +++ b/modules/stage1_target.py @@ -33,24 +33,24 @@ class stage1_target(generic_stage_target): # XXX: How do these override_foo() functions differ from the ones in generic_stage_target and why aren't they in stage3_target? def override_chost(self): - if self.settings.has_key("chost"): + if "chost" in self.settings: self.settings["CHOST"]=list_to_string(self.settings["chost"]) def override_cflags(self): - if self.settings.has_key("cflags"): + if "cflags" in self.settings: self.settings["CFLAGS"]=list_to_string(self.settings["cflags"]) def override_cxxflags(self): - if self.settings.has_key("cxxflags"): + if "cxxflags" in self.settings: self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"]) def override_ldflags(self): - if self.settings.has_key("ldflags"): + if "ldflags" in self.settings: self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"]) def set_portage_overlay(self): generic_stage_target.set_portage_overlay(self) - if self.settings.has_key("portage_overlay"): + if "portage_overlay" in self.settings: print "\nWARNING !!!!!" print "\tUsing an portage overlay for earlier stages could cause build issues." print "\tIf you break it, you buy it. Don't complain to us about it." diff --git a/modules/stage2_target.py b/modules/stage2_target.py index 34f44714..6083e2bb 100644 --- a/modules/stage2_target.py +++ b/modules/stage2_target.py @@ -16,7 +16,7 @@ class stage2_target(generic_stage_target): generic_stage_target.__init__(self,spec,addlargs) def set_source_path(self): - if self.settings.has_key("SEEDCACHE") and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")): + if "SEEDCACHE" in self.settings and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")): self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/") else: self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2") @@ -34,24 +34,24 @@ class stage2_target(generic_stage_target): # generic_stage_target and why aren't they in stage3_target? def override_chost(self): - if self.settings.has_key("chost"): + if "chost" in self.settings: self.settings["CHOST"]=list_to_string(self.settings["chost"]) def override_cflags(self): - if self.settings.has_key("cflags"): + if "cflags" in self.settings: self.settings["CFLAGS"]=list_to_string(self.settings["cflags"]) def override_cxxflags(self): - if self.settings.has_key("cxxflags"): + if "cxxflags" in self.settings: self.settings["CXXFLAGS"]=list_to_string(self.settings["cxxflags"]) def override_ldflags(self): - if self.settings.has_key("ldflags"): + if "ldflags" in self.settings: self.settings["LDFLAGS"]=list_to_string(self.settings["ldflags"]) def set_portage_overlay(self): generic_stage_target.set_portage_overlay(self) - if self.settings.has_key("portage_overlay"): + if "portage_overlay" in self.settings: print "\nWARNING !!!!!" print "\tUsing an portage overlay for earlier stages could cause build issues." print "\tIf you break it, you buy it. Don't complain to us about it." diff --git a/modules/stage3_target.py b/modules/stage3_target.py index 8c839dfc..4d3a008c 100644 --- a/modules/stage3_target.py +++ b/modules/stage3_target.py @@ -17,7 +17,7 @@ class stage3_target(generic_stage_target): def set_portage_overlay(self): generic_stage_target.set_portage_overlay(self) - if self.settings.has_key("portage_overlay"): + if "portage_overlay" in self.settings: print "\nWARNING !!!!!" print "\tUsing an overlay for earlier stages could cause build issues." print "\tIf you break it, you buy it. Don't complain to us about it." diff --git a/modules/stage4_target.py b/modules/stage4_target.py index 591f9b20..ce41b2da 100644 --- a/modules/stage4_target.py +++ b/modules/stage4_target.py @@ -31,9 +31,9 @@ class stage4_target(generic_stage_target): "preclean","rcupdate","unmerge","unbind","remove","empty",\ "clean"] -# if self.settings.has_key("TARBALL") or \ -# not self.settings.has_key("FETCH"): - if not self.settings.has_key("FETCH"): +# if "TARBALL" in self.settings or \ +# "FETCH" not in self.settings: + if "FETCH" not in self.settings: self.settings["action_sequence"].append("capture") self.settings["action_sequence"].append("clear_autoresume") -- 2.26.2