2018-05-26 23:19:05 +00:00
|
|
|
import logging
|
2019-04-03 05:30:14 +00:00
|
|
|
|
2019-06-25 17:46:55 +00:00
|
|
|
from borgmatic.borg.flags import make_flags, make_flags_from_arguments
|
2019-06-12 19:13:59 +00:00
|
|
|
from borgmatic.execute import execute_command
|
2018-05-26 23:19:05 +00:00
|
|
|
|
2019-06-17 18:53:08 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2018-05-26 23:19:05 +00:00
|
|
|
|
|
|
|
|
2018-09-30 05:45:00 +00:00
|
|
|
def display_archives_info(
|
2019-06-25 17:46:55 +00:00
|
|
|
repository, storage_config, info_arguments, local_path='borg', remote_path=None
|
2018-09-30 05:45:00 +00:00
|
|
|
):
|
2018-05-26 23:19:05 +00:00
|
|
|
'''
|
2019-06-25 17:46:55 +00:00
|
|
|
Given a local or remote repository path, a storage config dict, and the arguments to the info
|
|
|
|
action, display summary information for Borg archives in the repository or return JSON summary
|
|
|
|
information.
|
2018-05-26 23:19:05 +00:00
|
|
|
'''
|
|
|
|
lock_wait = storage_config.get('lock_wait', None)
|
|
|
|
|
|
|
|
full_command = (
|
2019-09-12 22:27:04 +00:00
|
|
|
(local_path, 'info')
|
2019-06-25 17:46:55 +00:00
|
|
|
+ (
|
|
|
|
('--info',)
|
|
|
|
if logger.getEffectiveLevel() == logging.INFO and not info_arguments.json
|
|
|
|
else ()
|
|
|
|
)
|
|
|
|
+ (
|
|
|
|
('--debug', '--show-rc')
|
|
|
|
if logger.isEnabledFor(logging.DEBUG) and not info_arguments.json
|
|
|
|
else ()
|
|
|
|
)
|
|
|
|
+ make_flags('remote-path', remote_path)
|
|
|
|
+ make_flags('lock-wait', lock_wait)
|
|
|
|
+ make_flags_from_arguments(info_arguments, excludes=('repository', 'archive'))
|
2019-09-12 22:27:04 +00:00
|
|
|
+ (
|
|
|
|
'::'.join((repository, info_arguments.archive))
|
|
|
|
if info_arguments.archive
|
|
|
|
else repository,
|
|
|
|
)
|
2018-05-26 23:19:05 +00:00
|
|
|
)
|
|
|
|
|
2019-06-25 17:46:55 +00:00
|
|
|
return execute_command(
|
2019-12-01 00:55:05 +00:00
|
|
|
full_command,
|
|
|
|
output_log_level=None if info_arguments.json else logging.WARNING,
|
|
|
|
error_on_warnings=False,
|
2019-06-25 17:46:55 +00:00
|
|
|
)
|