Reformat files with black

This commit is contained in:
Orsiris de Jong 2023-05-03 18:58:03 +02:00
parent 3db63aadaa
commit 6abe264b91
3 changed files with 52 additions and 25 deletions

View file

@ -68,6 +68,7 @@ def _read_file(filename):
with open(os.path.join(here, filename), "r", encoding="utf-8") as file_handle:
return file_handle.read()
def get_metadata(package_file):
"""
Read metadata from package file
@ -84,11 +85,11 @@ def get_metadata(package_file):
return _metadata
def check_private_build(audience):
private = None
try:
import PRIVATE._private_secret_keys
print("INFO: Building with private secret key")
private = True
except ImportError:
@ -137,9 +138,7 @@ def move_audience_files(audience):
possible_non_used_path,
"_NOUSE{}".format(possible_non_used_path),
)
os.rename(
file, new_file
)
os.rename(file, new_file)
else:
raise "Bogus audience"
@ -147,9 +146,16 @@ def move_audience_files(audience):
def get_conf_dist_file(audience):
platform = get_os().lower()
if audience == "private":
dist_conf_file_path = os.path.join(BASEDIR, os.pardir, "PRIVATE", "_private_npbackup.{}.conf.dist".format(platform))
dist_conf_file_path = os.path.join(
BASEDIR,
os.pardir,
"PRIVATE",
"_private_npbackup.{}.conf.dist".format(platform),
)
else:
dist_conf_file_path = os.path.join(BASEDIR, os.pardir, "examples", "npbackup.{}.conf.dist".format(platform))
dist_conf_file_path = os.path.join(
BASEDIR, os.pardir, "examples", "npbackup.{}.conf.dist".format(platform)
)
if not os.path.isfile(dist_conf_file_path):
print("DIST CONF FILE NOT FOUND: {}".format(dist_conf_file_path))
return None
@ -159,6 +165,7 @@ def get_conf_dist_file(audience):
def have_nuitka_commercial():
try:
import nuitka.plugins.commercial
print("Running with nuitka commercial")
return True
except ImportError:
@ -340,10 +347,7 @@ if __name__ == "__main__":
)
parser.add_argument(
"--no-gui",
action="store_true",
default=False,
help="Don't compile GUI support"
"--no-gui", action="store_true", default=False, help="Don't compile GUI support"
)
args = parser.parse_args()
@ -362,8 +366,12 @@ if __name__ == "__main__":
for audience in audiences:
move_audience_files(audience)
npbackup_version = get_metadata(os.path.join(BASEDIR, "__main__.py"))["version"]
installer_version = get_metadata(os.path.join(BASEDIR, os.pardir, "bin", "NPBackupInstaller.py"))["version"]
npbackup_version = get_metadata(os.path.join(BASEDIR, "__main__.py"))[
"version"
]
installer_version = get_metadata(
os.path.join(BASEDIR, os.pardir, "bin", "NPBackupInstaller.py")
)["version"]
private_build = check_private_build(audience)
if private_build and audience != "private":
@ -375,11 +383,19 @@ if __name__ == "__main__":
errors = True
continue
result = compile(arch=python_arch(), audience=audience, no_gui=args.no_gui)
build_type = 'private' if private_build else 'public'
build_type = "private" if private_build else "public"
if result:
print("SUCCESS: MADE {} build for audience {}".format(build_type, audience))
print(
"SUCCESS: MADE {} build for audience {}".format(
build_type, audience
)
)
else:
print("ERROR: Failed making {} build for audience {}".format(build_type, audience))
print(
"ERROR: Failed making {} build for audience {}".format(
build_type, audience
)
)
errors = True
if errors:
print("ERRORS IN BUILD PROCESS")

View file

@ -111,6 +111,7 @@ class NPBackupRunner:
"""
Wraps ResticRunner into a class that is usable by NPBackup
"""
# NPF-SEC-00002: password commands, pre_exec and post_exec commands will be executed with npbackup privileges
# This can lead to a problem when the config file can be written by users other than npbackup
@ -224,17 +225,27 @@ class NPBackupRunner:
try:
password_command = self.config_dict["repo"]["password_command"]
if password_command and password_command != "":
exit_code, output = command_runner(password_command, shell=True, timeout=30)
exit_code, output = command_runner(
password_command, shell=True, timeout=30
)
if exit_code != 0 or output == "":
logger.error("Password command failed to produce output:\n{}".format(output))
logger.error(
"Password command failed to produce output:\n{}".format(
output
)
)
can_run = False
else:
password = output
else:
logger.error("No password nor password command given. Repo password cannot be empty")
logger.error(
"No password nor password command given. Repo password cannot be empty"
)
can_run = False
except KeyError:
logger.error("No password nor password command given. Repo password cannot be empty")
logger.error(
"No password nor password command given. Repo password cannot be empty"
)
can_run = False
self.is_ready = can_run
if not can_run:

View file

@ -255,7 +255,7 @@ def config_gui(config_dict: dict, config_file: str):
],
[
sg.Text(_t("config.gui.backup_repo_password_command"), size=(30, 1)),
sg.Input(key="repo---password_command", size=(50, 1))
sg.Input(key="repo---password_command", size=(50, 1)),
],
[
sg.Text(_t("config_gui.upload_speed"), size=(30, 1)),