mirror of
https://github.com/TheLocehiliosan/yadm
synced 2025-06-04 00:23:58 +00:00
Add support for "seed" template (#435)
The file will only be created from the template the first run. On subsequent runs it will not be updated, even if the template has changed.
This commit is contained in:
parent
4214de8d91
commit
bbb58e6625
@ -195,6 +195,49 @@ def test_alt_template_with_condition(runner, paths, tst_arch):
|
||||
assert len(created) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("ds1_copy")
|
||||
@pytest.mark.parametrize("kind", ["default", None, "envtpl", "j2", "esh"])
|
||||
@pytest.mark.parametrize(
|
||||
"label",
|
||||
[
|
||||
"s",
|
||||
"seed",
|
||||
],
|
||||
)
|
||||
def test_alt_seed(runner, paths, kind, label):
|
||||
"""Test template seed"""
|
||||
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
|
||||
|
||||
suffix = f"##{label}.{kind}"
|
||||
if kind is None:
|
||||
suffix = f"##{label}"
|
||||
|
||||
utils.create_alt_files(paths, suffix, content="first")
|
||||
run = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "alt"])
|
||||
assert run.success
|
||||
assert run.err == ""
|
||||
|
||||
utils.create_alt_files(paths, suffix, preserve=True, content="second")
|
||||
run2 = runner([paths.pgm, "-Y", yadm_dir, "--yadm-data", yadm_data, "alt"])
|
||||
assert run2.success
|
||||
assert run2.err == ""
|
||||
|
||||
created = utils.parse_alt_output(run.out, linked=False)
|
||||
created2 = utils.parse_alt_output(run2.out, linked=False)
|
||||
assert len(created2) == 0
|
||||
|
||||
for created_path in TEST_PATHS:
|
||||
source_file_content = created_path + suffix
|
||||
source_file = paths.work.join(source_file_content)
|
||||
created_file = paths.work.join(created_path)
|
||||
if created_path == utils.ALT_DIR:
|
||||
source_file = source_file.join(utils.CONTAINED)
|
||||
created_file = created_file.join(utils.CONTAINED)
|
||||
assert created_file.isfile()
|
||||
assert created_file.read().strip() == source_file_content + "\nfirst"
|
||||
assert str(source_file) in created
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("ds1_copy")
|
||||
@pytest.mark.parametrize("autoalt", [None, "true", "false"])
|
||||
def test_auto_alt(runner, yadm_cmd, paths, autoalt):
|
||||
|
8
yadm
8
yadm
@ -222,17 +222,17 @@ function score_file() {
|
||||
# extension isn't a condition and doesn't affect the score
|
||||
continue
|
||||
;;
|
||||
t | template | yadm)
|
||||
s | seed | t | template | yadm)
|
||||
if ((negate)); then
|
||||
INVALID_ALT+=("$source")
|
||||
else
|
||||
elif [ "${label:0:1}" != "s" ] || [ ! -e "$target" ]; then
|
||||
template_processor=$(choose_template_processor "$value")
|
||||
if [ -n "$template_processor" ]; then
|
||||
delta=0
|
||||
elif [ -n "$loud" ]; then
|
||||
echo "No supported template processor for template $source"
|
||||
echo "No supported template processor for $source"
|
||||
else
|
||||
debug "No supported template processor for template $source"
|
||||
debug "No supported template processor for $source"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
4
yadm.1
4
yadm.1
@ -492,6 +492,10 @@ These are the supported attributes, in the order of the weighted precedence:
|
||||
Valid when the value matches a supported template processor.
|
||||
See the TEMPLATES section for more details.
|
||||
.TP
|
||||
.BR seed ,\ s
|
||||
Same as template, but only valid if the target file doesn't exist. I.e. the
|
||||
file will be "seeded" from the template on the first run.
|
||||
.TP
|
||||
.BR user ,\ u
|
||||
Valid if the value matches the current user.
|
||||
Current user is calculated by running
|
||||
|
Loading…
Reference in New Issue
Block a user