home · contact · privacy
From sync script, remove no-longer-necessary ID name differentiation. master
authorChristian Heller <c.heller@plomlompom.de>
Sun, 1 Dec 2024 07:48:57 +0000 (08:48 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 1 Dec 2024 07:48:57 +0000 (08:48 +0100)
src/sync.py

index 641e78ca7e8d72693f0176876755877b0e4715f8..494118812d3125083a57aa90993c4006c43e649f 100755 (executable)
@@ -21,7 +21,7 @@ ATTR_NAME_LAST_UPDATE = 'last_update'
 
 def back_and_forth(sync_func: Callable,
                    dbs: tuple[DbConn, DbConn],
 
 def back_and_forth(sync_func: Callable,
                    dbs: tuple[DbConn, DbConn],
-                   shared: YoutubeVideo | tuple[Any, str]
+                   shared: Any
                    ) -> None:
     """Run sync_func on arg pairs + shared, and again with pairs switched."""
     host_names = 'local', 'remote'
                    ) -> None:
     """Run sync_func on arg pairs + shared, and again with pairs switched."""
     host_names = 'local', 'remote'
@@ -31,10 +31,9 @@ def back_and_forth(sync_func: Callable,
 
 def sync_objects(host_names: tuple[str, str],
                  dbs: tuple[DbConn, DbConn],
 
 def sync_objects(host_names: tuple[str, str],
                  dbs: tuple[DbConn, DbConn],
-                 shared: tuple[Any, str]
+                 cls: Any
                  ) -> None:
     """Equalize both DB's object collections; prefer newer states to older."""
                  ) -> None:
     """Equalize both DB's object collections; prefer newer states to older."""
-    cls, _ = shared
     id_name = 'id_' if 'id' == cls.id_name else cls.id_name
     obj_colls = cls.get_all(dbs[0]), cls.get_all(dbs[1])
     for obj_0 in [obj for obj in obj_colls[0] if obj not in obj_colls[1]]:
     id_name = 'id_' if 'id' == cls.id_name else cls.id_name
     obj_colls = cls.get_all(dbs[0]), cls.get_all(dbs[1])
     for obj_0 in [obj for obj in obj_colls[0] if obj not in obj_colls[1]]:
@@ -80,8 +79,7 @@ def main():
     scp.get(PATH_DB, PATH_DB_REMOTE)
     with DbConn(PATH_DB) as db_local, DbConn(PATH_DB_REMOTE) as db_remote:
         for cls in (QuotaLog, YoutubeQuery, YoutubeVideo, VideoFile):
     scp.get(PATH_DB, PATH_DB_REMOTE)
     with DbConn(PATH_DB) as db_local, DbConn(PATH_DB_REMOTE) as db_remote:
         for cls in (QuotaLog, YoutubeQuery, YoutubeVideo, VideoFile):
-            back_and_forth(sync_objects, (db_local, db_remote),
-                           (cls, 'rel_path' if cls is VideoFile else 'id_'))
+            back_and_forth(sync_objects, (db_local, db_remote), cls)
         for yt_video_local in YoutubeVideo.get_all(db_local):
             back_and_forth(sync_relations, (db_local, db_remote),
                            yt_video_local)
         for yt_video_local in YoutubeVideo.get_all(db_local):
             back_and_forth(sync_relations, (db_local, db_remote),
                            yt_video_local)