From b720b746492214d4cf6f49bf92324f3f79cd6c7a Mon Sep 17 00:00:00 2001 From: deajan Date: Mon, 16 Jun 2025 11:51:07 +0200 Subject: [PATCH] Make linter happy --- npbackup/__debug__.py | 2 +- npbackup/__env__.py | 2 +- npbackup/__main__.py | 8 ++++---- npbackup/configuration.py | 7 +++---- npbackup/core/metrics.py | 12 ++++++------ npbackup/core/runner.py | 10 +++++----- npbackup/core/upgrade_runner.py | 1 - npbackup/gui/config.py | 9 ++++----- npbackup/key_management.py | 2 +- npbackup/restic_metrics/__init__.py | 4 ++-- npbackup/restic_wrapper/__init__.py | 5 ++--- npbackup/runner_interface.py | 2 ++ npbackup/windows/sign_windows.py | 2 +- 13 files changed, 32 insertions(+), 34 deletions(-) diff --git a/npbackup/__debug__.py b/npbackup/__debug__.py index 6f4fd3e..f65aa46 100644 --- a/npbackup/__debug__.py +++ b/npbackup/__debug__.py @@ -35,7 +35,7 @@ if not __SPECIAL_DEBUG_STRING: sys.argv.pop(sys.argv.index("--debug")) -if not "_DEBUG" in globals(): +if "_DEBUG" not in globals(): _DEBUG = False if __SPECIAL_DEBUG_STRING: if __debug_os_env == __SPECIAL_DEBUG_STRING: diff --git a/npbackup/__env__.py b/npbackup/__env__.py index 5e1dae7..3b75b04 100644 --- a/npbackup/__env__.py +++ b/npbackup/__env__.py @@ -37,7 +37,7 @@ UPGRADE_DEFER_TIME = 60 # Maximum allowed time offset in seconds to allow policy operations to run MAX_ALLOWED_NTP_OFFSET = 600.0 -if not "BUILD_TYPE" in globals(): +if "BUILD_TYPE" not in globals(): BUILD_TYPE = "UnknownBuildType" diff --git a/npbackup/__main__.py b/npbackup/__main__.py index 3a59775..1b5901e 100644 --- a/npbackup/__main__.py +++ b/npbackup/__main__.py @@ -387,9 +387,6 @@ This is free software, and you are welcome to redistribute it under certain cond else: sys.exit(1) - if args.verbose: - _VERBOSE = True - if args.config_file: if not os.path.isfile(args.config_file): msg = f"Config file {args.config_file} cannot be read or does not exist" @@ -630,6 +627,9 @@ This is free software, and you are welcome to redistribute it under certain cond # On group operations, we also need to set op_args + if args.verbose: + cli_args["verbose"] = True + if args.stdin: cli_args["operation"] = "backup" cli_args["op_args"] = { @@ -736,7 +736,7 @@ This is free software, and you are welcome to redistribute it under certain cond elif args.init: cli_args["operation"] = "init" - #### Group operation mode + # Group operation mode possible_group_ops = ( "backup", "restore", diff --git a/npbackup/configuration.py b/npbackup/configuration.py index e34be20..920387b 100644 --- a/npbackup/configuration.py +++ b/npbackup/configuration.py @@ -29,10 +29,9 @@ from ofunctions.random import random_string from ofunctions.misc import replace_in_iterable, BytesConverter, iter_over_keys from resources.customization import ID_STRING from npbackup.key_management import AES_KEY, EARLIER_AES_KEY, IS_PRIV_BUILD, get_aes_key - +from npbackup.__version__ import __version__ as MAX_CONF_VERSION MIN_CONF_VERSION = "3.0" -from npbackup.__version__ import __version__ as MAX_CONF_VERSION sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))) @@ -891,13 +890,13 @@ def load_config(config_file: Path) -> Optional[dict]: full_config = crypt_config( full_config, AES_KEY, ENCRYPTED_OPTIONS, operation="decrypt" ) - if full_config == False: + if full_config is False: if EARLIER_AES_KEY: logger.warning("Trying to migrate encryption key") full_config = crypt_config( full_config, EARLIER_AES_KEY, ENCRYPTED_OPTIONS, operation="decrypt" ) - if full_config == False: + if full_config is False: msg = "Cannot decrypt config file. Looks like our keys don't match." logger.critical(msg) raise EnvironmentError(msg) diff --git a/npbackup/core/metrics.py b/npbackup/core/metrics.py index 52b27d6..948a23a 100644 --- a/npbackup/core/metrics.py +++ b/npbackup/core/metrics.py @@ -22,7 +22,7 @@ from npbackup.restic_metrics import ( write_metrics_file, ) from npbackup.__version__ import __intname__ as NAME, version_dict -from npbackup.__debug__ import _DEBUG, fmt_json +from npbackup.__debug__ import fmt_json from resources.customization import OEM_STRING logger = getLogger() @@ -156,10 +156,10 @@ def metric_analyser( date=date, ) except KeyError as exc: - logger.info("Metrics error: {}".format(exc)) + logger.info(f"Metrics error: {exc}") logger.debug("Trace:", exc_info=True) except OSError as exc: - logger.error("Metrics OS error: ".format(exc)) + logger.error(f"Metrics OS error: {exc}") logger.debug("Trace:", exc_info=True) return operation_success, backup_too_small @@ -185,7 +185,7 @@ def send_prometheus_metrics( ) return False except KeyError as exc: - logger.error("No prometheus configuration found in config file.") + logger.error("No prometheus configuration found in config file: {exc}") return False if destination and dry_run: @@ -194,12 +194,12 @@ def send_prometheus_metrics( logger.debug("Sending metrics to {}".format(destination)) dest = destination.lower() if dest.startswith("http"): - if not "metrics" in dest: + if "metrics" not in dest: logger.error( "Destination does not contain 'metrics' keyword. Not uploading." ) return False - if not "job" in dest: + if "job" not in dest: logger.error( "Destination does not contain 'job' keyword. Not uploading." ) diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index 6e59a5c..dc56fbd 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -486,7 +486,7 @@ class NPBackupRunner: current_permissions = self.repo_config.g("permissions") if ( current_permissions - and not current_permissions in required_permissions[operation] + and current_permissions not in required_permissions[operation] ): self.write_logs( f"Required permissions for operation '{operation}' must be one of {', '.join(required_permissions[operation])}, current permission is '{current_permissions}'", @@ -935,9 +935,9 @@ class NPBackupRunner: if self.json_output: if isinstance(result, dict): js = result - if not "additional_error_info" in js.keys(): + if "additional_error_info" not in js.keys(): js["additional_error_info"] = [] - if not "additional_warning_info" in js.keys(): + if "additional_warning_info" not in js.keys(): js["additional_warning_info"] = [] else: js = { @@ -1405,7 +1405,7 @@ class NPBackupRunner: all_files_present = self.check_source_files_present(source_type, paths) if not all_files_present: self.write_logs( - f"Not all files/folders are present in backup source", + "Not all files/folders are present in backup source", level="error", ) @@ -1508,7 +1508,7 @@ class NPBackupRunner: current_permissions = self.repo_config.g("permissions") if ( current_permissions - and not current_permissions in required_permissions[post_backup_op] + and current_permissions not in required_permissions[post_backup_op] ): self.write_logs( f"Required permissions for post backup housekeeping must be one of {', '.join(required_permissions[post_backup_op])}, current permission is '{current_permissions}'", diff --git a/npbackup/core/upgrade_runner.py b/npbackup/core/upgrade_runner.py index c2b5b96..858ef07 100644 --- a/npbackup/core/upgrade_runner.py +++ b/npbackup/core/upgrade_runner.py @@ -11,7 +11,6 @@ __build__ = "2025030701" from logging import getLogger -from random import randint from npbackup.upgrade_client.upgrader import auto_upgrader, _check_new_version import npbackup.configuration diff --git a/npbackup/gui/config.py b/npbackup/gui/config.py index f67ffa9..8599dbe 100644 --- a/npbackup/gui/config.py +++ b/npbackup/gui/config.py @@ -249,10 +249,10 @@ def config_gui(full_config: dict, config_file: str): try: if combo_value.startswith("Repo: "): object_type = "repos" - object_name = combo_value[len("Repo: ") :] + object_name = combo_value[len("Repo: "):] elif combo_value.startswith("Group: "): object_type = "groups" - object_name = combo_value[len("Group: ") :] + object_name = combo_value[len("Group: "):] else: object_type = None object_name = None @@ -635,7 +635,7 @@ def config_gui(full_config: dict, config_file: str): # First we need to clear the whole GUI to reload new values for key in window.AllKeysDict: # We only clear config keys, which have '.' separator - if "." in str(key) and not "inherited" in str(key): + if "." in str(key) and "inherited" not in str(key): if isinstance(window[key], sg.Tree): window[key].Update(sg.TreeData()) else: @@ -791,7 +791,7 @@ def config_gui(full_config: dict, config_file: str): continue if not isinstance(key, str) or ( isinstance(key, str) - and (not "." in key and not key in ("repo_uri", "repo_group")) + and ("." not in key and key not in ("repo_uri", "repo_group")) ): # Don't bother with keys that don't contain with "." since they're not in the YAML config file # but are most probably for GUI events @@ -2975,5 +2975,4 @@ Google Cloud storage: GOOGLE_PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS\n\ # Closing this window takes ages window.hide() quick_close_simplegui_window(window) - del window # noqa: F821 (undefined name) return full_config diff --git a/npbackup/key_management.py b/npbackup/key_management.py index 955ada2..c2a5594 100644 --- a/npbackup/key_management.py +++ b/npbackup/key_management.py @@ -61,7 +61,7 @@ def get_aes_key(): try: with open(key_location, "rb") as key_file: key = key_file.read() - msg = f"Encryption key file read" + msg = "Encryption key file read" except OSError as exc: msg = f"Cannot read encryption key file: {exc}" return False, msg diff --git a/npbackup/restic_metrics/__init__.py b/npbackup/restic_metrics/__init__.py index 394091c..2e2bcbe 100644 --- a/npbackup/restic_metrics/__init__.py +++ b/npbackup/restic_metrics/__init__.py @@ -171,7 +171,7 @@ def restic_str_output_to_json( matches.group(), line ) ) - except IndexError as exc: + except IndexError: logger.error("Trace:", exc_info=True) errors = True @@ -472,7 +472,7 @@ def restic_output_2_metrics(restic_result, output, labels_string=None): matches.group(), line ) ) - except IndexError as exc: + except IndexError: logger.error("Trace:", exc_info=True) errors = True diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index a3a1e52..ab874da 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -19,7 +19,6 @@ import re from datetime import datetime, timezone import dateutil.parser import queue -from functools import wraps from command_runner import command_runner from packaging.version import parse as version_parse from ofunctions.misc import BytesConverter, fn_name @@ -169,7 +168,7 @@ class ResticRunner: os.environ[encrypted_env_variable] = value # Configure default cpu usage when not specifically set - if not "GOMAXPROCS" in self.environment_variables: + if "GOMAXPROCS" not in self.environment_variables: nb_cores = os.cpu_count() if nb_cores < 2: gomaxprocs = nb_cores @@ -377,7 +376,7 @@ class ResticRunner: logger.debug(f"Skipping output filter for {self._executor_operation}") return output if not isinstance(output, str): - logger.debug(f"Skipping output filter for non str output") + logger.debug("Skipping output filter for non str output") return output for filter in restic_output_filters: output = filter.sub("", output) diff --git a/npbackup/runner_interface.py b/npbackup/runner_interface.py index f1dd3e2..170bd67 100644 --- a/npbackup/runner_interface.py +++ b/npbackup/runner_interface.py @@ -42,6 +42,7 @@ def serialize_datetime(obj): def entrypoint(*args, **kwargs): + verbose = kwargs.pop("verbose", False) repo_config = kwargs.pop("repo_config", None) json_output = kwargs.pop("json_output") operation = kwargs.pop("operation") @@ -50,6 +51,7 @@ def entrypoint(*args, **kwargs): npbackup_runner = NPBackupRunner() if repo_config: npbackup_runner.repo_config = repo_config + npbackup_runner.verbose = verbose npbackup_runner.dry_run = kwargs.pop("dry_run") npbackup_runner.verbose = kwargs.pop("verbose") npbackup_runner.live_output = not json_output diff --git a/npbackup/windows/sign_windows.py b/npbackup/windows/sign_windows.py index 13e91c2..95d2ecb 100644 --- a/npbackup/windows/sign_windows.py +++ b/npbackup/windows/sign_windows.py @@ -59,7 +59,7 @@ def get_ev_data(cert_data_path): cryptographic_provider, ) = ev_cert except Exception as exc: - print("EV Cert data is corrupt") + print("EV Cert data is corrupt: {exc}") sys.exit(1) return pkcs12_certificate, pkcs12_password, container_name, cryptographic_provider