diff options
author | Mike Frysinger <vapier@gentoo.org> | 2015-10-11 23:54:33 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-10-28 12:49:56 -0400 |
commit | 9b0ba31859207264f5bf7af048d5d89725dd4025 (patch) | |
tree | d821ad7daf675e0889d03b2a15ff28a36686eb60 | |
parent | hash_utils: decode output of popen (diff) | |
download | catalyst-9b0ba31859207264f5bf7af048d5d89725dd4025.tar.gz catalyst-9b0ba31859207264f5bf7af048d5d89725dd4025.tar.bz2 catalyst-9b0ba31859207264f5bf7af048d5d89725dd4025.zip |
lint: convert type/types to isinstance
pylint complains about using (type(...) == types.xxx) checks as it
prefers isinstance(..., xxx) instead. Convert the code base to it.
-rw-r--r-- | .pylintrc | 3 | ||||
-rw-r--r-- | catalyst/base/stagebase.py | 57 | ||||
-rw-r--r-- | catalyst/support.py | 3 | ||||
-rw-r--r-- | catalyst/targets/grp.py | 5 | ||||
-rw-r--r-- | catalyst/targets/livecd_stage1.py | 5 | ||||
-rw-r--r-- | catalyst/targets/netboot.py | 9 | ||||
-rw-r--r-- | catalyst/targets/netboot2.py | 11 |
7 files changed, 39 insertions, 54 deletions
@@ -32,11 +32,10 @@ load-plugins= # bad-continuation -- might be hard with tab indentation policy # invalid-name -- need to manage constants better # line-too-long -- figure out a length and stick to it -# unidiomatic-typecheck -- convert to isinstance # redefined-outer-name -- clean up code to not do this # super-init-not-called -- fix the classes __init__ structure # no-init -- update classes w/missing __init__ functions -disable=missing-docstring, too-many-lines, too-many-branches, too-many-statements, too-few-public-methods, too-many-instance-attributes, too-many-public-methods, too-many-locals, too-many-arguments, locally-enabled, locally-disabled, fixme, broad-except, bad-whitespace, bad-continuation, invalid-name, line-too-long, unidiomatic-typecheck, redefined-outer-name, super-init-not-called, no-init +disable=missing-docstring, too-many-lines, too-many-branches, too-many-statements, too-few-public-methods, too-many-instance-attributes, too-many-public-methods, too-many-locals, too-many-arguments, locally-enabled, locally-disabled, fixme, broad-except, bad-whitespace, bad-continuation, invalid-name, line-too-long, redefined-outer-name, super-init-not-called, no-init [REPORTS] diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index 60941097..0e4d8c2d 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -1,7 +1,6 @@ import os import imp -import types import shutil import sys from stat import ST_UID, ST_GID, ST_MODE @@ -297,7 +296,7 @@ class StageBase(TargetBase, ClearBase, GenBase): def set_install_mask(self): if "install_mask" in self.settings: - if type(self.settings["install_mask"])!=types.StringType: + if not isinstance(self.settings['install_mask'], str): self.settings["install_mask"]=\ ' '.join(self.settings["install_mask"]) @@ -313,14 +312,14 @@ class StageBase(TargetBase, ClearBase, GenBase): self.settings["version_stamp"] +'/' def set_source_subpath(self): - if type(self.settings["source_subpath"])!=types.StringType: + if not isinstance(self.settings['source_subpath'], str): raise CatalystError( "source_subpath should have been a string. Perhaps you have " +\ "something wrong in your spec file?") def set_pkgcache_path(self): if "pkgcache_path" in self.settings: - if type(self.settings["pkgcache_path"])!=types.StringType: + if not isinstance(self.settings['pkgcache_path'], str): self.settings["pkgcache_path"]=\ normpath(self.settings["pkgcache_path"]) else: @@ -330,7 +329,7 @@ class StageBase(TargetBase, ClearBase, GenBase): def set_kerncache_path(self): if "kerncache_path" in self.settings: - if type(self.settings["kerncache_path"])!=types.StringType: + if not isinstance(self.settings['kerncache_path'], str): self.settings["kerncache_path"]=\ normpath(self.settings["kerncache_path"]) else: @@ -536,7 +535,7 @@ class StageBase(TargetBase, ClearBase, GenBase): del self.settings[self.settings["spec_prefix"]+"/use"] if "use" not in self.settings: self.settings["use"]="" - if type(self.settings["use"])==types.StringType: + if isinstance(self.settings['use'], str): self.settings["use"]=self.settings["use"].split() # Force bindist when options ask for it @@ -554,30 +553,27 @@ class StageBase(TargetBase, ClearBase, GenBase): def set_rm(self): if self.settings["spec_prefix"]+"/rm" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+\ - "/rm"])==types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/rm'], str): self.settings[self.settings["spec_prefix"]+"/rm"]=\ self.settings[self.settings["spec_prefix"]+"/rm"].split() def set_linuxrc(self): if self.settings["spec_prefix"]+"/linuxrc" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+\ - "/linuxrc"])==types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/linuxrc'], str): self.settings["linuxrc"]=\ self.settings[self.settings["spec_prefix"]+"/linuxrc"] del self.settings[self.settings["spec_prefix"]+"/linuxrc"] def set_busybox_config(self): if self.settings["spec_prefix"]+"/busybox_config" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+\ - "/busybox_config"])==types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/busybox_config'], str): self.settings["busybox_config"]=\ self.settings[self.settings["spec_prefix"]+"/busybox_config"] del self.settings[self.settings["spec_prefix"]+"/busybox_config"] def set_portage_overlay(self): if "portage_overlay" in self.settings: - if type(self.settings["portage_overlay"])==types.StringType: + if isinstance(self.settings['portage_overlay'], str): self.settings["portage_overlay"]=\ self.settings["portage_overlay"].split() log.info('portage_overlay directories are set to: %s', @@ -585,16 +581,14 @@ class StageBase(TargetBase, ClearBase, GenBase): def set_overlay(self): if self.settings["spec_prefix"]+"/overlay" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+\ - "/overlay"])==types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/overlay'], str): self.settings[self.settings["spec_prefix"]+"/overlay"]=\ self.settings[self.settings["spec_prefix"]+\ "/overlay"].split() def set_root_overlay(self): if self.settings["spec_prefix"]+"/root_overlay" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+\ - "/root_overlay"])==types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/root_overlay'], str): self.settings[self.settings["spec_prefix"]+"/root_overlay"]=\ self.settings[self.settings["spec_prefix"]+\ "/root_overlay"].split() @@ -605,7 +599,7 @@ class StageBase(TargetBase, ClearBase, GenBase): def set_valid_build_kernel_vars(self,addlargs): if "boot/kernel" in addlargs: - if type(addlargs["boot/kernel"])==types.StringType: + if isinstance(addlargs['boot/kernel'], str): loopy=[addlargs["boot/kernel"]] else: loopy=addlargs["boot/kernel"] @@ -625,8 +619,7 @@ class StageBase(TargetBase, ClearBase, GenBase): self.valid_values.append("boot/kernel/"+x+"/packages") self.valid_values.append("boot/kernel/"+x+"/kernelopts") if "boot/kernel/"+x+"/packages" in addlargs: - if type(addlargs["boot/kernel/"+x+\ - "/packages"])==types.StringType: + if isinstance(addlargs['boot/kernel/'+x+'/packages'], str): addlargs["boot/kernel/"+x+"/packages"]=\ [addlargs["boot/kernel/"+x+"/packages"]] @@ -1207,8 +1200,7 @@ class StageBase(TargetBase, ClearBase, GenBase): log.notice('Resume point detected, skipping empty operation...') else: if self.settings["spec_prefix"]+"/empty" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+\ - "/empty"])==types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/empty'], str): self.settings[self.settings["spec_prefix"]+"/empty"]=\ self.settings[self.settings["spec_prefix"]+\ "/empty"].split() @@ -1338,14 +1330,14 @@ class StageBase(TargetBase, ClearBase, GenBase): varname = "clst_" + x.replace("/", "_") varname = varname.replace("-", "_") varname = varname.replace(".", "_") - if type(self.settings[x])==types.StringType: + if isinstance(self.settings[x], str): # Prefix to prevent namespace clashes #os.environ[varname]=self.settings[x] self.env[varname]=self.settings[x] - elif type(self.settings[x])==types.ListType: + elif isinstance(self.settings[x], list): #os.environ[varname] = ' '.join(self.settings[x]) self.env[varname] = ' '.join(self.settings[x]) - elif type(self.settings[x])==types.BooleanType: + elif isinstance(self.settings[x], bool): if self.settings[x]: self.env[varname] = "true" else: @@ -1354,7 +1346,7 @@ class StageBase(TargetBase, ClearBase, GenBase): # Its currently used only for USE_EXPAND flags which are dictionaries of # lists in arch/amd64.py and friends. If we wanted self.settigs[var] # of any depth, we should make this function recursive. - elif type(self.settings[x]) == types.DictType: + elif isinstance(self.settings[x], dict): if x in ["compress_definitions", "decompress_definitions"]: continue @@ -1363,11 +1355,11 @@ class StageBase(TargetBase, ClearBase, GenBase): varname2 = "clst_" + y.replace("/", "_") varname2 = varname2.replace("-", "_") varname2 = varname2.replace(".", "_") - if type(self.settings[x][y]) == types.StringType: + if isinstance(self.settings[x][y], str): self.env[varname2] = self.settings[x][y] - elif type(self.settings[x][y]) == types.ListType: + elif isinstance(self.settings[x][y], list): self.env[varname2] = ' '.join(self.settings[x][y]) - elif type(self.settings[x][y]) == types.BooleanType: + elif isinstance(self.settings[x][y], bool): if self.settings[x][y]: self.env[varname] = "true" else: @@ -1429,8 +1421,7 @@ class StageBase(TargetBase, ClearBase, GenBase): log.notice('Resume point detected, skipping unmerge operation...') else: if self.settings["spec_prefix"]+"/unmerge" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+\ - "/unmerge"])==types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/unmerge'], str): self.settings[self.settings["spec_prefix"]+"/unmerge"]=\ [self.settings[self.settings["spec_prefix"]+"/unmerge"]] myunmerge=\ @@ -1529,7 +1520,7 @@ class StageBase(TargetBase, ClearBase, GenBase): if "boot/kernel" in self.settings: try: mynames=self.settings["boot/kernel"] - if type(mynames)==types.StringType: + if isinstance(mynames, str): mynames=[mynames] # Execute the script that sets up the kernel build environment cmd(self.settings["controller_file"]+\ @@ -1558,7 +1549,7 @@ class StageBase(TargetBase, ClearBase, GenBase): myopts=self.settings["boot/kernel/"+kname+\ "/kernelopts"] - if type(myopts) != types.StringType: + if not isinstance(myopts, str): myopts = ' '.join(myopts) self.env[kname+"_kernelopts"]=myopts diff --git a/catalyst/support.py b/catalyst/support.py index 8883acb7..380c1c1d 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -2,7 +2,6 @@ import glob import sys import os -import types import re import time from subprocess import Popen @@ -14,7 +13,7 @@ BASH_BINARY = "/bin/bash" def list_bashify(mylist): - if type(mylist)==types.StringType: + if isinstance(mylist, str): mypack=[mylist] else: mypack=mylist[:] diff --git a/catalyst/targets/grp.py b/catalyst/targets/grp.py index b37366c4..0b38417c 100644 --- a/catalyst/targets/grp.py +++ b/catalyst/targets/grp.py @@ -4,7 +4,6 @@ Gentoo Reference Platform (GRP) target # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation. import os -import types import glob from catalyst import log @@ -27,11 +26,11 @@ class grp(StageBase): raise CatalystError("Required value \"grp\" not specified in spec.") self.required_values.extend(["grp"]) - if type(addlargs["grp"])==types.StringType: + if isinstance(addlargs['grp'], str): addlargs["grp"]=[addlargs["grp"]] if "grp/use" in addlargs: - if type(addlargs["grp/use"])==types.StringType: + if isinstance(addlargs['grp/use'], str): addlargs["grp/use"]=[addlargs["grp/use"]] for x in addlargs["grp"]: diff --git a/catalyst/targets/livecd_stage1.py b/catalyst/targets/livecd_stage1.py index 8d9dcc71..70f92430 100644 --- a/catalyst/targets/livecd_stage1.py +++ b/catalyst/targets/livecd_stage1.py @@ -4,7 +4,6 @@ LiveCD stage1 target # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation. import os -import types from catalyst import log from catalyst.support import (normpath, cmd) @@ -60,14 +59,14 @@ class livecd_stage1(StageBase): def set_packages(self): StageBase.set_packages(self) if self.settings["spec_prefix"]+"/packages" in self.settings: - if type(self.settings[self.settings["spec_prefix"]+"/packages"]) == types.StringType: + if isinstance(self.settings[self.settings['spec_prefix']+'/packages'], str): 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 "pkgcache_path" in self.settings: - if type(self.settings["pkgcache_path"]) != types.StringType: + if not isinstance(self.settings['pkgcache_path'], str): self.settings["pkgcache_path"] = normpath(' '.join(self.settings["pkgcache_path"])) else: StageBase.set_pkgcache_path(self) diff --git a/catalyst/targets/netboot.py b/catalyst/targets/netboot.py index 333a2304..5285c056 100644 --- a/catalyst/targets/netboot.py +++ b/catalyst/targets/netboot.py @@ -4,7 +4,6 @@ netboot target, version 1 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation. import os -import types from catalyst import log from catalyst.support import (CatalystError, normpath, @@ -33,7 +32,7 @@ class netboot(StageBase): try: # XXX: This code does nothing because the for loop below is disabled. if "netboot/packages" in addlargs: - if type(addlargs["netboot/packages"]) == types.StringType: + if isinstance(addlargs['netboot/packages'], str): _loopy = [addlargs["netboot/packages"]] else: _loopy = addlargs["netboot/packages"] @@ -88,20 +87,20 @@ class netboot(StageBase): # create image myfiles=[] if "netboot/packages" in self.settings: - if type(self.settings["netboot/packages"]) == types.StringType: + if isinstance(self.settings['netboot/packages'], str): loopy=[self.settings["netboot/packages"]] else: loopy=self.settings["netboot/packages"] for x in loopy: if "netboot/packages/"+x+"/files" in self.settings: - if type(self.settings["netboot/packages/"+x+"/files"]) == types.ListType: + if isinstance(type(self.settings['netboot/packages/'+x+'/files']), str): myfiles.extend(self.settings["netboot/packages/"+x+"/files"]) else: myfiles.append(self.settings["netboot/packages/"+x+"/files"]) if "netboot/extra_files" in self.settings: - if type(self.settings["netboot/extra_files"]) == types.ListType: + if isinstance(self.settings['netboot/extra_files'], list): myfiles.extend(self.settings["netboot/extra_files"]) else: myfiles.append(self.settings["netboot/extra_files"]) diff --git a/catalyst/targets/netboot2.py b/catalyst/targets/netboot2.py index 8644786a..769b9452 100644 --- a/catalyst/targets/netboot2.py +++ b/catalyst/targets/netboot2.py @@ -4,7 +4,6 @@ netboot target, version 2 # NOTE: That^^ docstring has influence catalyst-spec(5) man page generation. import os -import types import shutil from stat import ST_UID, ST_GID, ST_MODE @@ -36,7 +35,7 @@ class netboot2(StageBase): try: if "netboot2/packages" in addlargs: - if type(addlargs["netboot2/packages"]) == types.StringType: + if isinstance(addlargs['netboot2/packages'], str): loopy=[addlargs["netboot2/packages"]] else: loopy=addlargs["netboot2/packages"] @@ -73,20 +72,20 @@ class netboot2(StageBase): log.notice('Resume point detected, skipping target path setup operation...') else: if "netboot2/packages" in self.settings: - if type(self.settings["netboot2/packages"]) == types.StringType: + if isinstance(self.settings['netboot2/packages'], str): loopy=[self.settings["netboot2/packages"]] else: loopy=self.settings["netboot2/packages"] for x in loopy: if "netboot2/packages/"+x+"/files" in self.settings: - if type(self.settings["netboot2/packages/"+x+"/files"]) == types.ListType: + if isinstance(self.settings['netboot2/packages/'+x+'/files'], list): myfiles.extend(self.settings["netboot2/packages/"+x+"/files"]) else: myfiles.append(self.settings["netboot2/packages/"+x+"/files"]) if "netboot2/extra_files" in self.settings: - if type(self.settings["netboot2/extra_files"]) == types.ListType: + if isinstance(self.settings['netboot2/extra_files'], list): myfiles.extend(self.settings["netboot2/extra_files"]) else: myfiles.append(self.settings["netboot2/extra_files"]) @@ -145,7 +144,7 @@ class netboot2(StageBase): log.notice('Resume point detected, skipping empty operation...') else: if "netboot2/empty" in self.settings: - if type(self.settings["netboot2/empty"])==types.StringType: + if isinstance(self.settings['netboot2/empty'], str): self.settings["netboot2/empty"]=self.settings["netboot2/empty"].split() for x in self.settings["netboot2/empty"]: myemp=self.settings["chroot_path"] + self.settings["merge_path"] + x |