2018-05-26 23:19:05 +00:00
|
|
|
import logging
|
2019-04-03 05:30:14 +00:00
|
|
|
|
2022-10-04 05:50:37 +00:00
|
|
|
from borgmatic.borg import environment, feature, flags
|
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(
|
2022-08-12 21:53:20 +00:00
|
|
|
repository,
|
|
|
|
storage_config,
|
|
|
|
local_borg_version,
|
|
|
|
info_arguments,
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
2018-09-30 05:45:00 +00:00
|
|
|
):
|
2018-05-26 23:19:05 +00:00
|
|
|
'''
|
2022-08-12 21:53:20 +00:00
|
|
|
Given a local or remote repository path, a storage config dict, the local Borg version, 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 ()
|
|
|
|
)
|
2022-08-17 22:36:19 +00:00
|
|
|
+ flags.make_flags('remote-path', remote_path)
|
|
|
|
+ flags.make_flags('lock-wait', lock_wait)
|
|
|
|
+ (
|
2022-10-04 05:50:37 +00:00
|
|
|
(
|
|
|
|
flags.make_flags('match-archives', f'sh:{info_arguments.prefix}*')
|
|
|
|
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
|
|
|
else flags.make_flags('glob-archives', f'{info_arguments.prefix}*')
|
|
|
|
)
|
2022-08-17 22:36:19 +00:00
|
|
|
if info_arguments.prefix
|
|
|
|
else ()
|
|
|
|
)
|
|
|
|
+ flags.make_flags_from_arguments(
|
|
|
|
info_arguments, excludes=('repository', 'archive', 'prefix')
|
|
|
|
)
|
2022-08-31 03:42:42 +00:00
|
|
|
+ flags.make_repository_flags(repository, local_borg_version)
|
2022-10-04 05:50:37 +00:00
|
|
|
+ (
|
|
|
|
flags.make_flags('match-archives', info_arguments.archive)
|
|
|
|
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
|
|
|
else flags.make_flags('glob-archives', info_arguments.archive)
|
|
|
|
)
|
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,
|
2020-05-15 05:38:38 +00:00
|
|
|
borg_local_path=local_path,
|
2022-06-30 20:42:17 +00:00
|
|
|
extra_environment=environment.make_environment(storage_config),
|
2019-06-25 17:46:55 +00:00
|
|
|
)
|