remote_db.commit_close()
scp.put(PATH_DB_REMOTE, PATH_DB)
os_remove(PATH_DB_REMOTE)
- for host, port, direction, mover in (
- (config.remote, config.port_remote, 'local->remote', scp.put),
- (config.host, config.port, 'remote->local', scp.get)):
+ missings = []
+ for host, port in ((config.remote, config.port_remote),
+ (config.host, config.port)):
url_missing = f'http://{host}:{port}/{PAGE_NAMES["missing"]}'
with urlopen(url_missing) as response:
- missing = json_loads(response.read())
- for path in (path_join(PATH_DOWNLOADS, path) for path in missing):
+ missings += [json_loads(response.read())]
+ 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_join(PATH_DOWNLOADS, path)
print(f'SYNC: sending {direction} file {path}')
- mover(path, path)
+ mover(full_path, full_path)
scp.close()