[Feature] Add label variable interpolation in hook context #861
|
@ -286,6 +286,7 @@ def run_actions(
|
|||
global_arguments = arguments['global']
|
||||
dry_run_label = ' (dry run; not making any changes)' if global_arguments.dry_run else ''
|
||||
hook_context = {
|
||||
'repository_label': repository.get('label', ''),
|
||||
codimp marked this conversation as resolved
Outdated
|
||||
'repository': repository_path,
|
||||
# Deprecated: For backwards compatibility with borgmatic < 1.6.0.
|
||||
'repositories': ','.join([repo['path'] for repo in config['repositories']]),
|
||||
|
|
|
@ -84,6 +84,8 @@ variables you can use here:
|
|||
path of the borgmatic log file, only set when the `--log-file` flag is used
|
||||
* `repository`: path of the current repository as configured in the current
|
||||
borgmatic configuration file
|
||||
* `repository_label`: current repository label as configured in the current
|
||||
codimp marked this conversation as resolved
Outdated
witten
commented
Sorry, another thing I think I mentioned on IRC.. What do you think of calling this Sorry, another thing I think I mentioned on IRC.. What do you think of calling this `repository_label` instead of just `label`?
codimp
commented
oups, right, my bad! oups, right, my bad!
|
||||
borgmatic configuration file
|
||||
|
||||
Note that you can also interpolate in [arbitrary environment
|
||||
variables](https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/).
|
||||
|
|
|
@ -494,10 +494,15 @@ def test_run_actions_adds_log_file_to_hook_context():
|
|||
expected = flexmock()
|
||||
flexmock(borgmatic.actions.create).should_receive('run_create').with_args(
|
||||
config_filename=object,
|
||||
repository={'path': 'repo'},
|
||||
repository={'path': 'repo', 'label': ''},
|
||||
config={'repositories': []},
|
||||
config_paths=[],
|
||||
hook_context={'repository': 'repo', 'repositories': '', 'log_file': 'foo'},
|
||||
hook_context={
|
||||
'repository': 'repo',
|
||||
'repository_label': '',
|
||||
'repositories': '',
|
||||
'log_file': 'foo',
|
||||
},
|
||||
local_borg_version=object,
|
||||
create_arguments=object,
|
||||
global_arguments=object,
|
||||
|
@ -515,7 +520,7 @@ def test_run_actions_adds_log_file_to_hook_context():
|
|||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
repository={'path': 'repo'},
|
||||
repository={'path': 'repo', 'label': ''},
|
||||
)
|
||||
)
|
||||
assert result == (expected,)
|
||||
|
|
Loading…
Reference in New Issue
Block a user
You could simplify this all to just:
repository_label = repository.get('label', '')
It could even be inline below without the temporary variable. (Do not feel strongly.)
Good idea!