From 1a0644d05c8eadeb6aee860065278a3c58e629f5 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Fri, 21 Jun 2024 03:24:44 +0200 Subject: [PATCH] Add missing UTF-8 encodings --- bin/compile.py | 2 +- npbackup/core/runner.py | 2 +- npbackup/core/upgrade_runner.py | 4 ++-- npbackup/task.py | 2 +- resources/update_custom_resources.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/compile.py b/bin/compile.py index f893720..cb12c91 100644 --- a/bin/compile.py +++ b/bin/compile.py @@ -316,7 +316,7 @@ def compile(arch: str, audience: str, build_type: str, onefile: bool): errors = True ## Create version file - with open(os.path.join(BUILDS_DIR, audience, "VERSION"), "w") as fh: + with open(os.path.join(BUILDS_DIR, audience, "VERSION"), "w", encoding="utf-8") as fh: fh.write(npbackup_version) print(f"COMPILED {'WITH SUCCESS' if not errors else 'WITH ERRORS'}") if not onefile: diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index 451f2b0..9549239 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -151,7 +151,7 @@ def metric_writer( else: try: # We use append so if prometheus text collector did not get data yet, we'll not wipe it - with open(destination, "a") as file_handle: + with open(destination, "a", encoding="utf-8") as file_handle: for metric in metrics: file_handle.write(metric + "\n") except OSError as exc: diff --git a/npbackup/core/upgrade_runner.py b/npbackup/core/upgrade_runner.py index 7bea344..3744c1a 100644 --- a/npbackup/core/upgrade_runner.py +++ b/npbackup/core/upgrade_runner.py @@ -37,7 +37,7 @@ def need_upgrade(upgrade_interval: int) -> bool: def _write_count(file: str, count: int) -> bool: try: - with open(file, "w") as fpw: + with open(file, "w", encoding="utf-8") as fpw: fpw.write(str(count)) return True except OSError: @@ -46,7 +46,7 @@ def need_upgrade(upgrade_interval: int) -> bool: def _get_count(file: str) -> Optional[int]: try: - with open(file, "r") as fpr: + with open(file, "r", encoding="utf-8") as fpr: count = int(fpr.read()) return count except OSError: diff --git a/npbackup/task.py b/npbackup/task.py index d019010..c2c07c1 100644 --- a/npbackup/task.py +++ b/npbackup/task.py @@ -122,7 +122,7 @@ def create_scheduled_task_unix( f'{trigger} cd "{executable_dir}" && {cli_executable_path} {TASK_ARGS}\n' ) try: - with open(cron_file, "w") as file_handle: + with open(cron_file, "w", encoding="utf-8") as file_handle: file_handle.write(crontab_entry) except OSError as exc: logger.error("Could not write to file {}: {}".format(cron_file, exc)) diff --git a/resources/update_custom_resources.py b/resources/update_custom_resources.py index c5f1ad0..9ae0c75 100644 --- a/resources/update_custom_resources.py +++ b/resources/update_custom_resources.py @@ -50,7 +50,7 @@ def update_custom_icons(): resources_dir = os.path.join(BASEDIR, os.path.pardir, 'resources') customization_py = os.path.join(resources_dir, 'customization.py') - with open(customization_py, 'r') as f: + with open(customization_py, 'r', encoding="utf-8") as f: customization = f.read() for var_name, file in custom_resources.items(): file_path = os.path.join(resources_dir, file) @@ -61,7 +61,7 @@ def update_custom_icons(): customization = re.sub(f'{var_name} = b".*"', f'{var_name} = b"{encoded_b64}"', customization) else: print("No file found for", var_name) - with open(customization_py, 'w') as f: + with open(customization_py, 'w', encoding="utf-8") as f: f.write(customization) if __name__ == '__main__':