mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 17:24:46 +00:00
@@ -15,6 +15,7 @@ Entry | Description | Default
|
||||
`banner` | Display the banner | true
|
||||
`check_version` | Check if a new version of dotdrop is available on github | false
|
||||
`chmod_on_import` | Always add a chmod entry on newly imported dotfiles (see `--preserve-mode`) | false
|
||||
`clear_workdir` | On `install` clear the `workdir` before installing dotfiles (see `--workdir-clear`) | false
|
||||
`cmpignore` | List of patterns to ignore when comparing, applied to all dotfiles (enclose in quotes when using wildcards; see [ignore patterns](config.md#ignore-patterns)) | -
|
||||
`create` | Create a directory hierarchy when installing dotfiles if it doesn't exist | true
|
||||
`default_actions` | List of action keys to execute for all installed dotfiles (See [actions](config-details.md#actions-entry)) | -
|
||||
|
||||
@@ -87,6 +87,7 @@ Some available options:
|
||||
Note that actions are not executed in this mode.
|
||||
* `-a`/`--force-actions`: Force the execution of actions even if the dotfiles are not installed
|
||||
* `-f`/`--force`: Do not ask for any confirmation
|
||||
* `-W`/`--workdir-clear`: Clear the `workdir` before installing dotfiles (see config entry `clear_workdir`)
|
||||
|
||||
To ignore specific patterns during installation, see [the ignore patterns](config.md#ignore-patterns).
|
||||
|
||||
|
||||
@@ -317,6 +317,14 @@ def cmd_install(opts):
|
||||
|
||||
installed = []
|
||||
|
||||
# clear the workdir
|
||||
if opts.install_clear_workdir and not opts.dry:
|
||||
LOG.dbg('clearing the workdir under {}'.format(opts.workdir))
|
||||
for root, _, files in os.walk(opts.workdir):
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
removepath(fpath, logger=LOG)
|
||||
|
||||
# execute profile pre-action
|
||||
LOG.dbg('run {} profile pre actions'.format(len(pro_pre_actions)))
|
||||
templ = _get_templater(opts)
|
||||
|
||||
@@ -56,18 +56,18 @@ USAGE = """
|
||||
{}
|
||||
|
||||
Usage:
|
||||
dotdrop install [-VbtfndDa] [-c <path>] [-p <profile>]
|
||||
[-w <nb>] [<key>...]
|
||||
dotdrop import [-Vbdfm] [-c <path>] [-p <profile>] [-s <path>]
|
||||
[-l <link>] [-i <pattern>...] <path>...
|
||||
dotdrop compare [-LVbz] [-c <path>] [-p <profile>]
|
||||
[-w <nb>] [-C <file>...] [-i <pattern>...]
|
||||
dotdrop update [-VbfdkPz] [-c <path>] [-p <profile>]
|
||||
[-w <nb>] [-i <pattern>...] [<path>...]
|
||||
dotdrop remove [-Vbfdk] [-c <path>] [-p <profile>] [<path>...]
|
||||
dotdrop files [-VbTG] [-c <path>] [-p <profile>]
|
||||
dotdrop detail [-Vb] [-c <path>] [-p <profile>] [<key>...]
|
||||
dotdrop profiles [-VbG] [-c <path>]
|
||||
dotdrop install [-VbtfndDaW] [-c <path>] [-p <profile>]
|
||||
[-w <nb>] [<key>...]
|
||||
dotdrop import [-Vbdfm] [-c <path>] [-p <profile>] [-s <path>]
|
||||
[-l <link>] [-i <pattern>...] <path>...
|
||||
dotdrop compare [-LVbz] [-c <path>] [-p <profile>]
|
||||
[-w <nb>] [-C <file>...] [-i <pattern>...]
|
||||
dotdrop update [-VbfdkPz] [-c <path>] [-p <profile>]
|
||||
[-w <nb>] [-i <pattern>...] [<path>...]
|
||||
dotdrop remove [-Vbfdk] [-c <path>] [-p <profile>] [<path>...]
|
||||
dotdrop files [-VbTG] [-c <path>] [-p <profile>]
|
||||
dotdrop detail [-Vb] [-c <path>] [-p <profile>] [<key>...]
|
||||
dotdrop profiles [-VbG] [-c <path>]
|
||||
dotdrop --help
|
||||
dotdrop --version
|
||||
|
||||
@@ -93,6 +93,7 @@ Options:
|
||||
-T --template Only template dotfiles.
|
||||
-V --verbose Be verbose.
|
||||
-w --workers=<nb> Number of concurrent workers [default: 1].
|
||||
-W --workdir-clear Clear the workdir.
|
||||
-z --ignore-missing Ignore files in installed folders that are missing.
|
||||
-v --version Show version.
|
||||
-h --help Show this screen.
|
||||
@@ -132,6 +133,7 @@ class Options(AttrMonitor):
|
||||
self.link_on_import = None
|
||||
self.chmod_on_import = None
|
||||
self.check_version = None
|
||||
self.clear_workdir = None
|
||||
|
||||
# args parsing
|
||||
self.args = {}
|
||||
@@ -244,6 +246,8 @@ class Options(AttrMonitor):
|
||||
if a.kind == Action.post]
|
||||
self.install_ignore = self.instignore
|
||||
self.install_force_chmod = self.force_chmod
|
||||
self.install_clear_workdir = self.args['--workdir-clear'] or \
|
||||
self.clear_workdir
|
||||
|
||||
def _apply_args_compare(self):
|
||||
"""compare specifics"""
|
||||
|
||||
@@ -46,6 +46,7 @@ class Settings(DictParser):
|
||||
key_ignore_missing_in_dotdrop = 'ignore_missing_in_dotdrop'
|
||||
key_chmod_on_import = 'chmod_on_import'
|
||||
key_check_version = 'check_version'
|
||||
key_clear_workdir = 'clear_workdir'
|
||||
|
||||
# import keys
|
||||
key_import_actions = 'import_actions'
|
||||
@@ -65,9 +66,8 @@ class Settings(DictParser):
|
||||
diff_command='diff -r -u {0} {1}',
|
||||
template_dotfile_default=True,
|
||||
ignore_missing_in_dotdrop=False,
|
||||
force_chmod=False,
|
||||
chmod_on_import=False,
|
||||
check_version=False):
|
||||
force_chmod=False, chmod_on_import=False,
|
||||
check_version=False, clear_workdir=False):
|
||||
self.backup = backup
|
||||
self.banner = banner
|
||||
self.create = create
|
||||
@@ -98,6 +98,7 @@ class Settings(DictParser):
|
||||
self.force_chmod = force_chmod
|
||||
self.chmod_on_import = chmod_on_import
|
||||
self.check_version = check_version
|
||||
self.clear_workdir = clear_workdir
|
||||
|
||||
def _serialize_seq(self, name, dic):
|
||||
"""serialize attribute 'name' into 'dic'"""
|
||||
@@ -125,6 +126,7 @@ class Settings(DictParser):
|
||||
self.key_force_chmod: self.force_chmod,
|
||||
self.key_chmod_on_import: self.chmod_on_import,
|
||||
self.key_check_version: self.check_version,
|
||||
self.key_clear_workdir: self.clear_workdir,
|
||||
}
|
||||
self._serialize_seq(self.key_default_actions, dic)
|
||||
self._serialize_seq(self.key_import_actions, dic)
|
||||
|
||||
133
tests-ng/clear-workdir.sh
Executable file
133
tests-ng/clear-workdir.sh
Executable file
@@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env bash
|
||||
# author: deadc0de6 (https://github.com/deadc0de6)
|
||||
# Copyright (c) 2021, deadc0de6
|
||||
#
|
||||
# test clear_workdir
|
||||
# returns 1 in case of error
|
||||
#
|
||||
|
||||
# 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"
|
||||
hash coverage 2>/dev/null && bin="coverage run -a --source=dotdrop -m dotdrop.dotdrop" || true
|
||||
|
||||
echo "dotdrop path: ${ddpath}"
|
||||
echo "pythonpath: ${PYTHONPATH}"
|
||||
|
||||
# get the helpers
|
||||
source ${cur}/helpers
|
||||
|
||||
echo -e "$(tput setaf 6)==> RUNNING $(basename $BASH_SOURCE) <==$(tput sgr0)"
|
||||
|
||||
################################################################
|
||||
# this is the test
|
||||
################################################################
|
||||
|
||||
# dotdrop directory
|
||||
basedir=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
mkdir -p ${basedir}/dotfiles
|
||||
echo "[+] dotdrop dir: ${basedir}"
|
||||
echo "[+] dotpath dir: ${basedir}/dotfiles"
|
||||
tmpd=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
if [ -z "${DOTDROP_WORKDIR}" ]; then
|
||||
tmpw=`mktemp -d --suffix='-dotdrop-tests' || mktemp -d`
|
||||
export DOTDROP_WORKDIR="${tmpw}"
|
||||
clear_on_exit "${tmpw}"
|
||||
fi
|
||||
|
||||
clear_on_exit "${basedir}"
|
||||
clear_on_exit "${tmpd}"
|
||||
|
||||
echo "{{@@ profile @@}}" > ${basedir}/dotfiles/x
|
||||
|
||||
# create the config file
|
||||
cfg="${basedir}/config.yaml"
|
||||
cat > ${cfg} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
dotfiles:
|
||||
f_x:
|
||||
src: x
|
||||
dst: ${tmpd}/x
|
||||
link: link
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_x
|
||||
_EOF
|
||||
|
||||
echo "[+] install (1)"
|
||||
cd ${ddpath} | ${bin} install -c ${cfg} -f -p p1 --verbose | grep '^1 dotfile(s) installed.$'
|
||||
[ "$?" != "0" ] && exit 1
|
||||
|
||||
[ ! -e ${tmpd}/x ] && echo "f_x not installed" && exit 1
|
||||
[ ! -h ${tmpd}/x ] && echo "f_x not symlink" && exit 1
|
||||
[ ! -e ${DOTDROP_WORKDIR}/${tmpd}/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1
|
||||
|
||||
# add file
|
||||
touch ${DOTDROP_WORKDIR}/new
|
||||
|
||||
echo "[+] re-install with clear-workdir in cli"
|
||||
cd ${ddpath} | printf "y\n" | ${bin} install -W -c ${cfg} -p p1 --verbose
|
||||
[ "$?" != "0" ] && exit 1
|
||||
|
||||
[ ! -e ${tmpd}/x ] && echo "f_x not installed" && exit 1
|
||||
[ ! -h ${tmpd}/x ] && echo "f_x not symlink" && exit 1
|
||||
[ ! -e ${DOTDROP_WORKDIR}/${tmpd}/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1
|
||||
[ -e ${DOTDROP_WORKDIR}/new ] && echo "workdir not cleared (1)" && exit 1
|
||||
|
||||
# add file
|
||||
touch ${DOTDROP_WORKDIR}/new
|
||||
|
||||
echo "[+] re-install with config clear-workdir in config"
|
||||
cat > ${cfg} << _EOF
|
||||
config:
|
||||
backup: true
|
||||
create: true
|
||||
dotpath: dotfiles
|
||||
clear_workdir: true
|
||||
dotfiles:
|
||||
f_x:
|
||||
src: x
|
||||
dst: ${tmpd}/x
|
||||
link: link
|
||||
profiles:
|
||||
p1:
|
||||
dotfiles:
|
||||
- f_x
|
||||
_EOF
|
||||
cd ${ddpath} | printf "y\n" | ${bin} install -W -c ${cfg} -p p1 --verbose
|
||||
[ "$?" != "0" ] && exit 1
|
||||
|
||||
[ ! -e ${tmpd}/x ] && echo "f_x not installed" && exit 1
|
||||
[ ! -h ${tmpd}/x ] && echo "f_x not symlink" && exit 1
|
||||
[ ! -e ${DOTDROP_WORKDIR}/${tmpd}/x ] && echo "f_x not in workdir (${DOTDROP_WORKDIR}/${tmpd})" && exit 1
|
||||
[ -e ${DOTDROP_WORKDIR}/new ] && echo "workdir not cleared (2)" && exit 1
|
||||
|
||||
echo "OK"
|
||||
exit 0
|
||||
13
tests.sh
13
tests.sh
@@ -82,7 +82,8 @@ fi
|
||||
unset DOTDROP_DEBUG=
|
||||
export DOTDROP_FORCE_NODEBUG=yes
|
||||
|
||||
export DOTDROP_WORKDIR=/tmp/dotdrop-tests-workdir
|
||||
tmpworkdir="/tmp/dotdrop-tests-workdir"
|
||||
export DOTDROP_WORKDIR="${tmpworkdir}"
|
||||
|
||||
if [ ! -z ${workers} ]; then
|
||||
DOTDROP_WORKERS=${workers}
|
||||
@@ -90,8 +91,8 @@ if [ ! -z ${workers} ]; then
|
||||
fi
|
||||
|
||||
# run bash tests
|
||||
workdir_tmp="no"
|
||||
[ -d "~/.config/dotdrop/tmp" ] && workdir_tmp="yes"
|
||||
workdir_tmp_exists="no"
|
||||
[ -d "~/.config/dotdrop/tmp" ] && workdir_tmp_exists="yes"
|
||||
if [ -z ${GITHUB_WORKFLOW} ]; then
|
||||
## local
|
||||
export COVERAGE_FILE=
|
||||
@@ -101,7 +102,11 @@ else
|
||||
export COVERAGE_FILE="${cur}/.coverage"
|
||||
tests-ng/tests-launcher.py 1
|
||||
fi
|
||||
[ "${workdir_tmp}" = "no" ] && rm -rf ~/.config/dotdrop/tmp
|
||||
|
||||
# clear workdir
|
||||
[ "${workdir_tmp_exists}" = "no" ] && rm -rf ~/.config/dotdrop/tmp
|
||||
# clear temp workdir
|
||||
rm -rf "${tmpworkdir}"
|
||||
|
||||
## test the doc with remark
|
||||
## https://github.com/remarkjs/remark-validate-links
|
||||
|
||||
@@ -136,6 +136,7 @@ def _fake_args():
|
||||
args['--workers'] = 1
|
||||
args['--preserve-mode'] = False
|
||||
args['--ignore-missing'] = False
|
||||
args['--workdir-clear'] = False
|
||||
# cmds
|
||||
args['profiles'] = False
|
||||
args['files'] = False
|
||||
|
||||
Reference in New Issue
Block a user