Files
2023-02-18 07:39:08 +01:00

47 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import logging
import subprocess
import sys
import time
from pathlib import Path
def find_file_arg(argv: list[str]) -> Path:
for it in argv:
if it.startswith('-'):
continue
if Path(it).is_file():
return Path(it)
def main():
argv = sys.argv[1:]
file_path = find_file_arg(argv)
if not file_path:
logging.error('file argument not passed')
return
size = file_path.stat().st_size
while True:
args = ['rsync', '--recursive', '--human-readable', '--progress', '--partial', *argv]
logging.debug(f'running rsync with {args=}')
p = subprocess.run(args)
p.check_returncode()
logging.debug('will check the file size in 20s')
time.sleep(20)
subprocess.run(['touch', str(file_path)])
new_size = file_path.stat().st_size
if new_size == size:
logging.info('file size has not changed, stopping')
break
logging.info(f'file size has changed {new_size - size} bytes, re-syncing')
size = new_size
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
main()