From 13956b452a192294eaa7a59ed9132f4a21dfb831 Mon Sep 17 00:00:00 2001 From: deajan Date: Sat, 25 Jan 2025 12:33:46 +0100 Subject: [PATCH] Reformat files with black --- RESTIC_SOURCE_FILES/update_restic.py | 4 ++- bin/compile.py | 42 ++++++++++++++++++------- npbackup/gui/__main__.py | 6 +++- resources/__init__.py | 2 +- resources/customization.py | 2 +- resources/update_custom_resources.py | 46 +++++++++++++++------------- setup.py | 3 +- tests/test_npbackup-cli.py | 4 +-- 8 files changed, 69 insertions(+), 40 deletions(-) diff --git a/RESTIC_SOURCE_FILES/update_restic.py b/RESTIC_SOURCE_FILES/update_restic.py index 1ce6820..70d7196 100644 --- a/RESTIC_SOURCE_FILES/update_restic.py +++ b/RESTIC_SOURCE_FILES/update_restic.py @@ -112,7 +112,9 @@ def download_restic_binaries(arch: str = "amd64") -> bool: if arch_suffix != ".bz2": if dest_dir.joinpath("ARCHIVES").joinpath(filename).is_file(): dest_dir.joinpath("ARCHIVES").joinpath(filename).unlink() - shutil.move(full_path, dest_dir.joinpath("ARCHIVES").joinpath(filename)) + shutil.move( + full_path, dest_dir.joinpath("ARCHIVES").joinpath(filename) + ) except OSError as exc: print( f'CANNOT MOVE TO ARCHIVE: {full_path} to {dest_dir.joinpath("ARCHIVES").joinpath(filename)}: {[exc]}' diff --git a/bin/compile.py b/bin/compile.py index 0b0261d..72e5758 100644 --- a/bin/compile.py +++ b/bin/compile.py @@ -31,6 +31,7 @@ import argparse import atexit from command_runner import command_runner from ofunctions.platform import python_arch, get_os + if os.name == "nt": from npbackup.windows.sign_windows import sign from npbackup.__version__ import IS_LEGACY @@ -105,12 +106,14 @@ def check_private_build(): try: import PRIVATE._private_secret_keys import PRIVATE._obfuscation + print("INFO: Building with private secret key") private = True except ImportError: try: import npbackup.secret_keys import npbackup.obfuscation + print("INFO: Building with default secret key") private = False except ImportError: @@ -166,6 +169,7 @@ def move_audience_files(audience): else: raise "Bogus audience" + """ def get_conf_dist_file(audience): platform = get_os().lower() @@ -186,6 +190,7 @@ def get_conf_dist_file(audience): return dist_conf_file_path """ + def have_nuitka_commercial(): try: import nuitka.plugins.commercial @@ -197,13 +202,20 @@ def have_nuitka_commercial(): return False -def compile(arch: str, audience: str, build_type: str, onefile: bool, create_tar_only: bool, ev_cert_data: str = None, sign_only: bool = False): +def compile( + arch: str, + audience: str, + build_type: str, + onefile: bool, + create_tar_only: bool, + ev_cert_data: str = None, + sign_only: bool = False, +): if build_type not in BUILD_TYPES: print("CANNOT BUILD BOGUS BUILD TYPE") sys.exit(1) source_program = "bin/npbackup-{}".format(build_type) - if onefile: suffix = "-{}-{}".format(build_type, arch) @@ -351,9 +363,16 @@ def compile(arch: str, audience: str, build_type: str, onefile: bool, create_tar compiled_output_dir = os.path.join( OUTPUT_DIR, "npbackup-{}{}".format(build_type, NUITKA_STANDALONE_SUFFIX) ) - npbackup_executable = os.path.join(compiled_output_dir, "npbackup-{}.exe".format(build_type)) + npbackup_executable = os.path.join( + compiled_output_dir, "npbackup-{}.exe".format(build_type) + ) if os.path.isfile(ev_cert_data): - sign(executable=npbackup_executable, arch=arch, ev_cert_data=ev_cert_data, dry_run=args.dry_run) + sign( + executable=npbackup_executable, + arch=arch, + ev_cert_data=ev_cert_data, + dry_run=args.dry_run, + ) else: print("ERROR: Cannot sign windows executable without EV certificate data") errors = True @@ -376,7 +395,7 @@ def create_archive( """ Create tar releases for each compiled version """ - + compiled_output = os.path.join( output_dir, "npbackup-{}{}".format(build_type, NUITKA_STANDALONE_SUFFIX) ) @@ -459,7 +478,6 @@ if __name__ == "__main__": help="Digitally sign windows executables", ) - parser.add_argument( "--sign-only", action="store_true", @@ -481,7 +499,7 @@ if __name__ == "__main__": action="store_true", default=False, required=False, - help="Only create tar files, shortcut when we need to package signed binaries" + help="Only create tar files, shortcut when we need to package signed binaries", ) args = parser.parse_args() @@ -512,8 +530,8 @@ if __name__ == "__main__": for audience in audiences: npbackup_version = get_metadata(os.path.join(BASEDIR, "__version__.py"))[ - "version" - ] + "version" + ] if not create_tar_only: move_audience_files(audience) @@ -522,7 +540,9 @@ if __name__ == "__main__": print("ERROR: Requested public build but private data available") sys.exit(1) elif not private_build and audience != "public": - print("ERROR: Requested private build but no private data available") + print( + "ERROR: Requested private build but no private data available" + ) sys.exit(1) for build_type in build_types: result = compile( @@ -532,7 +552,7 @@ if __name__ == "__main__": onefile=args.onefile, create_tar_only=create_tar_only, ev_cert_data=args.ev_cert_data, - sign_only=sign_only + sign_only=sign_only, ) if not create_tar_only and not sign_only: audience_build = "private" if private_build else "public" diff --git a/npbackup/gui/__main__.py b/npbackup/gui/__main__.py index ed4b304..2de5e9b 100644 --- a/npbackup/gui/__main__.py +++ b/npbackup/gui/__main__.py @@ -1163,7 +1163,11 @@ def _main_gui(viewer_mode: bool): except (TypeError, KeyError): sg.PopupNoFrame(_t("main_gui.unknown_repo")) if event == "--ABOUT--": - about_gui(version_string, full_config if not viewer_mode else None, auto_upgrade_result) + about_gui( + version_string, + full_config if not viewer_mode else None, + auto_upgrade_result, + ) if event == "--STATE-BUTTON--": if full_config or viewer_mode: current_state, backup_tz, snapshot_list = get_gui_data(repo_config) diff --git a/resources/__init__.py b/resources/__init__.py index 79d9367..90138bc 100644 --- a/resources/__init__.py +++ b/resources/__init__.py @@ -1,4 +1,4 @@ #! /usr/bin/env python3 # -*- coding: utf-8 -*- -# Placeholder so this directory becomes a package \ No newline at end of file +# Placeholder so this directory becomes a package diff --git a/resources/customization.py b/resources/customization.py index d37df24..8397f4a 100644 --- a/resources/customization.py +++ b/resources/customization.py @@ -684,4 +684,4 @@ copy of the Program in return for a fee. END OF TERMS AND CONDITIONS """ # Arbitrary string that should not be changed unless you know exactly what you are doing -ID_STRING = "__NPBACKUP__" \ No newline at end of file +ID_STRING = "__NPBACKUP__" diff --git a/resources/update_custom_resources.py b/resources/update_custom_resources.py index 5f2fdab..904a4e0 100644 --- a/resources/update_custom_resources.py +++ b/resources/update_custom_resources.py @@ -20,14 +20,15 @@ from npbackup.path_helper import BASEDIR Launching this file will update customization.py inline png images and gif animations with files from resources directory, if exist """ + def image_to_data_url(filename, as_url: bool = False): - ext = filename.split('.')[-1] - with open(filename, 'rb') as f: + ext = filename.split(".")[-1] + with open(filename, "rb") as f: img = f.read() if as_url: - return f'data:image/{ext};base64,' + base64.b64encode(img).decode('utf-8') + return f"data:image/{ext};base64," + base64.b64encode(img).decode("utf-8") else: - return base64.b64encode(img).decode('utf-8') + return base64.b64encode(img).decode("utf-8") def update_custom_icons(): @@ -36,21 +37,21 @@ def update_custom_icons(): """ custom_resources = { - 'FOLDER_ICON': 'folder_icon.png', - 'INHERITED_FOLDER_ICON': 'inherited_folder_icon.png', - 'FILE_ICON': 'file_icon.png', - 'INHERITED_FILE_ICON': 'inherited_file_icon.png', - 'TREE_ICON': 'tree_icon.png', - 'INHERITED_TREE_ICON': 'inherited_tree_icon.png', - 'NON_INHERITED_ICON': 'non_inherited_icon.png', - 'LOADING_ANIMATION': 'loading.gif', - 'OEM_LOGO': 'oem_logo.png', - 'OEM_ICON': 'oem_icon.png' + "FOLDER_ICON": "folder_icon.png", + "INHERITED_FOLDER_ICON": "inherited_folder_icon.png", + "FILE_ICON": "file_icon.png", + "INHERITED_FILE_ICON": "inherited_file_icon.png", + "TREE_ICON": "tree_icon.png", + "INHERITED_TREE_ICON": "inherited_tree_icon.png", + "NON_INHERITED_ICON": "non_inherited_icon.png", + "LOADING_ANIMATION": "loading.gif", + "OEM_LOGO": "oem_logo.png", + "OEM_ICON": "oem_icon.png", } - resources_dir = os.path.join(BASEDIR, os.path.pardir, 'resources') - customization_py = os.path.join(resources_dir, 'customization.py') - with open(customization_py, 'r', encoding="utf-8") as f: + resources_dir = os.path.join(BASEDIR, os.path.pardir, "resources") + customization_py = os.path.join(resources_dir, "customization.py") + 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) @@ -58,11 +59,14 @@ def update_custom_icons(): if os.path.exists(file_path): print(f"Updating {var_name} with {file_path}") encoded_b64 = image_to_data_url(file_path) - customization = re.sub(f'{var_name} = b".*"', f'{var_name} = b"{encoded_b64}"', customization) + 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', encoding="utf-8") as f: + with open(customization_py, "w", encoding="utf-8") as f: f.write(customization) -if __name__ == '__main__': - update_custom_icons() \ No newline at end of file + +if __name__ == "__main__": + update_custom_icons() diff --git a/setup.py b/setup.py index 2876070..298155c 100644 --- a/setup.py +++ b/setup.py @@ -105,7 +105,8 @@ scripts = ["misc/npbackup-cli.cmd"] console_scripts = [ "npbackup-cli = npbackup.__main__:main", "npbackup-gui = npbackup.gui.__main__:main_gui", - "npbackup-viewer = npbackup.gui.viewer:viewer_gui",] + "npbackup-viewer = npbackup.gui.viewer:viewer_gui", +] setuptools.setup( name=PACKAGE_NAME, diff --git a/tests/test_npbackup-cli.py b/tests/test_npbackup-cli.py index db9c6ad..12f12e0 100644 --- a/tests/test_npbackup-cli.py +++ b/tests/test_npbackup-cli.py @@ -436,9 +436,7 @@ def test_npbackup_cli_dump(): print("DUMPED FILE", DUMP_FILE) print(logs) assert '__intname__ = "npbackup"' in str(logs), "version file seems bogus" - assert '"pv": sys.version_info,' in str( - logs - ), "Version file still seems bogus" + assert '"pv": sys.version_info,' in str(logs), "Version file still seems bogus" if __name__ == "__main__":