From b05b361dd4cef2bdade8a8ba386e522a0ea91e8f Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 May 2024 22:22:06 -0500 Subject: [PATCH] added prune module --- src/restic/prune.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/restic/prune.py diff --git a/src/restic/prune.py b/src/restic/prune.py new file mode 100644 index 0000000..3d9128e --- /dev/null +++ b/src/restic/prune.py @@ -0,0 +1,33 @@ +import logging +import re +import subprocess + +from restic.console import console, logger + + +def main(dry_run: bool = False): + cmd = ['restic', 'prune'] + if dry_run: + cmd.append('-n') + logger.debug(f'Running cmd [bright_black]{" ".join(cmd)}[/]') + + with console.status('Pruning...'): + result = subprocess.run(cmd, capture_output=True, text=True) + + if m := re.search(r'total prune:\s+(.*?)$', result.stdout, re.MULTILINE): + pruned_data = m.group(1).split(' / ')[1] + logger.info(f'Pruned {pruned_data}') + + if m := re.search(r'remaining:\s+(.*?)$', result.stdout, re.MULTILINE): + remaining = m.group(1).split(' / ')[1] + logger.info(f'{remaining} remaining') + + +if __name__ == '__main__': + from rich.logging import RichHandler + + logging.basicConfig( + level='DEBUG', format='%(message)s', handlers=[RichHandler(markup=True, console=console)] + ) + + main()