From d25e0f28df4025e73273adc5bc08dc3dc5e5908a Mon Sep 17 00:00:00 2001 From: deajan Date: Fri, 24 Oct 2025 17:45:39 +0200 Subject: [PATCH] Reformat files with black --- RESTIC_SOURCE_FILES/update_restic.py | 6 ++-- bin/compile.py | 4 ++- npbackup/configuration.py | 12 +++---- npbackup/core/jobs.py | 4 ++- npbackup/core/runner.py | 8 +++-- resources/customization.py | 47 +++++++++++++++++++++++++--- resources/update_custom_resources.py | 5 ++- tests/test_npbackup-cli.py | 21 +++++++++---- 8 files changed, 82 insertions(+), 25 deletions(-) diff --git a/RESTIC_SOURCE_FILES/update_restic.py b/RESTIC_SOURCE_FILES/update_restic.py index 4967e1e..220acaa 100644 --- a/RESTIC_SOURCE_FILES/update_restic.py +++ b/RESTIC_SOURCE_FILES/update_restic.py @@ -37,7 +37,7 @@ def download_restic_binaries(arch: str = "amd64") -> bool: if response.status_code != 200: print(f"ERROR: Cannot get latest restic release: {response.status_code}") print("RESPONSE TEXT: ", response.text) - json_response = json.loads(response.text); + json_response = json.loads(response.text) try: current_version = json_response["tag_name"].lstrip("v") except KeyError: @@ -142,7 +142,9 @@ def download_restic_binaries_for_arch(): if not download_restic_binaries("amd64") or not download_restic_binaries("386"): return False elif sys.platform.lower() == "darwin": - if not download_restic_binaries("arm64") or not download_restic_binaries("amd64"): + if not download_restic_binaries("arm64") or not download_restic_binaries( + "amd64" + ): return False else: if ( diff --git a/bin/compile.py b/bin/compile.py index 8d8a805..57b1c13 100644 --- a/bin/compile.py +++ b/bin/compile.py @@ -372,7 +372,9 @@ def compile( dry_run=args.dry_run, ) else: - print(f"ERROR: Cannot sign windows executable: {SIGN_EXTERNALY} {ev_cert_data}") + print( + f"ERROR: Cannot sign windows executable: {SIGN_EXTERNALY} {ev_cert_data}" + ) errors = True if not onefile: diff --git a/npbackup/configuration.py b/npbackup/configuration.py index 8f9b78a..dbbc1c9 100644 --- a/npbackup/configuration.py +++ b/npbackup/configuration.py @@ -898,10 +898,8 @@ def _migrate_config_dict(full_config: dict, old_version: str, new_version: str) f"{object_type} {object_name} has no compression, skipping migration" ) return full_config - - def _migrate_presets_3_0_4_to_3_1_0( - full_config: dict - ): + + def _migrate_presets_3_0_4_to_3_1_0(full_config: dict): if full_config.g("presets") is None: full_config.s("presets", get_default_config().g("presets")) logger.info("Migrated presets to new config structure") @@ -952,9 +950,7 @@ def _load_config_file(config_file: Path) -> Union[bool, dict]: f"Config file {config_file} has no configuration version. Is this a valid npbackup config file?" ) return False - if conf_version < version_parse( - MIN_MIGRATABLE_CONF_VERSION - ): + if conf_version < version_parse(MIN_MIGRATABLE_CONF_VERSION): logger.critical( f"Config file {config_file} version {str(conf_version)} is not in required version range min={MIN_MIGRATABLE_CONF_VERSION}" ) @@ -963,7 +959,7 @@ def _load_config_file(config_file: Path) -> Union[bool, dict]: logger.critical( f"Config file {config_file} version {str(conf_version)} is not in required version range max={MAX_CONF_VERSION}. We will try to load it nevertheless." ) - + if conf_version < version_parse(CURRENT_CONF_VERSION): full_config = _migrate_config_dict( full_config, str(conf_version), CURRENT_CONF_VERSION diff --git a/npbackup/core/jobs.py b/npbackup/core/jobs.py index 58ca652..431043e 100644 --- a/npbackup/core/jobs.py +++ b/npbackup/core/jobs.py @@ -65,7 +65,9 @@ def schedule_on_interval(job_name: str, interval: int) -> bool: # We may not have read privileges logger.error(f"Cannot read {job_name} counter file {file}: {exc}") except ValueError as exc: - logger.error(f"Bogus {job_name} counter with value {count} in {file}: {exc}") + logger.error( + f"Bogus {job_name} counter with value {count} in {file}: {exc}" + ) return 0 path_list = [ diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index a2ac987..82159f0 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -1602,7 +1602,9 @@ class NPBackupRunner: except KeyError: pass except ValueError: - self.write_logs("Bogus additional restore parameters given", level="warning") + self.write_logs( + "Bogus additional restore parameters given", level="warning" + ) return self.restic_runner.restore( snapshot=snapshot, @@ -1637,7 +1639,9 @@ class NPBackupRunner: f"Checking time against ntp server {ntp_server}", level="info" ) offset = get_ntp_offset(ntp_server) - if offset in [False, None, ""] or offset > float(MAX_ALLOWED_NTP_OFFSET): + if offset in [False, None, ""] or offset > float( + MAX_ALLOWED_NTP_OFFSET + ): if offset in [False, None, ""]: msg = f"Offset cannot be obtained from NTP server {ntp_server}" elif offset > float(MAX_ALLOWED_NTP_OFFSET): diff --git a/resources/customization.py b/resources/customization.py index c42b7ad..b3609ba 100644 --- a/resources/customization.py +++ b/resources/customization.py @@ -35,10 +35,49 @@ SHORT_PRODUCT_NAME = "NPBackup" # SimpleGUI theme see with print(sg.theme_list()) # Valid list: ['Black', 'BlueMono', 'BluePurple', 'BrightColors', 'BrownBlue', 'Dark', 'Dark2', 'DarkAmber', 'DarkBlack', 'DarkBlack1', 'DarkBlue', 'DarkBlue1', 'DarkBlue10', 'DarkBlue11', 'DarkBlue12', 'DarkBlue13', 'DarkBlue14', 'DarkBlue15', 'DarkBlue16', 'DarkBlue17', 'DarkBlue2', 'DarkBlue3', 'DarkBlue4', 'DarkBlue5', 'DarkBlue6', 'DarkBlue7', 'DarkBlue8', 'DarkBlue9', 'DarkBrown', 'DarkBrown1', 'DarkBrown2', 'DarkBrown3', 'DarkBrown4', 'DarkBrown5', 'DarkBrown6', 'DarkBrown7', 'DarkGreen', 'DarkGreen1', 'DarkGreen2', 'DarkGreen3', 'DarkGreen4', 'DarkGreen5', 'DarkGreen6', 'DarkGreen7', 'DarkGrey', 'DarkGrey1', 'DarkGrey10', 'DarkGrey11', 'DarkGrey12', 'DarkGrey13', 'DarkGrey14', 'DarkGrey15', 'DarkGrey2', 'DarkGrey3', 'DarkGrey4', 'DarkGrey5', 'DarkGrey6', 'DarkGrey7', 'DarkGrey8', 'DarkGrey9', 'DarkPurple', 'DarkPurple1', 'DarkPurple2', 'DarkPurple3', 'DarkPurple4', 'DarkPurple5', 'DarkPurple6', 'DarkPurple7', 'DarkRed', 'DarkRed1', 'DarkRed2', 'DarkTanBlue', 'DarkTeal', 'DarkTeal1', 'DarkTeal10', 'DarkTeal11', 'DarkTeal12', 'DarkTeal2', 'DarkTeal3', 'DarkTeal4', 'DarkTeal5', 'DarkTeal6', 'DarkTeal7', 'DarkTeal8', 'DarkTeal9', 'Default', 'Default1', 'DefaultNoMoreNagging', 'GrayGrayGray', 'Green', 'GreenMono', 'GreenTan', 'HotDogStand', 'Kayak', 'LightBlue', 'LightBlue1', 'LightBlue2', 'LightBlue3', 'LightBlue4', 'LightBlue5', 'LightBlue6', 'LightBlue7', 'LightBrown', 'LightBrown1', 'LightBrown10', 'LightBrown11', 'LightBrown12', 'LightBrown13', 'LightBrown2', 'LightBrown3', 'LightBrown4', 'LightBrown5', 'LightBrown6', 'LightBrown7', 'LightBrown8', 'LightBrown9', 'LightGray1', 'LightGreen', 'LightGreen1', 'LightGreen10', 'LightGreen2', 'LightGreen3', 'LightGreen4', 'LightGreen5', 'LightGreen6', 'LightGreen7', 'LightGreen8', 'LightGreen9', 'LightGrey', 'LightGrey1', 'LightGrey2', 'LightGrey3', 'LightGrey4', 'LightGrey5', 'LightGrey6', 'LightPurple', 'LightTeal', 'LightYellow', 'Material1', 'Material2', 'NeutralBlue', 'Purple', 'Python', 'PythonPlus', 'Reddit', 'Reds', 'SandyBeach', 'SystemDefault', 'SystemDefault1', 'SystemDefaultForReal', 'Tan', 'TanBlue', 'TealMono', 'Topanga'] LOOK_AND_FEEL_TABLE = { - 'CLEAR': {'BACKGROUND': '#ffffff','TEXT': '#1a1a1b','INPUT': '#dae0e6','TEXT_INPUT': '#222222','SCROLL': '#a5a4a4','BUTTON': ('#333333', '#ffffff'),'PROGRESS': ('#015bbb', '#fed500'),'BORDER': 1,'SLIDER_DEPTH': 0,'PROGRESS_DEPTH': 0,'ACCENT1': '#ff5414','ACCENT2': '#33a8ff','ACCENT3': '#dbf0ff',}, - 'CLEAR2' : {'BACKGROUND': '#ffffff','TEXT': '#1a1a1b','INPUT': '#dae0e6','TEXT_INPUT': '#222222','SCROLL': '#a5a4a4','BUTTON': ('#333333', "#097ad1"),'PROGRESS': ('#015bbb', '#fed500'),'BORDER': 1,'SLIDER_DEPTH': 0,'PROGRESS_DEPTH': 0,'ACCENT1': '#ff5414','ACCENT2': '#33a8ff','ACCENT3': '#dbf0ff',}, - 'DARK': {'BACKGROUND': '#001d3c','TEXT': '#ffffff','INPUT': '#015bbb','TEXT_INPUT': '#fed500','SCROLL': '#015bbb','BUTTON': ('#fed500', '#001d3c'),'PROGRESS': ('#015bbb', '#fed500'),'BORDER': 1,'SLIDER_DEPTH': 1,'PROGRESS_DEPTH': 0,}, - } + "CLEAR": { + "BACKGROUND": "#ffffff", + "TEXT": "#1a1a1b", + "INPUT": "#dae0e6", + "TEXT_INPUT": "#222222", + "SCROLL": "#a5a4a4", + "BUTTON": ("#333333", "#ffffff"), + "PROGRESS": ("#015bbb", "#fed500"), + "BORDER": 1, + "SLIDER_DEPTH": 0, + "PROGRESS_DEPTH": 0, + "ACCENT1": "#ff5414", + "ACCENT2": "#33a8ff", + "ACCENT3": "#dbf0ff", + }, + "CLEAR2": { + "BACKGROUND": "#ffffff", + "TEXT": "#1a1a1b", + "INPUT": "#dae0e6", + "TEXT_INPUT": "#222222", + "SCROLL": "#a5a4a4", + "BUTTON": ("#333333", "#097ad1"), + "PROGRESS": ("#015bbb", "#fed500"), + "BORDER": 1, + "SLIDER_DEPTH": 0, + "PROGRESS_DEPTH": 0, + "ACCENT1": "#ff5414", + "ACCENT2": "#33a8ff", + "ACCENT3": "#dbf0ff", + }, + "DARK": { + "BACKGROUND": "#001d3c", + "TEXT": "#ffffff", + "INPUT": "#015bbb", + "TEXT_INPUT": "#fed500", + "SCROLL": "#015bbb", + "BUTTON": ("#fed500", "#001d3c"), + "PROGRESS": ("#015bbb", "#fed500"), + "BORDER": 1, + "SLIDER_DEPTH": 1, + "PROGRESS_DEPTH": 0, + }, +} SIMPLEGUI_THEME = "CLEAR" SIMPLEGUI_DARK_THEME = "DARK" diff --git a/resources/update_custom_resources.py b/resources/update_custom_resources.py index edc66d2..d1ee6ea 100644 --- a/resources/update_custom_resources.py +++ b/resources/update_custom_resources.py @@ -68,7 +68,10 @@ def update_custom_icons(): print(f"Updating {var_name} with {file_path}") encoded_b64 = image_to_data_url(file_path) customization = re.sub( - f'\n{var_name} = .*', f'\n{var_name} = b"{encoded_b64}"', customization, re.MULTILINE + f"\n{var_name} = .*", + f'\n{var_name} = b"{encoded_b64}"', + customization, + re.MULTILINE, ) else: print("No file found for", var_name) diff --git a/tests/test_npbackup-cli.py b/tests/test_npbackup-cli.py index ed35e4a..e540da3 100644 --- a/tests/test_npbackup-cli.py +++ b/tests/test_npbackup-cli.py @@ -65,7 +65,9 @@ repo_config, _ = get_repo_config(full_config) # File we will request in dump mode DUMP_FILE = "__version__.py" -DUMP_FILE_RESTORED = Path(tempfile.gettempdir()).absolute().joinpath("restored__version__.py") +DUMP_FILE_RESTORED = ( + Path(tempfile.gettempdir()).absolute().joinpath("restored__version__.py") +) DUMP_FILE_RESTIC_PATH = "/npbackup/npbackup/__version__.py" @@ -92,7 +94,7 @@ class RedirectedStdout: if self._bytes_io.getvalue(): return self._bytes_io.getvalue() return self._string_io.getvalue() - + def running_on_github_actions(): """ @@ -148,7 +150,9 @@ def test_download_restic_binaries(): github_actions = running_on_github_actions() print(f"DOWNLOAD result: {result}, github actions: {github_actions}") if github_actions: - assert True, "Allow restic download failure on github actions because of rate limiting" + assert ( + True + ), "Allow restic download failure on github actions because of rate limiting" else: assert result is True, "Could not download restic binaries" @@ -202,6 +206,7 @@ def test_npbackup_cli_init(): assert "Repo initialized successfully" in str(logs), "Repo init failed" os.environ["_DEBUG"] = "False" + def test_npbackup_cli_has_no_recent_snapshots(): """ After init, we should not have recent snapshots @@ -215,7 +220,9 @@ def test_npbackup_cli_has_no_recent_snapshots(): print(str(logs)) json_logs = json.loads(str(logs)) assert json_logs["result"] == False, "Should not have recent snapshots" - assert json_logs["operation"] == "has_recent_snapshot", "Bogus operation name, probably failed somewhere earlier" + assert ( + json_logs["operation"] == "has_recent_snapshot" + ), "Bogus operation name, probably failed somewhere earlier" def test_npbackup_cli_create_backup(): @@ -494,7 +501,6 @@ def test_npbackup_cli_raw(): assert False, "Did not find dump file in raw ls output" - def test_npbackup_cli_dump(): """ Don't use RedirectedStdout since dump will output binary data @@ -512,7 +518,10 @@ def test_npbackup_cli_dump(): original_sha = sha256sum(os.path.join("..", "npbackup", "npbackup", DUMP_FILE)) restored_sha = sha256sum(DUMP_FILE_RESTORED) - assert original_sha == restored_sha, "Dumped file has different sha256sum than original file" + assert ( + original_sha == restored_sha + ), "Dumped file has different sha256sum than original file" + if __name__ == "__main__": test_download_restic_binaries()