2018-05-26 23:19:05 +00:00
|
|
|
import logging
|
2019-04-03 05:30:14 +00:00
|
|
|
|
2022-12-02 20:12:10 +00:00
|
|
|
import borgmatic.logger
|
2022-10-04 05:50:37 +00:00
|
|
|
from borgmatic.borg import environment, feature, flags
|
2022-10-14 23:19:26 +00:00
|
|
|
from borgmatic.execute import execute_command, execute_command_and_capture_output
|
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(
|
2023-03-26 18:22:25 +00:00
|
|
|
repository_path,
|
2022-08-12 21:53:20 +00:00
|
|
|
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
|
|
|
'''
|
2022-12-02 20:12:10 +00:00
|
|
|
borgmatic.logger.add_custom_log_levels()
|
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
|
2023-03-31 22:21:08 +00:00
|
|
|
else (
|
|
|
|
flags.make_match_archives_flags(
|
2023-04-05 04:25:10 +00:00
|
|
|
info_arguments.match_archives
|
|
|
|
or info_arguments.archive
|
|
|
|
or storage_config.get('match_archives'),
|
2023-04-02 06:57:55 +00:00
|
|
|
storage_config.get('archive_name_format'),
|
|
|
|
local_borg_version,
|
2023-03-31 22:21:08 +00:00
|
|
|
)
|
|
|
|
)
|
2022-08-17 22:36:19 +00:00
|
|
|
)
|
|
|
|
+ flags.make_flags_from_arguments(
|
2023-04-05 04:25:10 +00:00
|
|
|
info_arguments, excludes=('repository', 'archive', 'prefix', 'match_archives')
|
2022-08-17 22:36:19 +00:00
|
|
|
)
|
2023-03-26 18:22:25 +00:00
|
|
|
+ flags.make_repository_flags(repository_path, local_borg_version)
|
2018-05-26 23:19:05 +00:00
|
|
|
)
|
|
|
|
|
2022-10-14 23:19:26 +00:00
|
|
|
if info_arguments.json:
|
|
|
|
return execute_command_and_capture_output(
|
2023-04-15 02:35:24 +00:00
|
|
|
full_command,
|
|
|
|
extra_environment=environment.make_environment(storage_config),
|
2022-10-14 23:19:26 +00:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
execute_command(
|
|
|
|
full_command,
|
2022-12-02 20:12:10 +00:00
|
|
|
output_log_level=logging.ANSWER,
|
2022-10-14 23:19:26 +00:00
|
|
|
borg_local_path=local_path,
|
|
|
|
extra_environment=environment.make_environment(storage_config),
|
|
|
|
)
|