From fa1be9d29c1e200272b8963c5d65467dd6c1d2b0 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 31 May 2022 18:24:30 +0200 Subject: [PATCH] update doc and tests for link --- completion/dotdrop.fish | 4 ++-- docs/config-config.md | 6 +++--- docs/config-dotfiles.md | 6 +++--- docs/config-file.md | 3 ++- docs/config-transformations.md | 2 +- docs/howto/symlink-dotfiles.md | 12 ++++++------ docs/templating.md | 2 +- dotdrop/dotdrop.py | 4 ++-- dotdrop/options.py | 5 +++-- scripts/change-link.py | 8 ++------ tests-ng/chmod-import.sh | 4 ++-- tests-ng/deprecated-link.sh | 2 +- tests-ng/link-import-default.sh | 2 +- tests-ng/link-value-tests.sh | 10 +++++----- tests-ng/minversion.sh | 2 +- tests/test_yamlcfg.py | 9 ++++++--- 16 files changed, 41 insertions(+), 40 deletions(-) diff --git a/completion/dotdrop.fish b/completion/dotdrop.fish index de0e5de..59fdd95 100644 --- a/completion/dotdrop.fish +++ b/completion/dotdrop.fish @@ -72,7 +72,7 @@ set -l f -s f -l force -d "Do not ask user confirmation for anything." set -l G -s G -l grepable -d "Grepable output." set -l i -s i -l ignore -d "Pattern to ignore." set -l k -s k -l key -d "Treat as a dotfile key." -set -l l -s l -l link -d "Link option (nolink|link|link_children)." +set -l l -s l -l link -d "Link option (nolink|absolute|relative|link_children)." set -l L -s L -l file-only -d "Do not show diff but only the files that differ." set -l m -s m -l preserve-mode -d "Insert a chmod entry in the dotfile with its mode." set -l n -s n -l nodiff -d "Do not diff when installing." @@ -91,7 +91,7 @@ set -l h -s h -l help -d "Show this screen." set -al c -rF set -al C -rF set -al i -x -set -al l -x -a "nolink link link_children" +set -al l -x -a "nolink absolute relative link_children" set -al p -x -a "(__fish_dotdrop_list_profiles)" set -al s -rF set -al w -x diff --git a/docs/config-config.md b/docs/config-config.md index fca9f9a..ac0413c 100644 --- a/docs/config-config.md +++ b/docs/config-config.md @@ -28,14 +28,14 @@ Entry | Description | Default `keepdot` | Preserve leading dot when importing hidden file in the `dotpath` | false `key_prefix` | Prefix dotfile key on `import` with `f` for file and `d` for directory | true `key_separator` | Separator to use on dotfile key generation on `import` | `_` -`link_dotfile_default` | Set a dotfile's `link` attribute to this value when undefined. Possible values: *nolink*, *link* (See [Symlinking dotfiles](config-file.md#symlinking-dotfiles)) | `nolink` -`link_on_import` | Set a dotfile's `link` attribute to this value when importing. Possible values: *nolink*, *link* [Symlinking dotfiles](config-file.md#symlinking-dotfiles)) | `nolink` +`link_dotfile_default` | Set a dotfile's `link` attribute to this value when undefined. Possible values: *nolink*, *absolute*, *relative* (See [Symlinking dotfiles](config-file.md#symlinking-dotfiles)) | `nolink` +`link_on_import` | Set a dotfile's `link` attribute to this value when importing. Possible values: *nolink*, *absolute*, *relative* [Symlinking dotfiles](config-file.md#symlinking-dotfiles)) | `nolink` `longkey` | Use long keys for dotfiles when importing (See [Import dotfiles](usage.md#import-dotfiles)) | false `minversion` | (*for internal use, do not modify*) Provides the minimal dotdrop version to use | - `showdiff` | On install, show a diff before asking to overwrite (See `--showdiff`) | false `template_dotfile_default` | Disable templating on all dotfiles when set to false | true `upignore` | List of patterns to ignore when updating, appled to all dotfiles (enclose in quotes when using wildcards; see [ignore patterns](config-file.md#ignore-patterns)) | - -`workdir` | Path to the directory where templates are installed before being symlinked when using `link:link` or `link:link_children` (absolute path or relative to the config file location) | `~/.config/dotdrop` +`workdir` | Path to the directory where templates are installed before being symlinked when using `link:absolute|relative|link_children` (absolute path or relative to the config file location) | `~/.config/dotdrop` link_by_default | When importing a dotfile, set `link` to this value by default | false diff --git a/docs/config-dotfiles.md b/docs/config-dotfiles.md index c9c5c49..8cebb1b 100644 --- a/docs/config-dotfiles.md +++ b/docs/config-dotfiles.md @@ -6,7 +6,7 @@ Entry | Description -------- | ------------- `dst` | Where this dotfile needs to be deployed (dotfiles with empty `dst` are ignored and considered installed, can use `variables`, make sure to quote) `src` | Dotfile path within the `dotpath` (dotfiles with empty `src` are ignored and considered installed, can use `variables`, make sure to quote) -`link` | Defines how this dotfile is installed. Possible values: *nolink*, *link*, *link_children* (See [Symlinking dotfiles](config-file.md#symlinking-dotfiles)) (defaults to value of `link_dotfile_default`) +`link` | Defines how this dotfile is installed. Possible values: *nolink*, *absolute*, *relative*, *link_children* (See [Symlinking dotfiles](config-file.md#symlinking-dotfiles)) (defaults to value of `link_dotfile_default`) `actions` | List of action keys that need to be defined in the **actions** entry below (See [actions](config-actions.md)) `chmod` | Defines the file permissions in octal notation to apply during installation (See [permissions](config-file.md#permissions)) `cmpignore` | List of patterns to ignore when comparing (enclose in quotes when using wildcards; see [ignore patterns](config-file.md#ignore-patterns)) @@ -25,7 +25,7 @@ Entry | Description dst: src: ## Optional - link: (nolink|link|link_children) + link: (nolink|absolute|relative|link_children) ignoreempty: (true|false) cmpignore: - "" @@ -209,7 +209,7 @@ profiles: dotfiles: - f_test variables: - link_value: "link" + link_value: "absolute" windows: dotfiles: - f_test diff --git a/docs/config-file.md b/docs/config-file.md index 3ebac4c..0865d19 100644 --- a/docs/config-file.md +++ b/docs/config-file.md @@ -119,7 +119,8 @@ Dotdrop is able to install dotfiles in three different ways, which are controlled by the `link` config attribute of each dotfile: * `link: nolink`: The dotfile (file or directory) is copied to its destination -* `link: link`: The dotfile (file or directory) is symlinked to its destination +* `link: absolute`: The dotfile (file or directory) is linked to its destination using an absolute symlink +* `link: relative`: The dotfile (file or directory) is linked to its destination using a relative symlink * `link: link_children`: The files/directories found under the dotfile (directory) are symlinked to their destination For more, see [this how-to](howto/symlink-dotfiles.md). diff --git a/docs/config-transformations.md b/docs/config-transformations.md index 955f940..e78d6b8 100644 --- a/docs/config-transformations.md +++ b/docs/config-transformations.md @@ -30,7 +30,7 @@ There are two types of transformations available: A typical use-case for transformations is when dotfiles need to be stored encrypted or compressed. For more, see [the howto](howto/howto.md). -Note that transformations cannot be used if the dotfile is to be linked (when `link: link` or `link: link_children`). +Note that transformations cannot be used if the dotfile is to be linked (when `link: absolute|relative|link_children`). Transformations also support additional positional arguments that must start from 2 (since `{0}` and `{1}` are added automatically). The transformations themselves as well as their arguments can also be templated. diff --git a/docs/howto/symlink-dotfiles.md b/docs/howto/symlink-dotfiles.md index 0e17beb..9353728 100644 --- a/docs/howto/symlink-dotfiles.md +++ b/docs/howto/symlink-dotfiles.md @@ -3,7 +3,7 @@ Dotdrop offers two ways to symlink a dotfile through its config entry `link`: -* Setting `link: link` for a dotfile will symlink `dst` to `src` +* Setting `link: absolute` or `link: relative` for a dotfile will symlink `dst` to `src` * Setting `link: link_children` will, for every direct child of `src`, symlink `dst/` to `src/` (See [Link children](#link-children)) where `src` is the file stored in your *dotpath* and @@ -28,13 +28,13 @@ $ dotdrop import ~/.bashrc -> "/home/user/.bashrc" imported ``` -Edit the `config.yaml` and set the `link` value to `link`: +Edit the `config.yaml` and set the `link` value to `absolute`: ```yaml dotfiles: f_bashrc: src: bashrc dst: ~/.bashrc - link: link + link: absolute ``` Install the dotfile, which will remove your `~/.bashrc` and replace it with a link to the file stored in dotdrop: @@ -64,7 +64,7 @@ Setting this option on a file that is not a directory will make any operation on A good example of its use is when managing `~/.vim` with dotdrop. -Here's what it looks like when using `link: link`: +Here's what it looks like when using `link: absolute`: ```yaml config: dotpath: dotfiles @@ -72,7 +72,7 @@ dotfiles: vim: dst: ~/.vim src: vim - link: link + link: absolute ``` The top directory `~/.vim` is symlinked to the `/vim` location: @@ -126,7 +126,7 @@ to dotdrop's `dotpath` directory (see [the config file doc](../config-file.md)). When using templating directives, however, the dotfiles are first installed into `workdir` (defaults to *~/.config/dotdrop*; see [the doc](../config-config.md)) and then symlinked there. -This applies to both dotfiles with `link: link` and `link: link_children`. +This applies to both dotfiles with `link: absolute|relative` and `link: link_children`. For example: ```bash diff --git a/docs/templating.md b/docs/templating.md index c81dd55..296cf54 100644 --- a/docs/templating.md +++ b/docs/templating.md @@ -14,7 +14,7 @@ Obviously, if the dotfile uses template directives, it needs to be templated. Ho is not, disabling templating will speed up its installation (since it won't have to be processed by the engine). -For dotfiles being symlinked (`link` or `link_children`), see +For dotfiles being symlinked (`absolute`, `relative` or `link_children`), see [the dedicated doc](howto/symlink-dotfiles.md#templating-symlinked-dotfiles). ## Delimiters diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 7d636d8..a53c034 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -224,7 +224,7 @@ def _dotfile_install(opts, dotfile, tmpdir=None): LinkTypes.LINK, LinkTypes.LINK_CHILDREN, LinkTypes.RELATIVE, LinkTypes.ABSOLUTE ): - # link|relative|absolute|link_children + # nolink|relative|absolute|link_children ret, err = inst.install(templ, dotfile.src, dotfile.dst, dotfile.link, actionexec=pre_actions_exec, @@ -645,7 +645,7 @@ def cmd_remove(opts): k = dotfile.key # ignore if uses any type of link if dotfile.link != LinkTypes.NOLINK: - msg = '{} uses link/link_children, remove manually' + msg = '{} uses symlink, remove manually' LOG.warn(msg.format(k)) continue diff --git a/dotdrop/options.py b/dotdrop/options.py index 57495de..9f1fa38 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -43,7 +43,8 @@ ETCCFG = '/etc/{}'.format(NAME) OPT_LINK = { LinkTypes.NOLINK.name.lower(): LinkTypes.NOLINK, - LinkTypes.LINK.name.lower(): LinkTypes.LINK, + LinkTypes.ABSOLUTE.name.lower(): LinkTypes.ABSOLUTE, + LinkTypes.RELATIVE.name.lower(): LinkTypes.RELATIVE, LinkTypes.LINK_CHILDREN.name.lower(): LinkTypes.LINK_CHILDREN} BANNER = r""" _ _ _ @@ -82,7 +83,7 @@ Options: -G --grepable Grepable output. -i --ignore= Pattern to ignore. -k --key Treat as a dotfile key. - -l --link= Link option (nolink|link|link_children). + -l --link= Link option (nolink|absolute|relative|link_children). -L --file-only Do not show diff but only the files that differ. -m --preserve-mode Insert a chmod entry in the dotfile with its mode. -n --nodiff Do not diff when installing. diff --git a/scripts/change-link.py b/scripts/change-link.py index ec75312..e67b284 100755 --- a/scripts/change-link.py +++ b/scripts/change-link.py @@ -19,7 +19,7 @@ USAGE = """ change-link.py Usage: - change-link.py (--true | --false) [--ignore=...] + change-link.py --value= [--ignore=...] change-link.py --help Options: @@ -35,11 +35,7 @@ def main(): """entry point""" args = docopt(USAGE) path = os.path.expanduser(args['']) - if args['--true']: - value = True - if args['--false']: - value = False - + value = args['--value'] ignores = args['--ignore'] with open(path, 'r') as file: diff --git a/tests-ng/chmod-import.sh b/tests-ng/chmod-import.sh index 7fd437f..4cd652e 100755 --- a/tests-ng/chmod-import.sh +++ b/tests-ng/chmod-import.sh @@ -142,7 +142,7 @@ mkdir -p ${tmps}/dotfiles # import without --preserve-mode and link for i in ${toimport}; do - cd ${ddpath} | ${bin} import -c ${cfg} -l link -f -p p1 -V ${i} + cd ${ddpath} | ${bin} import -c ${cfg} -l absolute -f -p p1 -V ${i} done cat ${cfg} @@ -155,7 +155,7 @@ cnt=`cat ${cfg} | grep "chmod: '777'" | wc -l` [ "${cnt}" != "${tot}" ] && echo "not all chmod inserted (2)" && exit 1 tot=`echo ${toimport} | wc -w` -cnt=`cat ${cfg} | grep 'link: link' | wc -l` +cnt=`cat ${cfg} | grep 'link: absolute' | wc -l` [ "${cnt}" != "${tot}" ] && echo "not all link inserted" && exit 1 ## --preserve-mode diff --git a/tests-ng/deprecated-link.sh b/tests-ng/deprecated-link.sh index 241da7c..edf67e2 100755 --- a/tests-ng/deprecated-link.sh +++ b/tests-ng/deprecated-link.sh @@ -129,7 +129,7 @@ set -e # test values have been correctly updated echo "========> test for updated entries" -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_link' | head -1 | grep ',link:link,' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_link' | head -1 | grep ',link:absolute,' cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_nolink' | head -1 | grep ',link:nolink,' cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_nolink1' | head -1 | grep ',link:nolink,' cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -G | grep '^f_children' | head -1 | grep ',link:link_children,' diff --git a/tests-ng/link-import-default.sh b/tests-ng/link-import-default.sh index 3cd082e..e792848 100755 --- a/tests-ng/link-import-default.sh +++ b/tests-ng/link-import-default.sh @@ -102,7 +102,7 @@ inside="${tmps}/dotfiles/${tmpd}/abc" [ ! -e ${inside} ] && exit 1 cat ${cfg} -cat ${cfg} | grep 'link: link' >/dev/null +cat ${cfg} | grep 'link: absolute' >/dev/null echo "OK" exit 0 diff --git a/tests-ng/link-value-tests.sh b/tests-ng/link-value-tests.sh index 701b29d..cdc40ea 100755 --- a/tests-ng/link-value-tests.sh +++ b/tests-ng/link-value-tests.sh @@ -181,11 +181,11 @@ _EOF # import df="${tmpd}/qwert" -cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V --link=link +cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V --link=absolute # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:link,' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:absolute,' # try to install rm -rf ${tmpd}/qwert @@ -219,7 +219,7 @@ cd ${ddpath} | ${bin} import -f -c ${cfg} -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:link,' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:absolute,' # try to install rm -rf ${tmpd}/qwert @@ -349,11 +349,11 @@ _EOF # import df="${tmpd}/qwert" -cd ${ddpath} | ${bin} import -f -c ${cfg} --link=link -p p1 ${df} -V +cd ${ddpath} | ${bin} import -f -c ${cfg} --link=absolute -p p1 ${df} -V # checks cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:link,' +cd ${ddpath} | ${bin} files -c ${cfg} -p p1 -V -G | grep "f_`basename ${df}`" | head -1 | grep ',link:absolute,' # try to install rm -rf ${tmpd}/qwert diff --git a/tests-ng/minversion.sh b/tests-ng/minversion.sh index deec8bd..616005a 100755 --- a/tests-ng/minversion.sh +++ b/tests-ng/minversion.sh @@ -80,7 +80,7 @@ cd ${ddpath} | ${bin} compare -c ${cfg} -p p1 -V # ensure minversion is present cat ${cfg} -grep 'link: link' ${cfg} +grep 'link: absolute' ${cfg} grep 'minversion' ${cfg} # fake a higher version diff --git a/tests/test_yamlcfg.py b/tests/test_yamlcfg.py index 2b53988..8539e33 100644 --- a/tests/test_yamlcfg.py +++ b/tests/test_yamlcfg.py @@ -51,17 +51,20 @@ class TestConfig(SubsetTestCase): self.assertTrue(conf.dump() != '') def test_def_link(self): - self._test_link_import('nolink', LinkTypes.LINK, 'link') + self._test_link_import('nolink', LinkTypes.ABSOLUTE, 'absolute') + self._test_link_import('nolink', LinkTypes.RELATIVE, 'relative') self._test_link_import('nolink', LinkTypes.NOLINK, 'nolink') self._test_link_import('nolink', LinkTypes.LINK_CHILDREN, 'link_children') - self._test_link_import('link', LinkTypes.LINK, 'link') + self._test_link_import('link', LinkTypes.ABSOLUTE, 'absolute') + self._test_link_import('link', LinkTypes.RELATIVE, 'relative') self._test_link_import('link', LinkTypes.NOLINK, 'nolink') self._test_link_import('link', LinkTypes.LINK_CHILDREN, 'link_children') - self._test_link_import('link_children', LinkTypes.LINK, 'link') + self._test_link_import('link_children', LinkTypes.ABSOLUTE, 'absolute') + self._test_link_import('link_children', LinkTypes.RELATIVE, 'relative') self._test_link_import('link_children', LinkTypes.NOLINK, 'nolink') self._test_link_import('link_children', LinkTypes.LINK_CHILDREN, 'link_children')