From 34bb5eb46b1bc5b64a7ae88b2e7e0c2693d3f726 Mon Sep 17 00:00:00 2001 From: Orsiris de Jong Date: Thu, 2 Feb 2023 23:07:44 +0100 Subject: [PATCH] Reformat files with black --- npbackup/core/runner.py | 1 - npbackup/gui/config.py | 2 +- npbackup/restic_wrapper/__init__.py | 12 ++-------- upgrade_server/upgrade_server.py | 1 - upgrade_server/upgrade_server/api.py | 32 ++++++++++++++++++++++----- upgrade_server/upgrade_server/crud.py | 2 +- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/npbackup/core/runner.py b/npbackup/core/runner.py index 7f79b1c..197e5de 100644 --- a/npbackup/core/runner.py +++ b/npbackup/core/runner.py @@ -554,7 +554,6 @@ class NPBackupRunner: @exec_timer def raw(self, command: str) -> bool: - logger.info("Running raw command: {}".format(command)) result = self.restic_runner.raw(command=command) return result diff --git a/npbackup/gui/config.py b/npbackup/gui/config.py index 16ebf6a..74ba72e 100644 --- a/npbackup/gui/config.py +++ b/npbackup/gui/config.py @@ -472,7 +472,7 @@ def config_gui(config_dict: dict, config_file: str): if event in (sg.WIN_CLOSED, "cancel"): break if event == "accept": - if not values['repo---password']: + if not values["repo---password"]: sg.PopupError(_t("config_gui.repo_password_cannot_be_empty")) continue config_dict = update_config_dict(values, config_dict) diff --git a/npbackup/restic_wrapper/__init__.py b/npbackup/restic_wrapper/__init__.py index 82a4be4..f4a164c 100644 --- a/npbackup/restic_wrapper/__init__.py +++ b/npbackup/restic_wrapper/__init__.py @@ -241,17 +241,9 @@ class ResticRunner: return True, output # TEMP-FIX-4155-END self.last_command_status = False - + # From here, we assume that we have errors - # Before going back to errors, let's analyze current output - - # Cannot connect to repo (port ?) - #if re.match("Fatal: unable to open config file: Head .*: dial tcp .*: connect .*", output): - # logger.error("Cannot connect to repo.") - - #if re.match("Is there a repository at the following location\?", output): - # We did achieve to get to the repo - + # We'll log them unless we tried to know if the repo is initialized if not errors_allowed and output: logger.error(output) return False, output diff --git a/upgrade_server/upgrade_server.py b/upgrade_server/upgrade_server.py index be3dd1e..74bc312 100644 --- a/upgrade_server/upgrade_server.py +++ b/upgrade_server/upgrade_server.py @@ -53,7 +53,6 @@ logger = logger_get_logger() if __name__ == "__main__": try: - server.run("upgrade_server.api:app", **server_args) except KeyboardInterrupt as exc: logger.error("Program interrupted by keyoard: {}".format(exc)) diff --git a/upgrade_server/upgrade_server/api.py b/upgrade_server/upgrade_server/api.py index b419578..61a6e74 100644 --- a/upgrade_server/upgrade_server/api.py +++ b/upgrade_server/upgrade_server/api.py @@ -80,21 +80,41 @@ async def current_version(auth=Depends(get_current_username)): @app.get("/upgrades/{platform}/{arch}", response_model=FileSend, status_code=200) -@app.get("/upgrades/{platform}/{arch}/{host_identity}", response_model=FileSend, status_code=200) -@app.get("/upgrades/{platform}/{arch}/{host_identity}/{installed_version}", response_model=FileSend, status_code=200) -@app.get("/upgrades/{platform}/{arch}/{host_identity}/{installed_version}/{group}", response_model=FileSend, status_code=200) -async def upgrades(request: Request, platform: Platform, arch: Arch, host_identity: str = None, installed_version: str = None, group: str = None, auth=Depends(get_current_username)): +@app.get( + "/upgrades/{platform}/{arch}/{host_identity}", + response_model=FileSend, + status_code=200, +) +@app.get( + "/upgrades/{platform}/{arch}/{host_identity}/{installed_version}", + response_model=FileSend, + status_code=200, +) +@app.get( + "/upgrades/{platform}/{arch}/{host_identity}/{installed_version}/{group}", + response_model=FileSend, + status_code=200, +) +async def upgrades( + request: Request, + platform: Platform, + arch: Arch, + host_identity: str = None, + installed_version: str = None, + group: str = None, + auth=Depends(get_current_username), +): data = { "ip": request.client.host, "host_identity": host_identity, "installed_version": installed_version, "group": group, "platform": platform.value, - "arch": arch.value + "arch": arch.value, } try: - crud.store_host_info(config_dict['upgrades']['statistics_file'], host_id = data) + crud.store_host_info(config_dict["upgrades"]["statistics_file"], host_id=data) except KeyError: logger.error("No statistics file set.") diff --git a/upgrade_server/upgrade_server/crud.py b/upgrade_server/upgrade_server/crud.py index 45c631c..899a269 100644 --- a/upgrade_server/upgrade_server/crud.py +++ b/upgrade_server/upgrade_server/crud.py @@ -41,7 +41,7 @@ def is_enabled() -> bool: def store_host_info(destination: str, host_id: dict) -> None: try: data = ",".join(host_id.values()) + "\n" - with open(destination, 'a', encoding='utf-8') as fpw: + with open(destination, "a", encoding="utf-8") as fpw: fpw.write(data) except OSError: logger.error("Cannot write statistics file")