Split out processing of alt (past/future)
This commit is contained in:
parent
289b8e0c6c
commit
c29292d02b
5 changed files with 83 additions and 30 deletions
3
pylintrc
3
pylintrc
|
@ -3,9 +3,10 @@ good-names=pytestmark
|
||||||
|
|
||||||
[DESIGN]
|
[DESIGN]
|
||||||
max-args=14
|
max-args=14
|
||||||
max-locals=27
|
max-locals=28
|
||||||
max-attributes=8
|
max-attributes=8
|
||||||
max-statements=65
|
max-statements=65
|
||||||
|
min-similarity-lines=6
|
||||||
|
|
||||||
[MESSAGES CONTROL]
|
[MESSAGES CONTROL]
|
||||||
disable=redefined-outer-name
|
disable=redefined-outer-name
|
||||||
|
|
|
@ -87,7 +87,9 @@ def test_alt(runner, yadm_y, paths,
|
||||||
encrypt=encrypt, exclude=exclude)
|
encrypt=encrypt, exclude=exclude)
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -188,7 +190,9 @@ def test_wild(request, runner, yadm_y, paths,
|
||||||
encrypt=encrypt, exclude=False)
|
encrypt=encrypt, exclude=False)
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -211,7 +215,9 @@ def test_wild(request, runner, yadm_y, paths,
|
||||||
encrypt=encrypt, exclude=False)
|
encrypt=encrypt, exclude=False)
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -249,7 +255,9 @@ def test_local_override(runner, yadm_y, paths,
|
||||||
paths, '##or-class.or-os.or-hostname.or-user')
|
paths, '##or-class.or-os.or-hostname.or-user')
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -287,7 +295,9 @@ def test_class_case(runner, yadm_y, paths, tst_sys, suffix):
|
||||||
utils.create_alt_files(paths, f'##{ending}')
|
utils.create_alt_files(paths, f'##{ending}')
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -320,7 +330,9 @@ def test_auto_alt(runner, yadm_y, paths, autoalt):
|
||||||
utils.create_alt_files(paths, suffix)
|
utils.create_alt_files(paths, suffix)
|
||||||
|
|
||||||
# run status to possibly trigger linking
|
# run status to possibly trigger linking
|
||||||
run = runner(yadm_y('status'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('status'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -356,7 +368,9 @@ def test_delimiter(runner, yadm_y, paths,
|
||||||
utils.create_alt_files(paths, suffix)
|
utils.create_alt_files(paths, suffix)
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -396,7 +410,9 @@ def test_invalid_links_removed(runner, yadm_y, paths):
|
||||||
utils.create_alt_files(paths, f'##{tst_class}')
|
utils.create_alt_files(paths, f'##{tst_class}')
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
||||||
|
@ -418,7 +434,9 @@ def test_invalid_links_removed(runner, yadm_y, paths):
|
||||||
utils.set_local(paths, 'class', 'changedclass')
|
utils.set_local(paths, 'class', 'changedclass')
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = linked_list(run.out)
|
linked = linked_list(run.out)
|
|
@ -50,7 +50,9 @@ def test_local_override(runner, yadm_y, paths,
|
||||||
# os.system(f'find {paths.work}' + ' -name *j2 -ls -exec cat \'{}\' ";"')
|
# os.system(f'find {paths.work}' + ' -name *j2 -ls -exec cat \'{}\' ";"')
|
||||||
# os.system(f'find {paths.work}')
|
# os.system(f'find {paths.work}')
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
created = created_list(run.out)
|
created = created_list(run.out)
|
||||||
|
@ -83,7 +85,9 @@ def test_auto_alt(runner, yadm_y, paths, autoalt, tst_sys,
|
||||||
utils.create_alt_files(paths, jinja_suffix, content='{{ YADM_OS }}')
|
utils.create_alt_files(paths, jinja_suffix, content='{{ YADM_OS }}')
|
||||||
|
|
||||||
# run status to possibly trigger linking
|
# run status to possibly trigger linking
|
||||||
run = runner(yadm_y('status'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('status'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
created = created_list(run.out)
|
created = created_list(run.out)
|
||||||
|
@ -111,6 +115,7 @@ def test_jinja_envtpl_missing(runner, paths):
|
||||||
process_global_args -Y "{paths.yadm}"
|
process_global_args -Y "{paths.yadm}"
|
||||||
set_operating_system
|
set_operating_system
|
||||||
configure_paths
|
configure_paths
|
||||||
|
YADM_COMPATIBILITY=1
|
||||||
ENVTPL_PROGRAM='envtpl_missing' main alt
|
ENVTPL_PROGRAM='envtpl_missing' main alt
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -170,7 +175,9 @@ def test_jinja(runner, yadm_y, paths,
|
||||||
includefile=True)
|
includefile=True)
|
||||||
|
|
||||||
# run alt to trigger linking
|
# run alt to trigger linking
|
||||||
run = runner(yadm_y('alt'))
|
env = os.environ.copy()
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
created = created_list(run.out)
|
created = created_list(run.out)
|
|
@ -4,6 +4,8 @@ import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'compatibility', [True, False], ids=['compat', 'no-compat'])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'setting, is_cygwin, expect_link, pre_existing', [
|
'setting, is_cygwin, expect_link, pre_existing', [
|
||||||
(None, False, True, None),
|
(None, False, True, None),
|
||||||
|
@ -28,7 +30,8 @@ import pytest
|
||||||
@pytest.mark.usefixtures('ds1_copy')
|
@pytest.mark.usefixtures('ds1_copy')
|
||||||
def test_cygwin_copy(
|
def test_cygwin_copy(
|
||||||
runner, yadm_y, paths, cygwin_sys, tst_sys,
|
runner, yadm_y, paths, cygwin_sys, tst_sys,
|
||||||
setting, is_cygwin, expect_link, pre_existing):
|
setting, is_cygwin, expect_link, pre_existing,
|
||||||
|
compatibility):
|
||||||
"""Test yadm.cygwin_copy"""
|
"""Test yadm.cygwin_copy"""
|
||||||
|
|
||||||
if setting is not None:
|
if setting is not None:
|
||||||
|
@ -49,6 +52,10 @@ def test_cygwin_copy(
|
||||||
expected_content = f'test_cygwin_copy##{cygwin_sys}'
|
expected_content = f'test_cygwin_copy##{cygwin_sys}'
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['PATH'] = ':'.join([str(uname_path), env['PATH']])
|
env['PATH'] = ':'.join([str(uname_path), env['PATH']])
|
||||||
|
if compatibility:
|
||||||
|
env['YADM_COMPATIBILITY'] = '1'
|
||||||
|
else:
|
||||||
|
pytest.xfail('Alternates 2.0.0 has not been implemented.')
|
||||||
|
|
||||||
run = runner(yadm_y('alt'), env=env)
|
run = runner(yadm_y('alt'), env=env)
|
||||||
assert run.success
|
assert run.success
|
||||||
|
|
52
yadm
52
yadm
|
@ -135,31 +135,51 @@ function alt() {
|
||||||
require_repo
|
require_repo
|
||||||
parse_encrypt
|
parse_encrypt
|
||||||
|
|
||||||
|
local local_class
|
||||||
local_class="$(config local.class)"
|
local_class="$(config local.class)"
|
||||||
|
|
||||||
|
local local_system
|
||||||
|
local_system="$(config local.os)"
|
||||||
|
if [ -z "$local_system" ] ; then
|
||||||
|
local_system="$OPERATING_SYSTEM"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local local_host
|
||||||
|
local_host="$(config local.hostname)"
|
||||||
|
if [ -z "$local_host" ] ; then
|
||||||
|
local_host=$(hostname)
|
||||||
|
local_host=${local_host%%.*} # trim any domain from hostname
|
||||||
|
fi
|
||||||
|
|
||||||
|
local local_user
|
||||||
|
local_user="$(config local.user)"
|
||||||
|
if [ -z "$local_user" ] ; then
|
||||||
|
local_user=$(id -u -n)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$YADM_COMPATIBILITY" = "1" ]; then
|
||||||
|
alt_past
|
||||||
|
else
|
||||||
|
alt_future
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function alt_future() {
|
||||||
|
# Future alternate processing, not implemented yet
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
function alt_past() {
|
||||||
|
|
||||||
if [ -z "$local_class" ] ; then
|
if [ -z "$local_class" ] ; then
|
||||||
match_class="%"
|
match_class="%"
|
||||||
else
|
else
|
||||||
match_class="$local_class"
|
match_class="$local_class"
|
||||||
fi
|
fi
|
||||||
match_class="(%|$match_class)"
|
match_class="(%|$match_class)"
|
||||||
|
|
||||||
local_system="$(config local.os)"
|
|
||||||
if [ -z "$local_system" ] ; then
|
|
||||||
local_system="$OPERATING_SYSTEM"
|
|
||||||
fi
|
|
||||||
match_system="(%|$local_system)"
|
match_system="(%|$local_system)"
|
||||||
|
|
||||||
local_host="$(config local.hostname)"
|
|
||||||
if [ -z "$local_host" ] ; then
|
|
||||||
local_host=$(hostname)
|
|
||||||
local_host=${local_host%%.*} # trim any domain from hostname
|
|
||||||
fi
|
|
||||||
match_host="(%|$local_host)"
|
match_host="(%|$local_host)"
|
||||||
|
|
||||||
local_user="$(config local.user)"
|
|
||||||
if [ -z "$local_user" ] ; then
|
|
||||||
local_user=$(id -u -n)
|
|
||||||
fi
|
|
||||||
match_user="(%|$local_user)"
|
match_user="(%|$local_user)"
|
||||||
|
|
||||||
# regex for matching "<file>##CLASS.SYSTEM.HOSTNAME.USER"
|
# regex for matching "<file>##CLASS.SYSTEM.HOSTNAME.USER"
|
||||||
|
|
Loading…
Reference in a new issue