From 98b07df6d505fd9b63ff62151d03af634cb6865a Mon Sep 17 00:00:00 2001 From: administrateur Date: Tue, 1 Apr 2025 13:32:54 +0200 Subject: [PATCH] fix: falling back to fullsync if mkdocs.yml is lacking or new website --- script_creator.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/script_creator.py b/script_creator.py index b806b11..f2615ea 100644 --- a/script_creator.py +++ b/script_creator.py @@ -64,7 +64,7 @@ def stream_command(cmd): process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) output = [] for line in process.stdout: - print(line.rstrip(), flush=True) + log_debug(line.rstrip()) output.append(line.rstrip()) process.wait() return process.returncode, "\n".join(output) @@ -74,13 +74,18 @@ def rclone_sync(website, local_path, file_path=None): remote_base = f"nextcloud:{NEXTCLOUD_PATH}/@{website}" if file_path: - remote_path = f"{remote_base}/{file_path}" dest_path = os.path.join(local_path, file_path) + if not os.path.exists(dest_path) or not os.path.exists(os.path.join(local_path, "mkdocs.yml")): + log_debug("Target file or mkdocs.yml missing — falling back to full sync") + file_path = None + + if file_path: + remote_path = f"{remote_base}/{file_path}" os.makedirs(os.path.dirname(dest_path), exist_ok=True) - cmd = f"rclone --config {config_file} copy {remote_path} {os.path.dirname(dest_path)} --use-server-modtime" + cmd = f"rclone --config {config_file} copy \"{remote_path}\" \"{os.path.dirname(dest_path)}\" --use-server-modtime --verbose" else: remote_path = remote_base - cmd = f"rclone --config {config_file} sync {remote_path} {local_path} --use-server-modtime --delete-after --fast-list --multi-thread-streams=4 --transfers=8 --checkers=16" + cmd = f"rclone --config {config_file} sync \"{remote_path}\" \"{local_path}\" --use-server-modtime --delete-after --fast-list --multi-thread-streams=4 --transfers=8 --checkers=16 --verbose" log_debug(f"Syncing from {remote_path} to {local_path}") return stream_command(cmd) @@ -130,7 +135,7 @@ def build_mkdocs(): return jsonify({"status": "error", "message": "MkDocs build failed", "stdout": output_build}), 500 log_debug(f"Performing differential copy from {compile_path} to {final_path}") - rsync_cmd = f"rsync -a --delete {compile_path}/ {final_path}/" + rsync_cmd = f"rsync -a --delete \"{compile_path}/\" \"{final_path}/\"" code, output_rsync = stream_command(rsync_cmd) if code != 0: return jsonify({"status": "error", "message": "Rsync failed", "stdout": output_rsync}), 500 @@ -152,4 +157,4 @@ def build_mkdocs(): if __name__ == "__main__": log_debug("Starting Flask server on 0.0.0.0:80") - app.run(host="0.0.0.0", port=80) + app.run(host="0.0.0.0", port=80) \ No newline at end of file