2022-08-12 23:59:03 +02:00
|
|
|
import logging
|
|
|
|
|
2022-12-02 21:12:10 +01:00
|
|
|
import borgmatic.logger
|
2022-08-14 07:07:15 +02:00
|
|
|
from borgmatic.borg import environment, feature, flags
|
2022-10-15 01:19:26 +02:00
|
|
|
from borgmatic.execute import execute_command, execute_command_and_capture_output
|
2022-08-12 23:59:03 +02:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def display_repository_info(
|
2023-03-26 20:22:25 +02:00
|
|
|
repository_path,
|
2022-08-12 23:59:03 +02:00
|
|
|
storage_config,
|
|
|
|
local_borg_version,
|
|
|
|
rinfo_arguments,
|
|
|
|
local_path='borg',
|
|
|
|
remote_path=None,
|
|
|
|
):
|
|
|
|
'''
|
|
|
|
Given a local or remote repository path, a storage config dict, the local Borg version, and the
|
|
|
|
arguments to the rinfo action, display summary information for the Borg repository or return
|
|
|
|
JSON summary information.
|
|
|
|
'''
|
2022-12-02 21:12:10 +01:00
|
|
|
borgmatic.logger.add_custom_log_levels()
|
2022-08-12 23:59:03 +02:00
|
|
|
lock_wait = storage_config.get('lock_wait', None)
|
|
|
|
|
|
|
|
full_command = (
|
|
|
|
(local_path,)
|
|
|
|
+ (
|
|
|
|
('rinfo',)
|
|
|
|
if feature.available(feature.Feature.RINFO, local_borg_version)
|
|
|
|
else ('info',)
|
|
|
|
)
|
|
|
|
+ (
|
|
|
|
('--info',)
|
|
|
|
if logger.getEffectiveLevel() == logging.INFO and not rinfo_arguments.json
|
|
|
|
else ()
|
|
|
|
)
|
|
|
|
+ (
|
|
|
|
('--debug', '--show-rc')
|
|
|
|
if logger.isEnabledFor(logging.DEBUG) and not rinfo_arguments.json
|
|
|
|
else ()
|
|
|
|
)
|
2022-08-14 07:07:15 +02:00
|
|
|
+ flags.make_flags('remote-path', remote_path)
|
|
|
|
+ flags.make_flags('lock-wait', lock_wait)
|
2022-08-12 23:59:03 +02:00
|
|
|
+ (('--json',) if rinfo_arguments.json else ())
|
2023-03-26 20:22:25 +02:00
|
|
|
+ flags.make_repository_flags(repository_path, local_borg_version)
|
2022-08-12 23:59:03 +02:00
|
|
|
)
|
|
|
|
|
2022-10-15 01:19:26 +02:00
|
|
|
extra_environment = environment.make_environment(storage_config)
|
|
|
|
|
|
|
|
if rinfo_arguments.json:
|
|
|
|
return execute_command_and_capture_output(
|
|
|
|
full_command, extra_environment=extra_environment,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
execute_command(
|
|
|
|
full_command,
|
2022-12-02 21:12:10 +01:00
|
|
|
output_log_level=logging.ANSWER,
|
2022-10-15 01:19:26 +02:00
|
|
|
borg_local_path=local_path,
|
|
|
|
extra_environment=extra_environment,
|
|
|
|
)
|