From 3397e0ce0198586b4053dc4b533e1c99670643df Mon Sep 17 00:00:00 2001 From: Pami Ketolainen Date: Thu, 11 Jan 2024 12:04:54 +0200 Subject: [PATCH 1/2] Remove unused import and variable, and trailing whitespace --- main.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 803fb7e..0361f7d 100755 --- a/main.py +++ b/main.py @@ -3,7 +3,6 @@ import subprocess import getpass import time -import pdb import configparser import sys import logging @@ -46,7 +45,7 @@ def refresh_repos(): logging.warning("An error occured while refreshing repos. See output below.") print(err.output) output = err.output - + return output def list_patches(): @@ -57,7 +56,7 @@ def list_patches(): logging.warning("An error occured while listing patches. See output below.") print(err.output) output = err.output - + return output def install_patches(categories, with_interactive): @@ -96,7 +95,7 @@ def install_patches(categories, with_interactive): else: logging.warning("An error occured while installing patches. See output below.") print(err.output) - + return output def send_email(content, subject, email_to): @@ -123,17 +122,15 @@ def compose_body(time_start, refresh_output, install_output, list_output): outputs = {'refresh_output': refresh_output, 'install_output': install_output, 'list_output': list_output} - + # Convert bytes to strings if needed. for key, value in outputs.items(): if type(value) is bytes: outputs[key] = str(value, 'utf-8') - - head = f"JOB STARTED: {time_start}" - + # Combine outputs to create body of message. body = "\n".join(outputs.values()) - + return body if __name__ == "__main__": From 297a5bdc275b44ded72f26a86721c2a63434b363 Mon Sep 17 00:00:00 2001 From: Pami Ketolainen Date: Thu, 11 Jan 2024 12:12:40 +0200 Subject: [PATCH 2/2] Fix comparison warnings It is recommended to test for None with indentity comparision 'is', and object types with isinstance(). --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 0361f7d..433d2c9 100755 --- a/main.py +++ b/main.py @@ -115,7 +115,7 @@ def send_telegram(content, token, chat_id): return r def compose_body(time_start, refresh_output, install_output, list_output): - if install_output == None: + if install_output is None: outputs = {'refresh_output': refresh_output, 'list_output': list_output} else: @@ -125,7 +125,7 @@ def compose_body(time_start, refresh_output, install_output, list_output): # Convert bytes to strings if needed. for key, value in outputs.items(): - if type(value) is bytes: + if isinstance(value, bytes): outputs[key] = str(value, 'utf-8') # Combine outputs to create body of message.