From c29292d02b8a444f8917bb9637ee8b787ce86aac Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Fri, 16 Aug 2019 08:19:11 -0500 Subject: [PATCH] Split out processing of alt (past/future) --- pylintrc | 3 +- test/{test_alt.py => test_compat_alt.py} | 36 ++++++++++---- test/{test_jinja.py => test_compat_jinja.py} | 13 +++-- test/test_cygwin_copy.py | 9 +++- yadm | 52 ++++++++++++++------ 5 files changed, 83 insertions(+), 30 deletions(-) rename test/{test_alt.py => test_compat_alt.py} (94%) rename test/{test_jinja.py => test_compat_jinja.py} (94%) diff --git a/pylintrc b/pylintrc index d686a0a..1ced5a6 100644 --- a/pylintrc +++ b/pylintrc @@ -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 diff --git a/test/test_alt.py b/test/test_compat_alt.py similarity index 94% rename from test/test_alt.py rename to test/test_compat_alt.py index 10315ae..466e7fc 100644 --- a/test/test_alt.py +++ b/test/test_compat_alt.py @@ -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, 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, 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, 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): 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): 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, 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): 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): 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) diff --git a/test/test_jinja.py b/test/test_compat_jinja.py similarity index 94% rename from test/test_jinja.py rename to test/test_compat_jinja.py index 54d248a..342d202 100644 --- a/test/test_jinja.py +++ b/test/test_compat_jinja.py @@ -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, 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): 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, 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) diff --git a/test/test_cygwin_copy.py b/test/test_cygwin_copy.py index 82b08ba..92141e3 100644 --- a/test/test_cygwin_copy.py +++ b/test/test_cygwin_copy.py @@ -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 @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( 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 diff --git a/yadm b/yadm index b4e56c1..0918938 100755 --- a/yadm +++ b/yadm @@ -135,31 +135,51 @@ function alt() { require_repo parse_encrypt + local 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 match_class="%" else match_class="$local_class" fi match_class="(%|$match_class)" - - local_system="$(config local.os)" - if [ -z "$local_system" ] ; then - local_system="$OPERATING_SYSTEM" - fi 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)" - - local_user="$(config local.user)" - if [ -z "$local_user" ] ; then - local_user=$(id -u -n) - fi match_user="(%|$local_user)" # regex for matching "##CLASS.SYSTEM.HOSTNAME.USER"