- local_db, remote_db = DbConnection(PATH_DB), DbConnection(PATH_DB_REMOTE)
- for cls in (QuotaLog, YoutubeQuery, YoutubeVideo, VideoFile):
- back_and_forth(sync_objects, (local_db, remote_db),
- (cls, 'rel_path' if cls is VideoFile else 'id_'))
- for yt_video_local in YoutubeVideo.get_all(local_db):
- back_and_forth(sync_relations, (local_db, remote_db), yt_video_local)
- local_db.commit_close()
- remote_db.commit_close()
+ 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_'))
+ for yt_video_local in YoutubeVideo.get_all(db_local):
+ back_and_forth(sync_relations, (db_local, db_remote),
+ yt_video_local)
+ db_remote.commit()
+ db_local.commit()