From: Christian Heller Date: Wed, 25 Dec 2024 19:55:58 +0000 (+0100) Subject: For sync, identify missing files by .digest.b64 rather than relative path. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7B%20deck_id%20%7D%7D/processes?a=commitdiff_plain;h=c00ccad1a60d4eb03daabf9f693ec023dfcfe3e1;p=ytplom For sync, identify missing files by .digest.b64 rather than relative path. --- diff --git a/src/sync.py b/src/sync.py index adfcef3..dde4348 100755 --- a/src/sync.py +++ b/src/sync.py @@ -4,14 +4,13 @@ # included libs from typing import Any, Callable from json import loads as json_loads -from pathlib import Path from urllib.request import urlopen # non-included libs from paramiko import SSHClient # type: ignore from scp import SCPClient # type: ignore from ytplom.db import DbConn, PATH_DB -from ytplom.misc import (PATH_DOWNLOADS, PATH_TEMP, Config, QuotaLog, - VideoFile, YoutubeQuery, YoutubeVideo) +from ytplom.misc import ( + PATH_TEMP, Config, QuotaLog, VideoFile, YoutubeQuery, YoutubeVideo) from ytplom.http import PAGE_NAMES @@ -95,15 +94,16 @@ def fill_missing(scp: SCPClient, config: Config) -> None: (config.host, config.port)): url_missing = f'http://{host}:{port}/{PAGE_NAMES["missing"]}' with urlopen(url_missing) as response: - missings += [[Path(p) for p in json_loads(response.read())]] + missings += [list(json_loads(response.read()))] + conn = DbConn() for i, direction_mover in enumerate([('local->remote', scp.put), ('remote->local', scp.get)]): direction, mover = direction_mover - for path in (p for p in missings[i] - if p not in missings[int(not bool(i))]): - full_path = PATH_DOWNLOADS.joinpath(path) - print(f'SYNC: sending {direction} file {path}') - mover(full_path, full_path) + for digest in (d for d in missings[i] + if d not in missings[int(not bool(i))]): + vf = VideoFile.get_one(conn, digest) + print(f'SYNC: sending {direction} file {vf.full_path}') + mover(vf.full_path, vf.full_path) def main(): diff --git a/src/ytplom/http.py b/src/ytplom/http.py index 7f4780f..0014383 100644 --- a/src/ytplom/http.py +++ b/src/ytplom/http.py @@ -350,7 +350,7 @@ class _TaskHandler(BaseHTTPRequestHandler): def _send_missing_json(self) -> None: with DbConn() as conn: - missing = [str(f.rel_path) for f in VideoFile.get_all(conn) + missing = [f.digest.b64 for f in VideoFile.get_all(conn) if f.missing] self._send_http(json_dumps(missing), headers=[(_HEADER_CONTENT_TYPE, _HEADER_APP_JSON)])