mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 16:49:42 +00:00
Merge branch 'master' of github.com:deadc0de6/dotdrop
This commit is contained in:
3
docs/config/config-dotfiles.md
vendored
3
docs/config/config-dotfiles.md
vendored
@@ -51,8 +51,7 @@ executed when the dotfile is installed (that is, when
|
||||
the version present in dotdrop differs from the one
|
||||
in the filesystem).
|
||||
|
||||
For example, let's consider
|
||||
[Vundle](https://github.com/VundleVim/Vundle.vim), used
|
||||
For example, let's consider Vundle, used
|
||||
to manage Vim's plugins. The following action could
|
||||
be set to update and install the plugins when `vimrc` is
|
||||
deployed:
|
||||
|
||||
14
docs/howto/test-latest-dotdrop.md
vendored
Normal file
14
docs/howto/test-latest-dotdrop.md
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Test latest dotdrop
|
||||
|
||||
If you installed dotdrop from a package but want to test
|
||||
you current setup with the latest version from git
|
||||
(or from a specific branch), you can do the following
|
||||
|
||||
```bash
|
||||
$ cd /tmp/
|
||||
$ git clone https://github.com/deadc0de6/dotdrop.git
|
||||
$ cd dotdrop
|
||||
## switch to a specific branch if needed
|
||||
$ git checkout <branch-name>
|
||||
$ ./dotdrop.sh --cfg <path-to-your-config-file.yaml>
|
||||
```
|
||||
@@ -274,37 +274,48 @@ class CfgAggregator:
|
||||
reloading=reloading,
|
||||
debug=self.debug)
|
||||
|
||||
self.log.dbg('parsing cfgyaml into cfg_aggregator')
|
||||
|
||||
# settings
|
||||
self.log.dbg('parsing settings')
|
||||
self.settings = Settings.parse(None, self.cfgyaml.settings)
|
||||
self.key_prefix = self.settings.key_prefix
|
||||
self.key_separator = self.settings.key_separator
|
||||
|
||||
# dotfiles
|
||||
self.log.dbg('parsing dotfiles')
|
||||
self.dotfiles = Dotfile.parse_dict(self.cfgyaml.dotfiles)
|
||||
debug_list('dotfiles', self.dotfiles, self.debug)
|
||||
|
||||
# profiles
|
||||
self.log.dbg('parsing profiles')
|
||||
self.profiles = Profile.parse_dict(self.cfgyaml.profiles)
|
||||
debug_list('profiles', self.profiles, self.debug)
|
||||
|
||||
# actions
|
||||
self.log.dbg('parsing actions')
|
||||
self.actions = Action.parse_dict(self.cfgyaml.actions)
|
||||
debug_list('actions', self.actions, self.debug)
|
||||
|
||||
# trans_r
|
||||
self.log.dbg('parsing trans_r')
|
||||
self.trans_r = Transform.parse_dict(self.cfgyaml.trans_r)
|
||||
debug_list('trans_r', self.trans_r, self.debug)
|
||||
|
||||
# trans_w
|
||||
self.log.dbg('parsing trans_w')
|
||||
self.trans_w = Transform.parse_dict(self.cfgyaml.trans_w)
|
||||
debug_list('trans_w', self.trans_w, self.debug)
|
||||
|
||||
# variables
|
||||
self.log.dbg('parsing variables')
|
||||
self.variables = self.cfgyaml.variables
|
||||
debug_dict('variables', self.variables, self.debug)
|
||||
|
||||
self.log.dbg('enrich variables')
|
||||
self._enrich_variables()
|
||||
|
||||
self.log.dbg('patch keys...')
|
||||
# patch dotfiles in profiles
|
||||
self._patch_keys_to_objs(self.profiles,
|
||||
"dotfiles", self.get_dotfile)
|
||||
@@ -333,6 +344,8 @@ class CfgAggregator:
|
||||
self._get_trans_w_args(self.get_trans_w),
|
||||
islist=False)
|
||||
|
||||
self.log.dbg('done parsing cfgyaml into cfg_aggregator')
|
||||
|
||||
def _enrich_variables(self):
|
||||
"""
|
||||
enrich available variables
|
||||
|
||||
@@ -256,7 +256,7 @@ class CfgYaml:
|
||||
# process imported variables (import_variables)
|
||||
newvars = self._import_variables()
|
||||
self._clear_profile_vars(newvars)
|
||||
self._add_variables(newvars)
|
||||
self._add_variables(newvars, prio=True)
|
||||
|
||||
# process imported actions (import_actions)
|
||||
self._import_actions()
|
||||
@@ -1042,7 +1042,7 @@ class CfgYaml:
|
||||
if dvar.keys():
|
||||
self._shell_exec_dvars(merged, keys=dvar.keys())
|
||||
self._clear_profile_vars(merged)
|
||||
newvars = self._merge_dict(newvars, merged)
|
||||
newvars = self._merge_dict(merged, newvars)
|
||||
if self._debug:
|
||||
self._debug_dict('imported variables', newvars)
|
||||
return newvars
|
||||
|
||||
@@ -157,6 +157,8 @@ class Options(AttrMonitor):
|
||||
# selected profile
|
||||
self.profile = self.args['--profile']
|
||||
self.confpath = self._get_config_path()
|
||||
self.confpath = os.path.abspath(self.confpath)
|
||||
self.log.dbg(f'config abs path: {self.confpath}')
|
||||
if not self.confpath:
|
||||
raise YamlException('no config file found')
|
||||
if not os.path.exists(self.confpath):
|
||||
|
||||
1
mkdocs.yml
vendored
1
mkdocs.yml
vendored
@@ -43,6 +43,7 @@ nav:
|
||||
- 'Prompt user for variables': 'howto/prompt-user-for-variables.md'
|
||||
- 'Share content across dotfiles': 'howto/sharing-content.md'
|
||||
- 'Symlink dotfiles': 'howto/symlink-dotfiles.md'
|
||||
- 'Test latest dotdrop': 'howto/test-latest-dotdrop.md'
|
||||
- '': ''
|
||||
- '': ''
|
||||
markdown_extensions:
|
||||
|
||||
145
tests-ng/import-variables.sh
vendored
Executable file
145
tests-ng/import-variables.sh
vendored
Executable file
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env bash
|
||||
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||
# Copyright (c) 2023, deadc0de6
|
||||
#
|
||||
# test import_variables
|
||||
# returns 1 in case of error
|
||||
# see issue 380
|
||||
#
|
||||
|
||||
# exit on first error
|
||||
set -e
|
||||
|
||||
# all this crap to get current path
|
||||
rl="readlink -f"
|
||||
if ! ${rl} "${0}" >/dev/null 2>&1; then
|
||||
rl="realpath"
|
||||
|
||||
if ! hash ${rl}; then
|
||||
echo "\"${rl}\" not found !" && exit 1
|
||||
fi
|
||||
fi
|
||||
cur=$(dirname "$(${rl} "${0}")")
|
||||
|
||||
#hash dotdrop >/dev/null 2>&1
|
||||
#[ "$?" != "0" ] && echo "install dotdrop to run tests" && exit 1
|
||||
|
||||
#echo "called with ${1}"
|
||||
|
||||
# dotdrop path can be pass as argument
|
||||
ddpath="${cur}/../"
|
||||
[ "${1}" != "" ] && ddpath="${1}"
|
||||
[ ! -d "${ddpath}" ] && echo "ddpath \"${ddpath}\" is not a directory" && exit 1
|
||||
|
||||
export PYTHONPATH="${ddpath}:${PYTHONPATH}"
|
||||
bin="python3 -m dotdrop.dotdrop"
|
||||
if hash coverage 2>/dev/null; then
|
||||
bin="coverage run -p --source=dotdrop -m dotdrop.dotdrop"
|
||||
fi
|
||||
|
||||
echo "dotdrop path: ${ddpath}"
|
||||
echo "pythonpath: ${PYTHONPATH}"
|
||||
|
||||
# get the helpers
|
||||
# shellcheck source=tests-ng/helpers
|
||||
source "${cur}"/helpers
|
||||
|
||||
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
|
||||
|
||||
################################################################
|
||||
# this is the test
|
||||
################################################################
|
||||
|
||||
# the dotfile source
|
||||
tmps=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
|
||||
mkdir -p "${tmps}"/dotfiles
|
||||
# the dotfile destination
|
||||
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
|
||||
|
||||
clear_on_exit "${tmps}"
|
||||
clear_on_exit "${tmpd}"
|
||||
|
||||
# create the config file
|
||||
cfg="${tmps}/config.yaml"
|
||||
cfgvar1="${tmps}/var1.yaml"
|
||||
cfgvar2="${tmps}/var2.yaml"
|
||||
|
||||
cat << _EOF > "${tmps}/dotfiles/abc"
|
||||
var1: {{@@ var1 @@}}
|
||||
var2: {{@@ var2 @@}}
|
||||
var3: {{@@ var3 @@}}
|
||||
var4: {{@@ var4 @@}}
|
||||
var5: {{@@ var5 @@}}
|
||||
var6: {{@@ var6 @@}}
|
||||
_EOF
|
||||
|
||||
cat > "${cfg}" << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
import_variables:
|
||||
- ${cfgvar1}
|
||||
- ${cfgvar2}
|
||||
variables:
|
||||
var1: "this is var1 from main config"
|
||||
var2: "this is var2 from main config"
|
||||
var3: "this is var3 from main config"
|
||||
dotfiles:
|
||||
f_abc:
|
||||
dst: ${tmpd}/abc
|
||||
src: 'abc'
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_abc
|
||||
_EOF
|
||||
echo "main config: ${cfg}"
|
||||
cat "${cfg}"
|
||||
|
||||
cat << _EOF > "${cfgvar1}"
|
||||
variables:
|
||||
var2: "this is var2 from sub1"
|
||||
var3: "this is var3 from sub1"
|
||||
var4: "this is var4 from sub1"
|
||||
var5: "this is var5 from sub1"
|
||||
_EOF
|
||||
echo "cfgvar1: ${cfgvar1}"
|
||||
cat "${cfgvar1}"
|
||||
|
||||
cat << _EOF > "${cfgvar2}"
|
||||
variables:
|
||||
var3: "this is var3 from sub2"
|
||||
var4: "this is var4 from sub2"
|
||||
var6: "this is var6 from sub2"
|
||||
_EOF
|
||||
echo "cfgvar2: ${cfgvar2}"
|
||||
cat "${cfgvar2}"
|
||||
|
||||
# install
|
||||
cd "${ddpath}" | ${bin} install -f -c "${cfg}" -p p1 --verbose
|
||||
|
||||
# test file existence
|
||||
[ -f "${tmpd}/abc" ] || {
|
||||
echo 'Dotfile not installed'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# test file content
|
||||
cat "${tmpd}"/abc
|
||||
echo "----------------------"
|
||||
grep '^var1: this is var1 from main config$' "${tmpd}"/abc >/dev/null
|
||||
echo "var1 ok"
|
||||
grep '^var2: this is var2 from sub1$' "${tmpd}"/abc >/dev/null
|
||||
echo "var2 ok"
|
||||
grep '^var3: this is var3 from sub2$' "${tmpd}"/abc >/dev/null
|
||||
echo "var3 ok"
|
||||
grep '^var4: this is var4 from sub2$' "${tmpd}"/abc >/dev/null
|
||||
echo "var4 ok"
|
||||
grep '^var5: this is var5 from sub1$' "${tmpd}"/abc >/dev/null
|
||||
echo "var5 ok"
|
||||
grep '^var6: this is var6 from sub2$' "${tmpd}"/abc >/dev/null
|
||||
echo "var6 ok"
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
3
tests-requirements.txt
vendored
3
tests-requirements.txt
vendored
@@ -5,4 +5,5 @@ coveralls; python_version > '3.5'
|
||||
pyflakes; python_version > '3.5'
|
||||
pylint; python_version > '3.5'
|
||||
halo; python_version > '3.5'
|
||||
distro; python_version > '3.5'
|
||||
distro; python_version > '3.5'
|
||||
urllib3; python_version > '3.5'
|
||||
5
tests.sh
vendored
5
tests.sh
vendored
@@ -23,7 +23,10 @@ if [ "${dotdrop_version}" != "${man_version}" ]; then
|
||||
echo "ERROR version.py (${dotdrop_version}) and manpage (${man_version}) differ!"
|
||||
exit 1
|
||||
fi
|
||||
echo "current version ${dotdrop_version}"
|
||||
echo "current dotdrop version ${dotdrop_version}"
|
||||
|
||||
echo "=> python version:"
|
||||
python3 --version
|
||||
|
||||
# test syntax
|
||||
echo "checking syntax..."
|
||||
|
||||
Reference in New Issue
Block a user