Răsfoiți Sursa

feat: syncing routine is now nextcloud compatible (remove reliance on rclone m5sum)

Noah Vogt 1 săptămână în urmă
părinte
comite
4591ad8532
4 a modificat fișierele cu 7 adăugiri și 75 ștergeri
  1. 1 2
      ssync.py
  2. 0 1
      sync/__init__.py
  3. 0 41
      sync/save_new_checkfile.py
  4. 6 31
      sync/syncing_needed.py

+ 1 - 2
ssync.py

@@ -30,14 +30,13 @@ from input import (
     parse_ssync_args_as_tuple,
     parse_ssync_args_as_tuple,
     SsyncFlags,
     SsyncFlags,
 )
 )
-from sync import sync_slide_repo, save_new_checkfile, syncing_needed
+from sync import sync_slide_repo, syncing_needed
 
 
 
 
 def ssync(ssync_flags: SsyncFlags, slide_style: SlideStyle) -> None:
 def ssync(ssync_flags: SsyncFlags, slide_style: SlideStyle) -> None:
     validate_ssync_config()
     validate_ssync_config()
     if syncing_needed(ssync_flags.offline_enabled):
     if syncing_needed(ssync_flags.offline_enabled):
         sync_slide_repo()
         sync_slide_repo()
-        save_new_checkfile()
     clear_obs_slides_dir()
     clear_obs_slides_dir()
     slide_selection_iterator(ssync_flags.disable_async_enabled, slide_style)
     slide_selection_iterator(ssync_flags.disable_async_enabled, slide_style)
 
 

+ 0 - 1
sync/__init__.py

@@ -14,5 +14,4 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 from .sync_slide_repo import sync_slide_repo
 from .sync_slide_repo import sync_slide_repo
-from .save_new_checkfile import save_new_checkfile
 from .syncing_needed import syncing_needed
 from .syncing_needed import syncing_needed

+ 0 - 41
sync/save_new_checkfile.py

@@ -1,41 +0,0 @@
-# Copyright © 2024 Noah Vogt <noah@noahvogt.com>
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-from os import system, path
-
-import shutil
-
-from utils import log, expand_dir, error_msg
-
-import config as const
-
-
-def save_new_checkfile() -> None:
-    cache_dir = expand_dir(const.SSYNC_CACHE_DIR)
-    log("saving new checkfile...")
-    system(
-        'rclone md5sum "{}" > "{}"'.format(
-            const.RCLONE_REMOTE_DIR,
-            path.join(cache_dir, const.SSYNC_CHECKFILE_NAMING),
-        )
-    )
-    try:
-        if not path.isfile(path.join(cache_dir, const.SSYNC_CACHEFILE_NAMING)):
-            shutil.copyfile(
-                path.join(cache_dir, const.SSYNC_CHECKFILE_NAMING),
-                path.join(cache_dir, const.SSYNC_CACHEFILE_NAMING),
-            )
-    except (FileNotFoundError, PermissionError, IOError) as error:
-        error_msg("Failed to save new checkfile. Reason: {}".format(error))

+ 6 - 31
sync/syncing_needed.py

@@ -14,10 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 import os
 import os
-import re
-
 from utils import log
 from utils import log
-
 import config as const
 import config as const
 
 
 
 
@@ -26,35 +23,13 @@ def syncing_needed(offline_flag_enabled: bool) -> bool:
         log("skipping sync with remote", color="cyan")
         log("skipping sync with remote", color="cyan")
         return False
         return False
 
 
-    if not cachefiles_found():
-        return True
-
     log("checking for remote changes...")
     log("checking for remote changes...")
-    os.system(
-        'rclone md5sum "{}" --checkfile "{}" > "{}" 2> "{}"'.format(
-            const.RCLONE_REMOTE_DIR,
-            os.path.join(const.SSYNC_CACHE_DIR, const.SSYNC_CHECKFILE_NAMING),
-            os.devnull,
-            os.path.join(const.SSYNC_CACHE_DIR, const.SSYNC_CACHEFILE_NAMING),
+
+    exit_code = os.system(
+        'rclone check "{}" "{}" --one-way --quiet'.format(
+            const.RCLONE_REMOTE_DIR, const.RCLONE_LOCAL_DIR
         )
         )
     )
     )
 
 
-    with open(
-        os.path.join(const.SSYNC_CACHE_DIR, const.SSYNC_CACHEFILE_NAMING),
-        mode="r",
-        encoding="utf-8-sig",
-    ) as cachefile_reader:
-        cachefile_content = cachefile_reader.readlines()
-    for line in cachefile_content:
-        if re.search(": ([0-9])+ differences found$", line):
-            diffs = int(line[line.rfind(":") + 1 : line.find("differences")])
-            return bool(diffs)
-    return False
-
-
-def cachefiles_found() -> bool:
-    return os.path.isfile(
-        os.path.join(const.SSYNC_CACHE_DIR, const.SSYNC_CHECKFILE_NAMING)
-    ) and os.path.isfile(
-        os.path.join(const.SSYNC_CACHE_DIR, const.SSYNC_CACHEFILE_NAMING)
-    )
+    # rclone check returns 0 when every file is identical
+    return exit_code != 0