info.py 961 B

12345678910111213141516171819202122232425262728
  1. import logging
  2. from borgmatic.borg.execute import execute_command
  3. from borgmatic.logger import get_logger
  4. logger = get_logger(__name__)
  5. def display_archives_info(
  6. repository, storage_config, local_path='borg', remote_path=None, json=False
  7. ):
  8. '''
  9. Given a local or remote repository path, and a storage config dict, display summary information
  10. for Borg archives in the repository or return JSON summary information.
  11. '''
  12. lock_wait = storage_config.get('lock_wait', None)
  13. full_command = (
  14. (local_path, 'info', repository)
  15. + (('--remote-path', remote_path) if remote_path else ())
  16. + (('--lock-wait', str(lock_wait)) if lock_wait else ())
  17. + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
  18. + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
  19. + (('--json',) if json else ())
  20. )
  21. return execute_command(full_command, capture_output=json)