Skip to content

Commit

Permalink
Split out processing of alt (past/future)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLocehiliosan committed Sep 27, 2019
1 parent 289b8e0 commit c29292d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 22 deletions.
3 changes: 2 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 27 additions & 9 deletions test/test_alt.py → test/test_compat_alt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions test/test_jinja.py → test/test_compat_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
"""

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion test/test_cygwin_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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),
Expand All @@ -28,7 +30,8 @@
@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:
Expand All @@ -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
Expand Down
36 changes: 28 additions & 8 deletions yadm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c29292d

Please sign in to comment.