From 733c9c7501f48f98946d40230a1b94397c35c51e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 17 Feb 2022 12:43:40 +0100 Subject: vidhar: ... --- hosts/vidhar/borg/copy.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'hosts/vidhar') diff --git a/hosts/vidhar/borg/copy.py b/hosts/vidhar/borg/copy.py index 679c9ad1..db907297 100755 --- a/hosts/vidhar/borg/copy.py +++ b/hosts/vidhar/borg/copy.py @@ -33,17 +33,20 @@ parser.add_argument('target', metavar='REPO_OR_ARCHIVE') args = parser.parse_args() halo_args = { - 'stream': sys.stderr, - 'enabled': sys.stderr.isatty(), + 'stream': stderr, + 'enabled': stderr.isatty(), 'spinner': 'arc' } def read_repo(path): 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: + with subprocess.Popen(['borg', 'list', '--debug', '--lock-wait', '120', '--json', path], stdout=subprocess.PIPE) as proc: res = json.load(proc.stdout)['archives'] - sp.succeed(f'{len(res)} archives in {path}') + if sp.enabled: + sp.succeed(f'{len(res)} archives in {path}') + else: + print(f'{len(res)} archives in {path}', file=stderr) return res class ToSync: @@ -73,7 +76,10 @@ def copy_archive(src_repo_path, dst_repo_path, entry): repo_id = json.load(proc.stdout)['repository']['id'] if repo_id: cache_suffix = f'{repo_id}_{match.group(1)}' - sp.succeed(f'Will process {entry["name"]} ({dateutil.parser.isoparse(entry["start"])}, cache_suffix={cache_suffix})') + if sp.enabled: + sp.succeed(f'Will process {entry["name"]} ({dateutil.parser.isoparse(entry["start"])}, cache_suffix={cache_suffix})') + else: + print(f'Will process {entry["name"]} ({dateutil.parser.isoparse(entry["start"])}, cache_suffix={cache_suffix})', file=stderr) with TemporaryDirectory(prefix=f'borg-mount_{entry["name"]}_') as tmpdir: child = os.fork() if child == 0: @@ -105,7 +111,10 @@ def copy_archive(src_repo_path, dst_repo_path, entry): stats = json.load(proc.stdout)['archives'][0]['stats'] total_size = stats['original_size'] total_files = stats['nfiles'] - sp.succeed(f'{total_files} files, {naturalsize(total_size, binary=True)}') + if sp.enabled: + sp.succeed(f'{total_files} files, {naturalsize(total_size, binary=True)}') + else: + print(f'{total_files} files, {naturalsize(total_size, binary=True)}', file=stderr) # 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', **halo_args) as sp: @@ -117,7 +126,10 @@ def copy_archive(src_repo_path, dst_repo_path, entry): elif datetime.now() - wait_start > timedelta(minutes=10): ret.check_returncode() sleep(0.1) - sp.succeed('Mounted') + if sp.enabled: + sp.succeed('Mounted') + else: + print('Mounted', file=stderr) while True: try: with tqdm(total=total_size, unit_scale=True, unit_divisor=1024, unit='B', smoothing=0.01, disable=None, dynamic_ncols=True, maxinterval=0.5, miniters=1) as progress: -- cgit v1.2.3