From db04c7132c9340cf6c4c9ba12214e0a6efd82666 Mon Sep 17 00:00:00 2001 From: Velichka Atanasova Date: Wed, 14 Jul 2021 15:12:12 +0300 Subject: [PATCH] Use %-style formatting in logging Replacing the f-strings in logging with %-style formatted strings. Signed-off-by: Velichka Atanasova --- tuf/ngclient/updater.py | 42 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/tuf/ngclient/updater.py b/tuf/ngclient/updater.py index de3af53cff..99e596e16b 100644 --- a/tuf/ngclient/updater.py +++ b/tuf/ngclient/updater.py @@ -327,8 +327,7 @@ def _preorder_depth_first_walk(self, target_filepath) -> Dict: self._load_targets(role_name, parent_role) # Skip any visited current role to prevent cycles. if (role_name, parent_role) in visited_role_names: - msg = f"Skipping visited current role {role_name}" - logger.debug(msg) + logger.debug("Skipping visited current role %s", role_name) continue # The metadata for 'role_name' must be downloaded/updated before @@ -357,11 +356,11 @@ def _preorder_depth_first_walk(self, target_filepath) -> Dict: ) if child_role.terminating and child_role_name is not None: - msg = ( - f"Adding child role {child_role_name}.\n", + logger.debug( + "Adding child role %s.\n" "Not backtracking to other roles.", + child_role_name, ) - logger.debug(msg) role_names = [] child_roles_to_visit.append( (child_role_name, role_name) @@ -369,12 +368,10 @@ def _preorder_depth_first_walk(self, target_filepath) -> Dict: break if child_role_name is None: - msg = f"Skipping child role {child_role_name}" - logger.debug(msg) + logger.debug("Skipping child role %s", child_role_name) else: - msg = f"Adding child role {child_role_name}" - logger.debug(msg) + logger.debug("Adding child role %s", child_role_name) child_roles_to_visit.append( (child_role_name, role_name) ) @@ -386,19 +383,19 @@ def _preorder_depth_first_walk(self, target_filepath) -> Dict: role_names.extend(child_roles_to_visit) else: - msg = f"Found target in current role {role_name}" - logger.debug(msg) + logger.debug("Found target in current role %s", role_name) if ( target is None and number_of_delegations == 0 and len(role_names) > 0 ): - msg = ( - f"{len(role_names)} roles left to visit, but allowed to ", - f"visit at most {self.config.max_delegations} delegations.", + logger.debug( + "%d roles left to visit, but allowed to " + "visit at most %d delegations.", + len(role_names), + self.config.max_delegations, ) - logger.debug(msg) return {"filepath": target_filepath, "fileinfo": target} @@ -471,19 +468,18 @@ def _visit_child_role(child_role: Dict, target_filepath: str) -> str: target_filepath.lstrip(os.sep), child_role_path.lstrip(os.sep) ): logger.debug( - "Child role " - + repr(child_role_name) - + " is allowed to sign for " - + repr(target_filepath) + "Child role %s is allowed to sign for %s", + repr(child_role_name), + repr(target_filepath), ) return child_role_name logger.debug( - "The given target path " - + repr(target_filepath) - + " does not match the trusted path or glob pattern: " - + repr(child_role_path) + "The given target path %s " + "does not match the trusted path or glob pattern: %s", + repr(target_filepath), + repr(child_role_path), ) continue