commit: ecdf556b4c00325bb299e012024f97e8af33c788
Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri Apr 10 16:51:36 2020 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Apr 10 21:03:34 2020 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=ecdf556b
catalyst: Fix most pylint warnings
- consider-iterating-dictionary
- consider-using-enumerate
- inconsistent-return-statements
- len-as-condition
- literal-comparison
- no-else-raise
- no-else-return
- useless-return
Unfortunately there are more and they're a bit trickier.
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
catalyst/base/stagebase.py | 10 ++++------
catalyst/builder.py | 2 --
catalyst/config.py | 2 +-
catalyst/defaults.py | 2 --
catalyst/fileops.py | 2 +-
catalyst/log.py | 3 +--
catalyst/main.py | 5 ++---
catalyst/support.py | 23 +++++++++++------------
catalyst/targets/stage1.py | 5 -----
targets/stage1/build.py | 6 +++---
10 files changed, 23 insertions(+), 37 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 021f3beb..6f0a1bc3 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -474,7 +474,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
"/snapshots/" + self.settings["snapshot_name"] +
self.settings["snapshot"]),
self.accepted_extensions,
- self.settings["source_matching"] is "strict"
+ self.settings["source_matching"] == "strict"
)
log.info('SNAPSHOT_PATH set to: %s',
self.settings['snapshot_path'])
self.settings["snapshot_path_hash"] = \
@@ -557,7 +557,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
else:
self.settings["action_sequence"].append("remove_autoresume")
self.settings["action_sequence"].append("remove_chroot")
- return
def set_use(self):
use = self.settings["spec_prefix"] + "/use"
@@ -716,8 +715,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
self.unbind()
if ismount(target):
raise
CatalystError("Auto-unbind failed for " + target)
- else:
- log.notice('Auto-unbind
successful...')
+ log.notice('Auto-unbind successful...')
except CatalystError:
raise CatalystError("Unable to
auto-unbind " + target)
@@ -1105,7 +1103,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
continue
myf.write("# %s is unsupported. USE AT
YOUR OWN RISK!\n"
% flags)
- if flags not in self.settings or (flags is not
"COMMON_FLAGS" and
+ if flags not in self.settings or (flags !=
"COMMON_FLAGS" and
self.settings[flags] ==
self.settings["COMMON_FLAGS"]):
myf.write('%s="${COMMON_FLAGS}"\n' %
flags)
elif isinstance(self.settings[flags], list):
@@ -1442,7 +1440,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
if "purgetmponly" in self.settings["options"]:
self.purge()
- return
+ return True
if "purgeonly" in self.settings["options"]:
log.info('StageBase: run() purgeonly')
diff --git a/catalyst/builder.py b/catalyst/builder.py
index e9f468d7..64e14c8d 100644
--- a/catalyst/builder.py
+++ b/catalyst/builder.py
@@ -1,5 +1,3 @@
-import os
-
class generic():
def __init__(self,myspec):
self.settings=myspec
diff --git a/catalyst/config.py b/catalyst/config.py
index 5e70de41..1571db9d 100644
--- a/catalyst/config.py
+++ b/catalyst/config.py
@@ -22,7 +22,7 @@ class ParserBase():
def dump(self):
dump = ""
- for x in self.values.keys():
+ for x in self.values:
dump += x + " = " + repr(self.values[x]) + "\n"
return dump
diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index bcb59796..349f16f6 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -1,6 +1,4 @@
-import os
-
from DeComp.definitions import DECOMPRESSOR_SEARCH_ORDER
from DeComp.definitions import COMPRESSOR_PROGRAM_OPTIONS, XATTRS_OPTIONS
from DeComp.definitions import DECOMPRESSOR_PROGRAM_OPTIONS,
LIST_XATTRS_OPTIONS
diff --git a/catalyst/fileops.py b/catalyst/fileops.py
index 9fa23c52..fffcfc6a 100644
--- a/catalyst/fileops.py
+++ b/catalyst/fileops.py
@@ -18,7 +18,7 @@ from snakeoil.osutils import (ensure_dirs as
snakeoil_ensure_dirs,
# pylint: enable=unused-import
from catalyst import log
-from catalyst.support import (cmd, CatalystError)
+from catalyst.support import CatalystError
def ensure_dirs(path, gid=-1, uid=-1, mode=0o755, minimal=True,
diff --git a/catalyst/log.py b/catalyst/log.py
index 7956c28f..8a23660a 100644
--- a/catalyst/log.py
+++ b/catalyst/log.py
@@ -92,8 +92,7 @@ class CatalystFormatter(logging.Formatter):
color = self._COLORS.get(record.levelname)
if color:
return color + msg + self._NORMAL
- else:
- return msg
+ return msg
# We define |debug| in global scope so people can call log.debug(), but it
diff --git a/catalyst/main.py b/catalyst/main.py
index 14733540..24e9a759 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -271,10 +271,9 @@ def main(argv):
if opts.trace:
return trace(_main, parser, opts)
- elif opts.profile:
+ if opts.profile:
return profile(_main, parser, opts)
- else:
- return _main(parser, opts)
+ return _main(parser, opts)
def _main(parser, opts):
diff --git a/catalyst/support.py b/catalyst/support.py
index 9cc5d751..eb0b7d14 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -65,20 +65,19 @@ def file_check(filepath, extensions=None, strict=True):
files = glob.glob("%s.*" % filepath)
# remove any false positive files
files = [x for x in files if not x.endswith(".CONTENTS") and not
x.endswith(".DIGESTS")]
- if len(files) is 1:
+ if len(files) == 1:
return files[0]
- elif len(files) > 1 and strict:
+ if len(files) > 1 and strict:
msg = "Ambiguos Filename: %s\nPlease specify the correct
extension as well" % filepath
raise CatalystError(msg, print_traceback=False)
- else:
- target_file = None
- for ext in extensions:
- target = filepath + "." + ext
- if target in files:
- target_file = target
- break
- if target_file:
- return target_file
+ target_file = None
+ for ext in extensions:
+ target = filepath + "." + ext
+ if target in files:
+ target_file = target
+ break
+ if target_file:
+ return target_file
raise CatalystError("File Not Found: %s" % filepath)
@@ -90,7 +89,7 @@ def file_locate(settings,filelist,expand=1):
#filenames such as cdtar are optional, so we don't
assume the variable is defined.
pass
else:
- if len(settings[myfile])==0:
+ if not settings[myfile]:
raise CatalystError("File variable \"" + myfile
+
"\" has a length of zero (not
specified.)", print_traceback=True)
if settings[myfile][0]=="/":
diff --git a/catalyst/targets/stage1.py b/catalyst/targets/stage1.py
index ca6c1e0d..d40d4ffe 100644
--- a/catalyst/targets/stage1.py
+++ b/catalyst/targets/stage1.py
@@ -3,10 +3,6 @@ stage1 target
"""
# NOTE: That^^ docstring has influence catalyst-spec(5) man page generation.
-import os
-
-from snakeoil import fileutils
-
from catalyst import log
from catalyst.support import normpath
from catalyst.fileops import ensure_dirs, move_path
@@ -106,7 +102,6 @@ class stage1(StageBase):
else:
self.settings["action_sequence"].append("remove_autoresume")
self.settings["action_sequence"].append("remove_chroot")
- return
def clean_stage1(self):
diff --git a/targets/stage1/build.py b/targets/stage1/build.py
index 069d8d32..b95b4182 100755
--- a/targets/stage1/build.py
+++ b/targets/stage1/build.py
@@ -22,10 +22,10 @@ buildpkgs = scan_profile("packages.build")
# we replace the buildpkg item with the one in the
# system profile (it may have <,>,=,etc... operators
# and version numbers)
-for idx in range(0, len(pkgs)):
+for pkg in pkgs:
try:
- bidx = buildpkgs.index(portage.dep_getkey(pkgs[idx]))
- buildpkgs[bidx] = pkgs[idx]
+ bidx = buildpkgs.index(portage.dep_getkey(pkg))
+ buildpkgs[bidx] = pkg
if buildpkgs[bidx][0:1] == "*":
buildpkgs[bidx] = buildpkgs[bidx][1:]
except Exception: