From 5ffd208bdb85215cc7c5ba6f2903bfa7756aa945 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 15 Nov 2020 16:10:38 +0100 Subject: plugins/link: drop the glob option It is too complex. --- README.md | 3 --- dotbot/plugins/link.py | 58 +++++++++++--------------------------------------- 2 files changed, 12 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index cfb7e56..bb799e0 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,6 @@ mapped to extended configuration dictionaries. | `force` | Force removes the old target, file or folder, and forces a new link (default: false) | | `relative` | Use a relative path to the source when creating the symlink (default: false, absolute links) | | `canonicalize-path` | Resolve any symbolic links encountered in the source to symlink to the canonical path (default: true, real paths) | -| `glob` | Treat a `*` character as a wildcard, and perform link operations on all of those matches (default: false) | | `if` | Execute this in your `$SHELL` and only link if it is successful. | | `ignore-missing` | Do not fail if the source is missing and create the link anyway (default: false) | @@ -213,7 +212,6 @@ Explicit sources: force: true path: zshrc ~/.config/: - glob: true path: config/* relink: true ``` @@ -229,7 +227,6 @@ Implicit sources: ~/.zshrc: force: true ~/.config/: - glob: true path: config/* relink: true ``` diff --git a/dotbot/plugins/link.py b/dotbot/plugins/link.py index 9130362..411a0ef 100644 --- a/dotbot/plugins/link.py +++ b/dotbot/plugins/link.py @@ -1,9 +1,7 @@ import os -import glob import shutil import dotbot import dotbot.util -import subprocess class Link(dotbot.Plugin): @@ -22,7 +20,6 @@ class Link(dotbot.Plugin): canonical_path = defaults.get('canonicalize-path', True) force = defaults.get('force', False) relink = defaults.get('relink', False) - use_glob = defaults.get('glob', False) test = defaults.get('if', None) ignore_missing = defaults.get('ignore-missing', False) if isinstance(source, dict): @@ -32,7 +29,6 @@ class Link(dotbot.Plugin): canonical_path = source.get('canonicalize-path', canonical_path) force = source.get('force', force) relink = source.get('relink', relink) - use_glob = source.get('glob', use_glob) ignore_missing = source.get('ignore-missing', ignore_missing) path = self._default_source(destination, source.get('path')) else: @@ -41,48 +37,18 @@ class Link(dotbot.Plugin): self._log.verbose('Skipping %s' % destination) continue path = os.path.expandvars(os.path.expanduser(path)) - if use_glob: - self._log.debug("Globbing with path: " + str(path)) - glob_results = glob.glob(path) - if len(glob_results) == 0: - self._log.warning("Globbing couldn't find anything matching " + str(path)) - success = False - continue - glob_star_loc = path.find('*') - if glob_star_loc == -1 and destination[-1] == '/': - self._log.error("Ambiguous action requested.") - self._log.error("No wildcard in glob, directory use undefined: " + - destination + " -> " + str(glob_results)) - self._log.warning("Did you want to link the directory or into it?") - success = False - continue - elif glob_star_loc == -1 and len(glob_results) == 1: - # perform a normal link operation - if force or relink: - success &= self._delete(path, destination, relative, canonical_path, force) - success &= self._link(path, destination, relative, canonical_path, ignore_missing) - else: - self._log.verbose("Globs from '" + path + "': " + str(glob_results)) - glob_base = path[:glob_star_loc] - for glob_full_item in glob_results: - glob_item = glob_full_item[len(glob_base):] - glob_link_destination = os.path.join(destination, glob_item) - if force or relink: - success &= self._delete(glob_full_item, glob_link_destination, relative, canonical_path, force) - success &= self._link(glob_full_item, glob_link_destination, relative, canonical_path, ignore_missing) - else: - if not ignore_missing and not self._exists(os.path.join(self._context.base_directory(), path)): - # we seemingly check this twice (here and in _link) because - # if the file doesn't exist and force is True, we don't - # want to remove the original (this is tested by - # link-force-leaves-when-nonexistent.bash) - success = False - self._log.warning('Nonexistent source %s -> %s' % - (destination, path)) - continue - if force or relink: - success &= self._delete(path, destination, relative, canonical_path, force) - success &= self._link(path, destination, relative, canonical_path, ignore_missing) + if not ignore_missing and not self._exists(os.path.join(self._context.base_directory(), path)): + # we seemingly check this twice (here and in _link) because + # if the file doesn't exist and force is True, we don't + # want to remove the original (this is tested by + # link-force-leaves-when-nonexistent.bash) + success = False + self._log.warning('Nonexistent source %s -> %s' % + (destination, path)) + continue + if force or relink: + success &= self._delete(path, destination, relative, canonical_path, force) + success &= self._link(path, destination, relative, canonical_path, ignore_missing) if success: self._log.verbose('All links have been set up') else: -- cgit v1.2.3