mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-21 10:57:02 +08:00
Reformat files with black
This commit is contained in:
parent
3db63aadaa
commit
6abe264b91
3 changed files with 52 additions and 25 deletions
|
@ -68,6 +68,7 @@ def _read_file(filename):
|
||||||
with open(os.path.join(here, filename), "r", encoding="utf-8") as file_handle:
|
with open(os.path.join(here, filename), "r", encoding="utf-8") as file_handle:
|
||||||
return file_handle.read()
|
return file_handle.read()
|
||||||
|
|
||||||
|
|
||||||
def get_metadata(package_file):
|
def get_metadata(package_file):
|
||||||
"""
|
"""
|
||||||
Read metadata from package file
|
Read metadata from package file
|
||||||
|
@ -84,11 +85,11 @@ def get_metadata(package_file):
|
||||||
return _metadata
|
return _metadata
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def check_private_build(audience):
|
def check_private_build(audience):
|
||||||
private = None
|
private = None
|
||||||
try:
|
try:
|
||||||
import PRIVATE._private_secret_keys
|
import PRIVATE._private_secret_keys
|
||||||
|
|
||||||
print("INFO: Building with private secret key")
|
print("INFO: Building with private secret key")
|
||||||
private = True
|
private = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -137,9 +138,7 @@ def move_audience_files(audience):
|
||||||
possible_non_used_path,
|
possible_non_used_path,
|
||||||
"_NOUSE{}".format(possible_non_used_path),
|
"_NOUSE{}".format(possible_non_used_path),
|
||||||
)
|
)
|
||||||
os.rename(
|
os.rename(file, new_file)
|
||||||
file, new_file
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
raise "Bogus audience"
|
raise "Bogus audience"
|
||||||
|
|
||||||
|
@ -147,9 +146,16 @@ def move_audience_files(audience):
|
||||||
def get_conf_dist_file(audience):
|
def get_conf_dist_file(audience):
|
||||||
platform = get_os().lower()
|
platform = get_os().lower()
|
||||||
if audience == "private":
|
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:
|
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):
|
if not os.path.isfile(dist_conf_file_path):
|
||||||
print("DIST CONF FILE NOT FOUND: {}".format(dist_conf_file_path))
|
print("DIST CONF FILE NOT FOUND: {}".format(dist_conf_file_path))
|
||||||
return None
|
return None
|
||||||
|
@ -159,6 +165,7 @@ def get_conf_dist_file(audience):
|
||||||
def have_nuitka_commercial():
|
def have_nuitka_commercial():
|
||||||
try:
|
try:
|
||||||
import nuitka.plugins.commercial
|
import nuitka.plugins.commercial
|
||||||
|
|
||||||
print("Running with nuitka commercial")
|
print("Running with nuitka commercial")
|
||||||
return True
|
return True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -340,10 +347,7 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-gui",
|
"--no-gui", action="store_true", default=False, help="Don't compile GUI support"
|
||||||
action="store_true",
|
|
||||||
default=False,
|
|
||||||
help="Don't compile GUI support"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -362,8 +366,12 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
for audience in audiences:
|
for audience in audiences:
|
||||||
move_audience_files(audience)
|
move_audience_files(audience)
|
||||||
npbackup_version = get_metadata(os.path.join(BASEDIR, "__main__.py"))["version"]
|
npbackup_version = get_metadata(os.path.join(BASEDIR, "__main__.py"))[
|
||||||
installer_version = get_metadata(os.path.join(BASEDIR, os.pardir, "bin", "NPBackupInstaller.py"))["version"]
|
"version"
|
||||||
|
]
|
||||||
|
installer_version = get_metadata(
|
||||||
|
os.path.join(BASEDIR, os.pardir, "bin", "NPBackupInstaller.py")
|
||||||
|
)["version"]
|
||||||
|
|
||||||
private_build = check_private_build(audience)
|
private_build = check_private_build(audience)
|
||||||
if private_build and audience != "private":
|
if private_build and audience != "private":
|
||||||
|
@ -375,11 +383,19 @@ if __name__ == "__main__":
|
||||||
errors = True
|
errors = True
|
||||||
continue
|
continue
|
||||||
result = compile(arch=python_arch(), audience=audience, no_gui=args.no_gui)
|
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:
|
if result:
|
||||||
print("SUCCESS: MADE {} build for audience {}".format(build_type, audience))
|
print(
|
||||||
|
"SUCCESS: MADE {} build for audience {}".format(
|
||||||
|
build_type, audience
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
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
|
errors = True
|
||||||
if errors:
|
if errors:
|
||||||
print("ERRORS IN BUILD PROCESS")
|
print("ERRORS IN BUILD PROCESS")
|
||||||
|
|
|
@ -111,6 +111,7 @@ class NPBackupRunner:
|
||||||
"""
|
"""
|
||||||
Wraps ResticRunner into a class that is usable by NPBackup
|
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
|
# 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
|
# 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:
|
try:
|
||||||
password_command = self.config_dict["repo"]["password_command"]
|
password_command = self.config_dict["repo"]["password_command"]
|
||||||
if password_command and 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 == "":
|
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
|
can_run = False
|
||||||
else:
|
else:
|
||||||
password = output
|
password = output
|
||||||
else:
|
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
|
can_run = False
|
||||||
except KeyError:
|
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
|
can_run = False
|
||||||
self.is_ready = can_run
|
self.is_ready = can_run
|
||||||
if not can_run:
|
if not can_run:
|
||||||
|
|
|
@ -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.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)),
|
sg.Text(_t("config_gui.upload_speed"), size=(30, 1)),
|
||||||
|
|
Loading…
Add table
Reference in a new issue