Browse Source

Split out processing of alt (past/future)

pull/174/head
Tim Byrne 3 years ago
parent
commit
c29292d02b
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
  1. 3
      pylintrc
  2. 36
      test/test_compat_alt.py
  3. 13
      test/test_compat_jinja.py
  4. 9
      test/test_cygwin_copy.py
  5. 36
      yadm

3
pylintrc

@ -3,9 +3,10 @@ good-names=pytestmark @@ -3,9 +3,10 @@ good-names=pytestmark
[DESIGN]
max-args=14
max-locals=27
max-locals=28
max-attributes=8
max-statements=65
min-similarity-lines=6
[MESSAGES CONTROL]
disable=redefined-outer-name

36
test/test_alt.py → test/test_compat_alt.py

@ -87,7 +87,9 @@ def test_alt(runner, yadm_y, paths, @@ -87,7 +87,9 @@ def test_alt(runner, yadm_y, paths,
encrypt=encrypt, exclude=exclude)
# 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.err == ''
linked = linked_list(run.out)
@ -188,7 +190,9 @@ def test_wild(request, runner, yadm_y, paths, @@ -188,7 +190,9 @@ def test_wild(request, runner, yadm_y, paths,
encrypt=encrypt, exclude=False)
# 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.err == ''
linked = linked_list(run.out)
@ -211,7 +215,9 @@ def test_wild(request, runner, yadm_y, paths, @@ -211,7 +215,9 @@ def test_wild(request, runner, yadm_y, paths,
encrypt=encrypt, exclude=False)
# 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.err == ''
linked = linked_list(run.out)
@ -249,7 +255,9 @@ def test_local_override(runner, yadm_y, paths, @@ -249,7 +255,9 @@ def test_local_override(runner, yadm_y, paths,
paths, '##or-class.or-os.or-hostname.or-user')
# 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.err == ''
linked = linked_list(run.out)
@ -287,7 +295,9 @@ def test_class_case(runner, yadm_y, paths, tst_sys, suffix): @@ -287,7 +295,9 @@ def test_class_case(runner, yadm_y, paths, tst_sys, suffix):
utils.create_alt_files(paths, f'##{ending}')
# 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.err == ''
linked = linked_list(run.out)
@ -320,7 +330,9 @@ def test_auto_alt(runner, yadm_y, paths, autoalt): @@ -320,7 +330,9 @@ def test_auto_alt(runner, yadm_y, paths, autoalt):
utils.create_alt_files(paths, suffix)
# 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.err == ''
linked = linked_list(run.out)
@ -356,7 +368,9 @@ def test_delimiter(runner, yadm_y, paths, @@ -356,7 +368,9 @@ def test_delimiter(runner, yadm_y, paths,
utils.create_alt_files(paths, suffix)
# 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.err == ''
linked = linked_list(run.out)
@ -396,7 +410,9 @@ def test_invalid_links_removed(runner, yadm_y, paths): @@ -396,7 +410,9 @@ def test_invalid_links_removed(runner, yadm_y, paths):
utils.create_alt_files(paths, f'##{tst_class}')
# 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.err == ''
linked = linked_list(run.out)
@ -418,7 +434,9 @@ def test_invalid_links_removed(runner, yadm_y, paths): @@ -418,7 +434,9 @@ def test_invalid_links_removed(runner, yadm_y, paths):
utils.set_local(paths, 'class', 'changedclass')
# 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.err == ''
linked = linked_list(run.out)

13
test/test_jinja.py → test/test_compat_jinja.py

@ -50,7 +50,9 @@ def test_local_override(runner, yadm_y, paths, @@ -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}')
# 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.err == ''
created = created_list(run.out)
@ -83,7 +85,9 @@ def test_auto_alt(runner, yadm_y, paths, autoalt, tst_sys, @@ -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 }}')
# 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.err == ''
created = created_list(run.out)
@ -111,6 +115,7 @@ def test_jinja_envtpl_missing(runner, paths): @@ -111,6 +115,7 @@ def test_jinja_envtpl_missing(runner, paths):
process_global_args -Y "{paths.yadm}"
set_operating_system
configure_paths
YADM_COMPATIBILITY=1
ENVTPL_PROGRAM='envtpl_missing' main alt
"""
@ -170,7 +175,9 @@ def test_jinja(runner, yadm_y, paths, @@ -170,7 +175,9 @@ def test_jinja(runner, yadm_y, paths,
includefile=True)
# 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.err == ''
created = created_list(run.out)

9
test/test_cygwin_copy.py

@ -4,6 +4,8 @@ import os @@ -4,6 +4,8 @@ import os
import pytest
@pytest.mark.parametrize(
'compatibility', [True, False], ids=['compat', 'no-compat'])
@pytest.mark.parametrize(
'setting, is_cygwin, expect_link, pre_existing', [
(None, False, True, None),
@ -28,7 +30,8 @@ import pytest @@ -28,7 +30,8 @@ import pytest
@pytest.mark.usefixtures('ds1_copy')
def test_cygwin_copy(
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"""
if setting is not None:
@ -49,6 +52,10 @@ def test_cygwin_copy( @@ -49,6 +52,10 @@ def test_cygwin_copy(
expected_content = f'test_cygwin_copy##{cygwin_sys}'
env = os.environ.copy()
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)
assert run.success

36
yadm

@ -135,31 +135,51 @@ function alt() { @@ -135,31 +135,51 @@ function alt() {
require_repo
parse_encrypt
local local_class
local_class="$(config local.class)"
if [ -z "$local_class" ] ; then
match_class="%"
else
match_class="$local_class"
fi
match_class="(%|$match_class)"
local local_system
local_system="$(config local.os)"
if [ -z "$local_system" ] ; then
local_system="$OPERATING_SYSTEM"
fi
match_system="(%|$local_system)"
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
match_host="(%|$local_host)"
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
match_class="%"
else
match_class="$local_class"
fi
match_class="(%|$match_class)"
match_system="(%|$local_system)"
match_host="(%|$local_host)"
match_user="(%|$local_user)"
# regex for matching "<file>##CLASS.SYSTEM.HOSTNAME.USER"

Loading…
Cancel
Save