From 81b87724da3216817057d6febdf8036bf7dfca65 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 17 Feb 2022 12:34:06 +0100 Subject: vidhar: ... --- hosts/vidhar/borg/copy.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'hosts') diff --git a/hosts/vidhar/borg/copy.py b/hosts/vidhar/borg/copy.py index b99e301a..af876d99 100755 --- a/hosts/vidhar/borg/copy.py +++ b/hosts/vidhar/borg/copy.py @@ -31,8 +31,14 @@ parser.add_argument('source', metavar='REPO_OR_ARCHIVE') parser.add_argument('target', metavar='REPO_OR_ARCHIVE') args = parser.parse_args() +halo_args = { + stream: sys.stderr, + enabled: not sys.stderr.isatty(), + spinner: 'arc' +} + def read_repo(path): - with Halo(text=f'Listing {path}', spinner='arc') as sp: + with Halo(text=f'Listing {path}', **halo_args) as sp: res = None with subprocess.Popen(['borg', 'list', '--info', '--lock-wait', '120', '--json', path], stdout=subprocess.PIPE) as proc: res = json.load(proc.stdout)['archives'] @@ -58,7 +64,7 @@ class ToSync: def copy_archive(src_repo_path, dst_repo_path, entry): cache_suffix = None - with Halo(text=f'Determine archive parameters', spinner='arc') as sp: + with Halo(text=f'Determine archive parameters', **halo_args) as sp: match = re.compile('^(.*)-[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.(checkpoint|recreate)(\.[0-9]+)?)?').fullmatch(entry['name']) if match: repo_id = None @@ -91,7 +97,7 @@ def copy_archive(src_repo_path, dst_repo_path, entry): os.chdir('/') dir = pathlib.Path('/borg') dir.mkdir(parents=True,exist_ok=True) - with Halo(text=f'Determine size', spinner='arc') as sp: + with Halo(text=f'Determine size', **halo_args) as sp: total_size = None total_files = None with subprocess.Popen(['borg', 'info', '--info', '--json', '--lock-wait', '120', f'{src_repo_path}::{entry["name"]}'], stdout=subprocess.PIPE, text=True) as proc: @@ -101,7 +107,7 @@ def copy_archive(src_repo_path, dst_repo_path, entry): sp.succeed(f'{total_files} files, {naturalsize(total_size, binary=True)}') # print(f'Mounting to {dir}', file=stderr) with subprocess.Popen(['borg', 'mount', '--foreground', '--progress', '--lock-wait', '120', f'{src_repo_path}::{entry["name"]}', dir]) as mount_proc: - with Halo(text='Waiting for mount', spinner='arc') as sp: + with Halo(text='Waiting for mount', **halo_args) as sp: wait_start = datetime.now() while True: ret = subprocess.run(['mountpoint', '-q', dir]) -- cgit v1.2.3