mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-12 07:55:23 +08:00
Reformat files with black
This commit is contained in:
parent
19f67881e6
commit
13956b452a
8 changed files with 69 additions and 40 deletions
|
@ -112,7 +112,9 @@ def download_restic_binaries(arch: str = "amd64") -> bool:
|
||||||
if arch_suffix != ".bz2":
|
if arch_suffix != ".bz2":
|
||||||
if dest_dir.joinpath("ARCHIVES").joinpath(filename).is_file():
|
if dest_dir.joinpath("ARCHIVES").joinpath(filename).is_file():
|
||||||
dest_dir.joinpath("ARCHIVES").joinpath(filename).unlink()
|
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:
|
except OSError as exc:
|
||||||
print(
|
print(
|
||||||
f'CANNOT MOVE TO ARCHIVE: {full_path} to {dest_dir.joinpath("ARCHIVES").joinpath(filename)}: {[exc]}'
|
f'CANNOT MOVE TO ARCHIVE: {full_path} to {dest_dir.joinpath("ARCHIVES").joinpath(filename)}: {[exc]}'
|
||||||
|
|
|
@ -31,6 +31,7 @@ import argparse
|
||||||
import atexit
|
import atexit
|
||||||
from command_runner import command_runner
|
from command_runner import command_runner
|
||||||
from ofunctions.platform import python_arch, get_os
|
from ofunctions.platform import python_arch, get_os
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
from npbackup.windows.sign_windows import sign
|
from npbackup.windows.sign_windows import sign
|
||||||
from npbackup.__version__ import IS_LEGACY
|
from npbackup.__version__ import IS_LEGACY
|
||||||
|
@ -105,12 +106,14 @@ def check_private_build():
|
||||||
try:
|
try:
|
||||||
import PRIVATE._private_secret_keys
|
import PRIVATE._private_secret_keys
|
||||||
import PRIVATE._obfuscation
|
import PRIVATE._obfuscation
|
||||||
|
|
||||||
print("INFO: Building with private secret key")
|
print("INFO: Building with private secret key")
|
||||||
private = True
|
private = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
import npbackup.secret_keys
|
import npbackup.secret_keys
|
||||||
import npbackup.obfuscation
|
import npbackup.obfuscation
|
||||||
|
|
||||||
print("INFO: Building with default secret key")
|
print("INFO: Building with default secret key")
|
||||||
private = False
|
private = False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -166,6 +169,7 @@ def move_audience_files(audience):
|
||||||
else:
|
else:
|
||||||
raise "Bogus audience"
|
raise "Bogus audience"
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def get_conf_dist_file(audience):
|
def get_conf_dist_file(audience):
|
||||||
platform = get_os().lower()
|
platform = get_os().lower()
|
||||||
|
@ -186,6 +190,7 @@ def get_conf_dist_file(audience):
|
||||||
return dist_conf_file_path
|
return dist_conf_file_path
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def have_nuitka_commercial():
|
def have_nuitka_commercial():
|
||||||
try:
|
try:
|
||||||
import nuitka.plugins.commercial
|
import nuitka.plugins.commercial
|
||||||
|
@ -197,13 +202,20 @@ def have_nuitka_commercial():
|
||||||
return False
|
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:
|
if build_type not in BUILD_TYPES:
|
||||||
print("CANNOT BUILD BOGUS BUILD TYPE")
|
print("CANNOT BUILD BOGUS BUILD TYPE")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
source_program = "bin/npbackup-{}".format(build_type)
|
source_program = "bin/npbackup-{}".format(build_type)
|
||||||
|
|
||||||
|
|
||||||
if onefile:
|
if onefile:
|
||||||
suffix = "-{}-{}".format(build_type, arch)
|
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(
|
compiled_output_dir = os.path.join(
|
||||||
OUTPUT_DIR, "npbackup-{}{}".format(build_type, NUITKA_STANDALONE_SUFFIX)
|
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):
|
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:
|
else:
|
||||||
print("ERROR: Cannot sign windows executable without EV certificate data")
|
print("ERROR: Cannot sign windows executable without EV certificate data")
|
||||||
errors = True
|
errors = True
|
||||||
|
@ -376,7 +395,7 @@ def create_archive(
|
||||||
"""
|
"""
|
||||||
Create tar releases for each compiled version
|
Create tar releases for each compiled version
|
||||||
"""
|
"""
|
||||||
|
|
||||||
compiled_output = os.path.join(
|
compiled_output = os.path.join(
|
||||||
output_dir, "npbackup-{}{}".format(build_type, NUITKA_STANDALONE_SUFFIX)
|
output_dir, "npbackup-{}{}".format(build_type, NUITKA_STANDALONE_SUFFIX)
|
||||||
)
|
)
|
||||||
|
@ -459,7 +478,6 @@ if __name__ == "__main__":
|
||||||
help="Digitally sign windows executables",
|
help="Digitally sign windows executables",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--sign-only",
|
"--sign-only",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
@ -481,7 +499,7 @@ if __name__ == "__main__":
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
required=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()
|
args = parser.parse_args()
|
||||||
|
@ -512,8 +530,8 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
for audience in audiences:
|
for audience in audiences:
|
||||||
npbackup_version = get_metadata(os.path.join(BASEDIR, "__version__.py"))[
|
npbackup_version = get_metadata(os.path.join(BASEDIR, "__version__.py"))[
|
||||||
"version"
|
"version"
|
||||||
]
|
]
|
||||||
if not create_tar_only:
|
if not create_tar_only:
|
||||||
move_audience_files(audience)
|
move_audience_files(audience)
|
||||||
|
|
||||||
|
@ -522,7 +540,9 @@ if __name__ == "__main__":
|
||||||
print("ERROR: Requested public build but private data available")
|
print("ERROR: Requested public build but private data available")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif not private_build and audience != "public":
|
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)
|
sys.exit(1)
|
||||||
for build_type in build_types:
|
for build_type in build_types:
|
||||||
result = compile(
|
result = compile(
|
||||||
|
@ -532,7 +552,7 @@ if __name__ == "__main__":
|
||||||
onefile=args.onefile,
|
onefile=args.onefile,
|
||||||
create_tar_only=create_tar_only,
|
create_tar_only=create_tar_only,
|
||||||
ev_cert_data=args.ev_cert_data,
|
ev_cert_data=args.ev_cert_data,
|
||||||
sign_only=sign_only
|
sign_only=sign_only,
|
||||||
)
|
)
|
||||||
if not create_tar_only and not sign_only:
|
if not create_tar_only and not sign_only:
|
||||||
audience_build = "private" if private_build else "public"
|
audience_build = "private" if private_build else "public"
|
||||||
|
|
|
@ -1163,7 +1163,11 @@ def _main_gui(viewer_mode: bool):
|
||||||
except (TypeError, KeyError):
|
except (TypeError, KeyError):
|
||||||
sg.PopupNoFrame(_t("main_gui.unknown_repo"))
|
sg.PopupNoFrame(_t("main_gui.unknown_repo"))
|
||||||
if event == "--ABOUT--":
|
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 event == "--STATE-BUTTON--":
|
||||||
if full_config or viewer_mode:
|
if full_config or viewer_mode:
|
||||||
current_state, backup_tz, snapshot_list = get_gui_data(repo_config)
|
current_state, backup_tz, snapshot_list = get_gui_data(repo_config)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Placeholder so this directory becomes a package
|
# Placeholder so this directory becomes a package
|
||||||
|
|
|
@ -684,4 +684,4 @@ copy of the Program in return for a fee.
|
||||||
END OF TERMS AND CONDITIONS
|
END OF TERMS AND CONDITIONS
|
||||||
"""
|
"""
|
||||||
# Arbitrary string that should not be changed unless you know exactly what you are doing
|
# Arbitrary string that should not be changed unless you know exactly what you are doing
|
||||||
ID_STRING = "__NPBACKUP__"
|
ID_STRING = "__NPBACKUP__"
|
||||||
|
|
|
@ -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
|
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):
|
def image_to_data_url(filename, as_url: bool = False):
|
||||||
ext = filename.split('.')[-1]
|
ext = filename.split(".")[-1]
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, "rb") as f:
|
||||||
img = f.read()
|
img = f.read()
|
||||||
if as_url:
|
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:
|
else:
|
||||||
return base64.b64encode(img).decode('utf-8')
|
return base64.b64encode(img).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
def update_custom_icons():
|
def update_custom_icons():
|
||||||
|
@ -36,21 +37,21 @@ def update_custom_icons():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
custom_resources = {
|
custom_resources = {
|
||||||
'FOLDER_ICON': 'folder_icon.png',
|
"FOLDER_ICON": "folder_icon.png",
|
||||||
'INHERITED_FOLDER_ICON': 'inherited_folder_icon.png',
|
"INHERITED_FOLDER_ICON": "inherited_folder_icon.png",
|
||||||
'FILE_ICON': 'file_icon.png',
|
"FILE_ICON": "file_icon.png",
|
||||||
'INHERITED_FILE_ICON': 'inherited_file_icon.png',
|
"INHERITED_FILE_ICON": "inherited_file_icon.png",
|
||||||
'TREE_ICON': 'tree_icon.png',
|
"TREE_ICON": "tree_icon.png",
|
||||||
'INHERITED_TREE_ICON': 'inherited_tree_icon.png',
|
"INHERITED_TREE_ICON": "inherited_tree_icon.png",
|
||||||
'NON_INHERITED_ICON': 'non_inherited_icon.png',
|
"NON_INHERITED_ICON": "non_inherited_icon.png",
|
||||||
'LOADING_ANIMATION': 'loading.gif',
|
"LOADING_ANIMATION": "loading.gif",
|
||||||
'OEM_LOGO': 'oem_logo.png',
|
"OEM_LOGO": "oem_logo.png",
|
||||||
'OEM_ICON': 'oem_icon.png'
|
"OEM_ICON": "oem_icon.png",
|
||||||
}
|
}
|
||||||
|
|
||||||
resources_dir = os.path.join(BASEDIR, os.path.pardir, 'resources')
|
resources_dir = os.path.join(BASEDIR, os.path.pardir, "resources")
|
||||||
customization_py = os.path.join(resources_dir, 'customization.py')
|
customization_py = os.path.join(resources_dir, "customization.py")
|
||||||
with open(customization_py, 'r', encoding="utf-8") as f:
|
with open(customization_py, "r", encoding="utf-8") as f:
|
||||||
customization = f.read()
|
customization = f.read()
|
||||||
for var_name, file in custom_resources.items():
|
for var_name, file in custom_resources.items():
|
||||||
file_path = os.path.join(resources_dir, file)
|
file_path = os.path.join(resources_dir, file)
|
||||||
|
@ -58,11 +59,14 @@ def update_custom_icons():
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
print(f"Updating {var_name} with {file_path}")
|
print(f"Updating {var_name} with {file_path}")
|
||||||
encoded_b64 = image_to_data_url(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:
|
else:
|
||||||
print("No file found for", var_name)
|
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)
|
f.write(customization)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
update_custom_icons()
|
if __name__ == "__main__":
|
||||||
|
update_custom_icons()
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -105,7 +105,8 @@ scripts = ["misc/npbackup-cli.cmd"]
|
||||||
console_scripts = [
|
console_scripts = [
|
||||||
"npbackup-cli = npbackup.__main__:main",
|
"npbackup-cli = npbackup.__main__:main",
|
||||||
"npbackup-gui = npbackup.gui.__main__:main_gui",
|
"npbackup-gui = npbackup.gui.__main__:main_gui",
|
||||||
"npbackup-viewer = npbackup.gui.viewer:viewer_gui",]
|
"npbackup-viewer = npbackup.gui.viewer:viewer_gui",
|
||||||
|
]
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name=PACKAGE_NAME,
|
name=PACKAGE_NAME,
|
||||||
|
|
|
@ -436,9 +436,7 @@ def test_npbackup_cli_dump():
|
||||||
print("DUMPED FILE", DUMP_FILE)
|
print("DUMPED FILE", DUMP_FILE)
|
||||||
print(logs)
|
print(logs)
|
||||||
assert '__intname__ = "npbackup"' in str(logs), "version file seems bogus"
|
assert '__intname__ = "npbackup"' in str(logs), "version file seems bogus"
|
||||||
assert '"pv": sys.version_info,' in str(
|
assert '"pv": sys.version_info,' in str(logs), "Version file still seems bogus"
|
||||||
logs
|
|
||||||
), "Version file still seems bogus"
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Reference in a new issue