yt_result.save_to_query(dbs[1], q.id_)
-def main():
- """Connect to remote, sync local+remote DBs, + downloads where missing."""
- config = Config()
- ssh = SSHClient()
- ssh.load_system_host_keys()
- ssh.connect(config.remote)
- scp = SCPClient(ssh.get_transport())
+def sync_dbs(scp: SCPClient) -> None:
+ """Download remote DB, run sync_(objects|relations), put remote DB back."""
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):
db_local.commit()
scp.put(PATH_DB_REMOTE, PATH_DB)
PATH_DB_REMOTE.unlink()
+
+
+def fill_missing(scp: SCPClient, config: Config) -> None:
+ """Between config.host and .remote, fill files listed in as missing."""
missings = []
for host, port in ((config.remote, config.port_remote),
(config.host, config.port)):
full_path = PATH_DOWNLOADS.joinpath(path)
print(f'SYNC: sending {direction} file {path}')
mover(full_path, full_path)
- scp.close()
+
+
+def main():
+ """Connect to remote, sync local+remote DBs, + downloads where missing."""
+ config = Config()
+ ssh = SSHClient()
+ ssh.load_system_host_keys()
+ ssh.connect(config.remote)
+ with SCPClient(ssh.get_transport()) as scp:
+ sync_dbs(scp)
+ fill_missing(scp, config)
if __name__ == '__main__':