fix: falling back to fullsync if mkdocs.yml is lacking or new website
This commit is contained in:
parent
a2c8a307f0
commit
98b07df6d5
@ -64,7 +64,7 @@ def stream_command(cmd):
|
|||||||
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||||
output = []
|
output = []
|
||||||
for line in process.stdout:
|
for line in process.stdout:
|
||||||
print(line.rstrip(), flush=True)
|
log_debug(line.rstrip())
|
||||||
output.append(line.rstrip())
|
output.append(line.rstrip())
|
||||||
process.wait()
|
process.wait()
|
||||||
return process.returncode, "\n".join(output)
|
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}"
|
remote_base = f"nextcloud:{NEXTCLOUD_PATH}/@{website}"
|
||||||
|
|
||||||
if file_path:
|
if file_path:
|
||||||
remote_path = f"{remote_base}/{file_path}"
|
|
||||||
dest_path = os.path.join(local_path, 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)
|
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:
|
else:
|
||||||
remote_path = remote_base
|
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}")
|
log_debug(f"Syncing from {remote_path} to {local_path}")
|
||||||
return stream_command(cmd)
|
return stream_command(cmd)
|
||||||
@ -130,7 +135,7 @@ def build_mkdocs():
|
|||||||
return jsonify({"status": "error", "message": "MkDocs build failed", "stdout": output_build}), 500
|
return jsonify({"status": "error", "message": "MkDocs build failed", "stdout": output_build}), 500
|
||||||
|
|
||||||
log_debug(f"Performing differential copy from {compile_path} to {final_path}")
|
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)
|
code, output_rsync = stream_command(rsync_cmd)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
return jsonify({"status": "error", "message": "Rsync failed", "stdout": output_rsync}), 500
|
return jsonify({"status": "error", "message": "Rsync failed", "stdout": output_rsync}), 500
|
||||||
@ -152,4 +157,4 @@ def build_mkdocs():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
log_debug("Starting Flask server on 0.0.0.0:80")
|
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)
|
Loading…
x
Reference in New Issue
Block a user