[virt-tools-list] [virt-manager] [PATCH 3/5] pylint: Resolve logging-not-lazy

Radostin Stoyanov rstoyanov1 at gmail.com
Fri Mar 2 08:01:23 UTC 2018


A new Python checker was added to warn about using a + operator inside
call of logging methods when one of the operands is a literal string.

https://pylint.readthedocs.io/en/latest/whatsnew/1.8.html

Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 tests/clitest.py           | 2 +-
 virtManager/addhardware.py | 4 ++--
 virtManager/clone.py       | 2 +-
 virtManager/connectauth.py | 2 +-
 virtManager/connection.py  | 4 ++--
 virtinst/installer.py      | 2 +-
 virtinst/interface.py      | 4 ++--
 virtinst/storage.py        | 4 ++--
 virtinst/urlfetcher.py     | 6 +++---
 9 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/tests/clitest.py b/tests/clitest.py
index 337bdb97..9177f7c4 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -194,7 +194,7 @@ class Command(object):
 
             code, output = self._launch_command(conn)
 
-            logging.debug(output + "\n")
+            logging.debug("%s\n", output)
             return code, output
         except Exception as e:
             return (-1, "".join(traceback.format_exc()) + str(e))
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 863cb3cd..208538d4 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -1290,8 +1290,8 @@ class vmmAddHardware(vmmGObjectUI):
 
 
     def _add_device(self):
-        self._dev.get_xml_config()
-        logging.debug("Adding device:\n" + self._dev.get_xml_config())
+        xml = self._dev.get_xml_config()
+        logging.debug("Adding device:\n%s", xml)
 
         if self._remove_usb_controller:
             kwargs = {}
diff --git a/virtManager/clone.py b/virtManager/clone.py
index 02a860d0..df7ac4f8 100644
--- a/virtManager/clone.py
+++ b/virtManager/clone.py
@@ -470,7 +470,7 @@ class vmmCloneVM(vmmGObjectUI):
                 newpath = self.generate_clone_path_name(origpath, newname)
                 row[STORAGE_INFO_NEW_PATH] = newpath
             except Exception as e:
-                logging.debug("Generating new path from clone name failed: " +
+                logging.debug("Generating new path from clone name failed: %s",
                               str(e))
 
     def build_storage_entry(self, disk, storage_box):
diff --git a/virtManager/connectauth.py b/virtManager/connectauth.py
index 50047ac7..d959c870 100644
--- a/virtManager/connectauth.py
+++ b/virtManager/connectauth.py
@@ -162,6 +162,6 @@ def acquire_tgt():
                                 "org.freedesktop.KrbAuthDialog", None)
         ret = ka.acquireTgt("(s)", "")
     except Exception as e:
-        logging.info("Cannot acquire tgt" + str(e))
+        logging.info("Cannot acquire tgt %s", str(e))
         ret = False
     return ret
diff --git a/virtManager/connection.py b/virtManager/connection.py
index c05fb58d..6ea1b595 100644
--- a/virtManager/connection.py
+++ b/virtManager/connection.py
@@ -1014,8 +1014,8 @@ class vmmConnection(vmmGObject):
 
         self._change_state(self._STATE_CONNECTING)
 
-        logging.debug("Scheduling background open thread for " +
-                     self.get_uri())
+        logging.debug("Scheduling background open thread for %s",
+                      self.get_uri())
         self._start_thread(self._open_thread, "Connect %s" % self.get_uri())
 
     def _do_creds_password(self, creds):
diff --git a/virtinst/installer.py b/virtinst/installer.py
index f6145c07..1d85290d 100644
--- a/virtinst/installer.py
+++ b/virtinst/installer.py
@@ -182,7 +182,7 @@ class Installer(object):
         Remove any temporary files retrieved during installation
         """
         for f in self._tmpfiles:
-            logging.debug("Removing " + f)
+            logging.debug("Removing %s", str(f))
             os.unlink(f)
 
         for vol in self._tmpvols:
diff --git a/virtinst/interface.py b/virtinst/interface.py
index 03783f83..236f651d 100644
--- a/virtinst/interface.py
+++ b/virtinst/interface.py
@@ -247,8 +247,8 @@ class Interface(XMLBuilder):
             try:
                 iface.undefine()
             except Exception as e:
-                logging.debug("Error cleaning up interface after failure: " +
-                              "%s" % str(e))
+                logging.debug("Error cleaning up interface after failure: %s",
+                              str(e))
             raise RuntimeError(errmsg)
 
         return iface
diff --git a/virtinst/storage.py b/virtinst/storage.py
index df6f601d..537a3d46 100644
--- a/virtinst/storage.py
+++ b/virtinst/storage.py
@@ -540,8 +540,8 @@ class StoragePool(_StorageObject):
             try:
                 pool.undefine()
             except Exception as e:
-                logging.debug("Error cleaning up pool after failure: " +
-                              "%s" % str(e))
+                logging.debug("Error cleaning up pool after failure: %s",
+                              str(e))
             raise RuntimeError(errmsg)
 
         self.conn.cache_new_pool(pool)
diff --git a/virtinst/urlfetcher.py b/virtinst/urlfetcher.py
index 495c3f6a..69c152a8 100644
--- a/virtinst/urlfetcher.py
+++ b/virtinst/urlfetcher.py
@@ -161,7 +161,7 @@ class _URLFetcher(object):
             fn = fileobj.name
 
         self._grabURL(filename, fileobj)
-        logging.debug("Saved file to " + fn)
+        logging.debug("Saved file to %s", fn)
         return fn
 
     def acquireFileContent(self, filename):
@@ -300,7 +300,7 @@ class _MountedURLFetcher(_LocalURLFetcher):
                                            dir=self.scratchdir)
         mountcmd = "/bin/mount"
 
-        logging.debug("Preparing mount at " + self._srcdir)
+        logging.debug("Preparing mount at %s", self._srcdir)
         cmd = [mountcmd, "-o", "ro", self.location[4:], self._srcdir]
 
         logging.debug("mount cmd: %s", cmd)
@@ -317,7 +317,7 @@ class _MountedURLFetcher(_LocalURLFetcher):
         if not self._mounted:
             return
 
-        logging.debug("Cleaning up mount at " + self._srcdir)
+        logging.debug("Cleaning up mount at %s", self._srcdir)
         try:
             if not self._in_test_suite:
                 cmd = ["/bin/umount", self._srcdir]
-- 
2.14.3




More information about the virt-tools-list mailing list