diff mbox series

[swugenerator,03/13] Fix logging functions

Message ID 20230110181237.410579-4-colin.mcallister@garmin.com
State Accepted
Headers show
Series Refactoring Python code | expand

Commit Message

McAllister, Colin Jan. 10, 2023, 6:12 p.m. UTC
From: Colin McAllister <colinmca242@gmail.com>

When using python's built-in logging module the string should be formatted as if with string.format() instead of concatenating strings with values. This fixes Pylint error W1201.

Signed-off-by: Colin McAllister <colinmca242@gmail.com>
---
 swugenerator/generator.py | 15 +++++++--------
 swugenerator/main.py      |  6 +++---
 swugenerator/swu_sign.py  |  2 +-
 3 files changed, 11 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/swugenerator/generator.py b/swugenerator/generator.py
index 4598a02..2ce37a5 100644
--- a/swugenerator/generator.py
+++ b/swugenerator/generator.py
@@ -70,10 +70,10 @@  class SWUGenerator:
                 new = image
                 break
         if not new:
-            logging.debug("New artifact  %s" % entry["filename"])
+            logging.debug("New artifact  %s", entry["filename"])
             new = Artifact(entry["filename"])
             if not new.findfile(self.artifactory):
-                logging.critical("Artifact %s not found" % entry["filename"])
+                logging.critical("Artifact %s not found", entry["filename"])
                 exit(22)
 
             new.newfilename = entry["filename"]
@@ -83,7 +83,7 @@  class SWUGenerator:
                 if cmp == True:
                     cmp = "zlib"
                 if cmp != "zlib" and cmp != "zstd":
-                    logging.critical("Wrong compression algorithm: %s" % cmp)
+                    logging.critical("Wrong compression algorithm: %s", cmp)
                     exit(1)
 
                 new_path = os.path.join(self.temp.name, new.newfilename) + "." + cmp
@@ -116,7 +116,7 @@  class SWUGenerator:
                     subprocess.run(" ".join(cmd), shell=True, check=True, text=True)
                 except:
                     logging.critical(
-                        "Cannot compress %s with %s" % (entry["filename"], cmd)
+                        "Cannot compress %s with %s", entry["filename"], cmd
                     )
                     exit(1)
 
@@ -126,8 +126,7 @@  class SWUGenerator:
             if "encrypted" in entry and not self.noencrypt:
                 if not self.aeskey:
                     logging.critical(
-                        "%s must be encrypted, but no encryption key is given"
-                        % entry["filename"]
+                        "%s must be encrypted, but no encryption key is given", entry["filename"]
                     )
                 if self.noivt:
                     iv = self.aesiv
@@ -144,7 +143,7 @@  class SWUGenerator:
 
             self.artifacts.append(new)
         else:
-            logging.debug("Artifact  %s already stored" % entry["filename"])
+            logging.debug("Artifact  %s already stored", entry["filename"])
 
         entry["filename"] = new.newfilename
         entry["sha256"] = new.getsha256()
@@ -159,7 +158,7 @@  class SWUGenerator:
                 for t in val:
                     self.find_files_in_swdesc(t)
             else:
-                logging.debug("%s = %s" % (n, val))
+                logging.debug("%s = %s", n, val)
                 if n == "filename":
                     self.filelist.append(first)
 
diff --git a/swugenerator/main.py b/swugenerator/main.py
index 0a64910..260c813 100644
--- a/swugenerator/main.py
+++ b/swugenerator/main.py
@@ -21,7 +21,7 @@  def extract_keys(keyfile):
         with open(keyfile, "r") as f:
             lines = f.readlines()
     except IOError:
-        logging.fatal("Failed to open file with keys %s" % (keyfile))
+        logging.fatal("Failed to open file with keys %s", keyfile)
         exit(1)
 
     key, iv = None, None
@@ -150,14 +150,14 @@  def main() -> None:
     # Read configuration file if any
     vars = {}
     if args.config and args.config != "":
-        logging.info("Reading configuration file %s" % args.config)
+        logging.info("Reading configuration file %s", args.config)
 
         with codecs.open(args.config, "r", "utf-8") as f:
             config = libconf.load(f)
             for key, keydict in config.items():
                 if key == "variables":
                     for varname, varvalue in keydict.items():
-                        logging.debug("VAR = %s VAL = %s" % (varname, varvalue))
+                        logging.debug("VAR = %s VAL = %s", varname, varvalue)
                         vars[varname] = varvalue
             f.close()
 
diff --git a/swugenerator/swu_sign.py b/swugenerator/swu_sign.py
index 1ec9473..1d8d77b 100644
--- a/swugenerator/swu_sign.py
+++ b/swugenerator/swu_sign.py
@@ -29,7 +29,7 @@  class SWUSign:
             subprocess.run(" ".join(self.signcmd), shell=True, check=True, text=True)
         except:
             logging.critical(
-                "SWU cannot be signed, signing command was %s" % self.signcmd
+                "SWU cannot be signed, signing command was %s", self.signcmd
             )
             exit(1)