list.py 1.6 KB

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