list.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import json
  2. import logging
  3. import borgmatic.borg.list
  4. import borgmatic.config.validate
  5. logger = logging.getLogger(__name__)
  6. def run_list(
  7. repository,
  8. storage,
  9. local_borg_version,
  10. list_arguments,
  11. global_arguments,
  12. local_path,
  13. remote_path,
  14. ):
  15. '''
  16. Run the "list" action for the given repository and archive.
  17. If list_arguments.json is True, yield the JSON output from listing the archive.
  18. '''
  19. if list_arguments.repository is None or borgmatic.config.validate.repositories_match(
  20. repository, list_arguments.repository
  21. ):
  22. if not list_arguments.json: # pragma: nocover
  23. if list_arguments.find_paths:
  24. logger.answer(f'{repository.get("label", repository["path"])}: Searching archives')
  25. elif not list_arguments.archive:
  26. logger.answer(f'{repository.get("label", repository["path"])}: Listing archives')
  27. list_arguments.archive = borgmatic.borg.rlist.resolve_archive_name(
  28. repository['path'],
  29. list_arguments.archive,
  30. storage,
  31. local_borg_version,
  32. global_arguments,
  33. local_path,
  34. remote_path,
  35. )
  36. json_output = borgmatic.borg.list.list_archive(
  37. repository['path'],
  38. storage,
  39. local_borg_version,
  40. list_arguments,
  41. global_arguments,
  42. local_path,
  43. remote_path,
  44. )
  45. if json_output: # pragma: nocover
  46. yield json.loads(json_output)