[master 1/17] Clean up some pylint warnings

bcl installerbot-noreply at redhat.com
Tue May 12 00:14:07 UTC 2015


From: "Brian C. Lane" <bcl at redhat.com>

Mostly logging, using .format() on the strings.
---
 .gitignore                 |  1 +
 docs/conf.py               |  2 +-
 src/bin/image-minimizer    |  3 ---
 src/pylorax/__init__.py    | 13 ++++++-------
 src/pylorax/imgutils.py    |  4 ++--
 src/pylorax/ltmpl.py       |  2 +-
 src/sbin/livemedia-creator | 32 ++++++++++++++++----------------
 src/sbin/lorax             |  4 ++--
 8 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9b92808..70111ab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 *.pyc
 src/pylorax/version.py*
 _build/
+tests/pylint/.pylint.d/
diff --git a/docs/conf.py b/docs/conf.py
index 395f4c2..41183d0 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -50,7 +50,7 @@
 
 # General information about the project.
 project = u'Lorax'
-copyright = u'2015, Red Hat, Inc.'
+copyright = u'2015, Red Hat, Inc.'      # pylint: disable=redefined-builtin
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
diff --git a/src/bin/image-minimizer b/src/bin/image-minimizer
index 42f8077..8c37ab4 100755
--- a/src/bin/image-minimizer
+++ b/src/bin/image-minimizer
@@ -192,9 +192,6 @@ def main():
         sys.exit(e.code)
     except KeyboardInterrupt, e:
         print >> sys.stderr, "Aborted at user request"
-    except Exception, e:
-        print e
-        sys.exit(1)
 
 if __name__ == "__main__":
     main()
diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
index 3d74a4b..72d55c8 100644
--- a/src/pylorax/__init__.py
+++ b/src/pylorax/__init__.py
@@ -190,15 +190,15 @@ def run(self, dbo, product, version, release, variant="", bugurl="",
         self.init_stream_logging()
         self.init_file_logging(logdir)
 
-        logger.debug("version is {0}".format(vernum))
-        logger.debug("using work directory {0.workdir}".format(self))
-        logger.debug("using log directory {0}".format(logdir))
+        logger.debug("version is %s", vernum)
+        logger.debug("using work directory %s", self.workdir)
+        logger.debug("using log directory %s", logdir)
 
         # set up output directory
         self.outputdir = outputdir or tempfile.mkdtemp(prefix="pylorax.out.")
         if not os.path.isdir(self.outputdir):
             os.makedirs(self.outputdir)
-        logger.debug("using output directory {0.outputdir}".format(self))
+        logger.debug("using output directory %s", self.outputdir)
 
         # do we have root privileges?
         logger.info("checking for root privileges")
@@ -228,7 +228,7 @@ def run(self, dbo, product, version, release, variant="", bugurl="",
             logger.critical("no dnf base object")
             sys.exit(1)
         self.inroot = dbo.conf.installroot
-        logger.debug("using install root: {0}".format(self.inroot))
+        logger.debug("using install root: %s", self.inroot)
 
         if not buildarch:
             buildarch = get_buildarch(dbo)
@@ -246,8 +246,7 @@ def run(self, dbo, product, version, release, variant="", bugurl="",
 
         # NOTE: if you change isolabel, you need to change pungi to match, or
         # the pungi images won't boot.
-        isolabel = volid or "{0.name}-{0.version}-{1.basearch}".format(self.product,
-                                                                       self.arch)
+        isolabel = volid or "%s-%s-%s" % (product, version, self.arch.basearch)
 
         if len(isolabel) > 32:
             logger.fatal("the volume id cannot be longer than 32 characters")
diff --git a/src/pylorax/imgutils.py b/src/pylorax/imgutils.py
index 232d91f..1617ca8 100644
--- a/src/pylorax/imgutils.py
+++ b/src/pylorax/imgutils.py
@@ -352,9 +352,9 @@ def __enter__(self):
             except CalledProcessError:
                 logger.debug(traceback.format_exc())
         if self.mount_dir:
-            logger.info("Partition mounted on {0} size={1}".format(self.mount_dir, self.mount_size))
+            logger.info("Partition mounted on %s size=%s", self.mount_dir, self.mount_size)
         else:
-            logger.debug("Unable to mount anything from {0}".format(self.disk_img))
+            logger.debug("Unable to mount anything from %s", self.disk_img)
             os.rmdir(mount_dir)
         return self
 
diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
index 6a0d50c..117efd3 100644
--- a/src/pylorax/ltmpl.py
+++ b/src/pylorax/ltmpl.py
@@ -186,7 +186,7 @@ def _getsize(self, *files):
     def run(self, templatefile, **variables):
         for k,v in self.defaults.items() + self.builtins.items():
             variables.setdefault(k,v)
-        logger.debug("executing {0} with variables={1}".format(templatefile, variables))
+        logger.debug("executing %s with variables=%s", templatefile, variables)
         self.templatefile = templatefile
         t = LoraxTemplate(directories=[self.templatedir])
         commands = t.parse(templatefile, variables)
diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator
index 438d6b6..e60e091 100755
--- a/src/sbin/livemedia-creator
+++ b/src/sbin/livemedia-creator
@@ -128,7 +128,7 @@ class LogRequestHandler(SocketServer.BaseRequestHandler):
 
             except socket.timeout:
                 pass
-            except:
+            except Exception:       # pylint: disable=broad-except
                 break
 
     def finish(self):
@@ -434,7 +434,7 @@ class VirtualInstall(object):
 
         Could use libvirt for this instead.
         """
-        log.info("Shutting down {0}".format(self.virt_name))
+        log.info("Shutting down %s", self.virt_name)
         subprocess.call(["virsh", "destroy", self.virt_name])
         subprocess.call(["virsh", "undefine", self.virt_name])
 
@@ -503,12 +503,12 @@ def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
     if not (disk_img and template and outfile):
         return None
 
-    log.info("Creating appliance definition using {0}".format(template))
+    log.info("Creating appliance definition using %s", template)
 
     if not arch:
         arch = "x86_64"
 
-    log.info("Calculating SHA256 checksum of {0}".format(disk_img))
+    log.info("Calculating SHA256 checksum of %s", disk_img)
     sha256 = hashlib.sha256()
     with open(disk_img) as f:
         while True:
@@ -516,7 +516,7 @@ def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
             if not data:
                 break
             sha256.update(data)
-    log.info("SHA256 of {0} is {1}".format(disk_img, sha256.hexdigest()))
+    log.info("SHA256 of %s is %s", disk_img, sha256.hexdigest())
     disk_info = DataHolder(name=os.path.basename(disk_img), format="raw",
                            checksum_type="sha256", checksum=sha256.hexdigest())
     try:
@@ -596,7 +596,7 @@ def rebuild_initrds_for_live(opts, sys_root_dir, results_dir):
         dracut_args = []
         for arg in opts.dracut_args:
             dracut_args += arg.split(" ", 1)
-    log.info("dracut args = {0}".format(dracut_args))
+    log.info("dracut args = %s", dracut_args)
 
     dracut = ["dracut", "--nomdadmconf", "--nolvmconf"] + dracut_args
 
@@ -729,7 +729,7 @@ def make_livecd(opts, mount_dir, work_dir):
         dracut_args = []
         for arg in opts.dracut_args:
             dracut_args += arg.split(" ", 1)
-    log.info("dracut args = {0}".format(dracut_args))
+    log.info("dracut args = %s", dracut_args)
     tb.rebuild_initrds(add_args=dracut_args)
     log.info("Building boot.iso")
     tb.build()
@@ -874,8 +874,8 @@ def novirt_install(opts, disk_img, disk_size, repo_url):
         if not os.path.isdir(log_anaconda):
             os.mkdir(log_anaconda)
         for l in glob.glob("/tmp/*log")+glob.glob("/tmp/anaconda-tb-*"):
-                shutil.copy2(l, log_anaconda)
-                os.unlink(l)
+            shutil.copy2(l, log_anaconda)
+            os.unlink(l)
 
         if opts.make_iso or opts.make_fsimage:
             umount(ROOT_PATH)
@@ -1056,7 +1056,7 @@ def make_image(opts, ks):
 
             virt_install(opts, install_log, disk_img, disk_size)
     except InstallError as e:
-        log.error("Install failed: {0}".format(e))
+        log.error("Install failed: %s", e)
         if not opts.keep_image and os.path.exists(disk_img):
             log.info("Removing bad disk image")
             os.unlink(disk_img)
@@ -1436,7 +1436,7 @@ def main():
         result_dir = None
         if opts.make_iso:
             work_dir = tempfile.mkdtemp()
-            log.info("working dir is {0}".format(work_dir))
+            log.info("working dir is %s", work_dir)
 
             if (opts.fs_image or opts.no_virt) and not opts.disk_image:
                 # Create iso from a filesystem image
@@ -1469,7 +1469,7 @@ def main():
                            opts.vcpus, opts.arch, opts.title, opts.project, opts.releasever)
         elif opts.make_pxe_live:
             work_dir = tempfile.mkdtemp()
-            log.info("working dir is {0}".format(work_dir))
+            log.info("working dir is %s", work_dir)
 
             if (opts.fs_image or opts.no_virt) and not opts.disk_image:
                 # Create pxe live images from a filesystem image
@@ -1503,12 +1503,12 @@ def main():
 
     log.info("SUMMARY")
     log.info("-------")
-    log.info("Logs are in {0}".format(os.path.abspath(os.path.dirname(opts.logfile))))
+    log.info("Logs are in %s", os.path.abspath(os.path.dirname(opts.logfile)))
     if disk_img:
-        log.info("Disk image is at {0}".format(disk_img))
+        log.info("Disk image is at %s", disk_img)
     if opts.make_appliance:
-        log.info("Appliance description is in {0}".format(opts.app_file))
-    log.info("Results are in {0}".format(opts.result_dir))
+        log.info("Appliance description is in %s", opts.app_file)
+    log.info("Results are in %s", opts.result_dir)
 
     sys.exit( 0 )
 
diff --git a/src/sbin/lorax b/src/sbin/lorax
index bd07bb3..7870d2b 100755
--- a/src/sbin/lorax
+++ b/src/sbin/lorax
@@ -307,7 +307,7 @@ def get_dnf_base_object(installroot, repositories, mirrorlists=None,
     # add the repositories
     for i, r in enumerate(repositories):
         if "SRPM" in r or "srpm" in r:
-            log.info("Skipping source repo: %s" % r)
+            log.info("Skipping source repo: %s", r)
             continue
         repo_name = "lorax-repo-%d" % i
         repo = dnf.repo.Repo(repo_name, cachedir)
@@ -327,7 +327,7 @@ def get_dnf_base_object(installroot, repositories, mirrorlists=None,
     # add the mirrorlists
     for i, r in enumerate(mirrorlists):
         if "SRPM" in r or "srpm" in r:
-            log.info("Skipping source repo: %s" % r)
+            log.info("Skipping source repo: %s", r)
             continue
         repo_name = "lorax-mirrorlist-%d" % i
         repo = dnf.repo.Repo(repo_name, cachedir)


-- 
To view this commit on github, visit https://github.com/rhinstaller/lorax/commit/d069f84015f1b3325d8e26157d33c465fb6bc019


More information about the anaconda-patches mailing list