From b39a03479f581c36a7f5ec302160388367ecd5b5 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Fri, 29 Oct 2021 18:05:22 +0200 Subject: [PATCH] add clear_workdir and -W for #330 --- docs/config-format.md | 1 + dotdrop/dotdrop.py | 8 ++++++++ dotdrop/options.py | 26 ++++++++++++++------------ dotdrop/settings.py | 8 +++++--- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/config-format.md b/docs/config-format.md index 28b12ad..10ea38c 100644 --- a/docs/config-format.md +++ b/docs/config-format.md @@ -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` | Clear the `workdir` before install | 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)) | - diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index b66f71c..d41a16a 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -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) diff --git a/dotdrop/options.py b/dotdrop/options.py index f1ea7f8..e43e6fa 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -56,18 +56,18 @@ USAGE = """ {} Usage: - dotdrop install [-VbtfndDa] [-c ] [-p ] - [-w ] [...] - dotdrop import [-Vbdfm] [-c ] [-p ] [-s ] - [-l ] [-i ...] ... - dotdrop compare [-LVbz] [-c ] [-p ] - [-w ] [-C ...] [-i ...] - dotdrop update [-VbfdkPz] [-c ] [-p ] - [-w ] [-i ...] [...] - dotdrop remove [-Vbfdk] [-c ] [-p ] [...] - dotdrop files [-VbTG] [-c ] [-p ] - dotdrop detail [-Vb] [-c ] [-p ] [...] - dotdrop profiles [-VbG] [-c ] + dotdrop install [-VbtfndDaW] [-c ] [-p ] + [-w ] [...] + dotdrop import [-Vbdfm] [-c ] [-p ] [-s ] + [-l ] [-i ...] ... + dotdrop compare [-LVbz] [-c ] [-p ] + [-w ] [-C ...] [-i ...] + dotdrop update [-VbfdkPz] [-c ] [-p ] + [-w ] [-i ...] [...] + dotdrop remove [-Vbfdk] [-c ] [-p ] [...] + dotdrop files [-VbTG] [-c ] [-p ] + dotdrop detail [-Vb] [-c ] [-p ] [...] + dotdrop profiles [-VbG] [-c ] dotdrop --help dotdrop --version @@ -93,6 +93,7 @@ Options: -T --template Only template dotfiles. -V --verbose Be verbose. -w --workers= 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. @@ -244,6 +245,7 @@ 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""" diff --git a/dotdrop/settings.py b/dotdrop/settings.py index 3b4675a..54554d2 100644 --- a/dotdrop/settings.py +++ b/dotdrop/settings.py @@ -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)