1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 19:09:44 +00:00

Option to ignore missing files update and compare

This commit is contained in:
Marcel Robitaille
2020-12-11 00:54:51 -05:00
parent 900f705b30
commit 8081b4adf5
6 changed files with 27 additions and 10 deletions

View File

@@ -16,7 +16,7 @@ from dotdrop.utils import must_ignore, uniq_list, diff, \
class Comparator: class Comparator:
def __init__(self, diff_cmd='', debug=False): def __init__(self, diff_cmd='', debug=False, ignore_missing_in_dotdrop=False):
"""constructor """constructor
@diff_cmd: diff command to use @diff_cmd: diff command to use
@debug: enable debug @debug: enable debug
@@ -24,6 +24,7 @@ class Comparator:
self.diff_cmd = diff_cmd self.diff_cmd = diff_cmd
self.debug = debug self.debug = debug
self.log = Logger() self.log = Logger()
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
def compare(self, left, right, ignore=[]): def compare(self, left, right, ignore=[]):
"""diff left (dotdrop dotfile) and right (deployed file)""" """diff left (dotdrop dotfile) and right (deployed file)"""
@@ -111,7 +112,9 @@ class Comparator:
if must_ignore([os.path.join(right, i)], if must_ignore([os.path.join(right, i)],
ignore, debug=self.debug): ignore, debug=self.debug):
continue continue
ret.append('=> \"{}\" does not exist in dotdrop\n'.format(i))
if not self.ignore_missing_in_dotdrop:
ret.append('=> \"{}\" does not exist in dotdrop\n'.format(i))
# same left and right but different type # same left and right but different type
funny = comp.common_funny funny = comp.common_funny

View File

@@ -80,7 +80,8 @@ def _dotfile_update(o, path, key=False):
updater = Updater(o.dotpath, o.variables, o.conf, updater = Updater(o.dotpath, o.variables, o.conf,
dry=o.dry, safe=o.safe, debug=o.debug, dry=o.dry, safe=o.safe, debug=o.debug,
ignore=o.update_ignore, ignore=o.update_ignore,
showpatch=o.update_showpatch) showpatch=o.update_showpatch,
ignore_missing_in_dotdrop=o.ignore_missing_in_dotdrop)
if key: if key:
return updater.update_key(path) return updater.update_key(path)
return updater.update_path(path) return updater.update_path(path)
@@ -97,7 +98,8 @@ def _dotfile_compare(o, dotfile, tmp):
workdir=o.workdir, debug=o.debug, workdir=o.workdir, debug=o.debug,
backup_suffix=o.install_backup_suffix, backup_suffix=o.install_backup_suffix,
diff_cmd=o.diff_command) diff_cmd=o.diff_command)
comp = Comparator(diff_cmd=o.diff_command, debug=o.debug) comp = Comparator(diff_cmd=o.diff_command, debug=o.debug,
ignore_missing_in_dotdrop=o.ignore_missing_in_dotdrop)
# add dotfile variables # add dotfile variables
newvars = dotfile.get_dotfile_variables() newvars = dotfile.get_dotfile_variables()

View File

@@ -43,7 +43,7 @@ OPT_LINK = {
LinkTypes.LINK.name.lower(): LinkTypes.LINK, LinkTypes.LINK.name.lower(): LinkTypes.LINK,
LinkTypes.LINK_CHILDREN.name.lower(): LinkTypes.LINK_CHILDREN} LinkTypes.LINK_CHILDREN.name.lower(): LinkTypes.LINK_CHILDREN}
BANNER = """ _ _ _ BANNER = r""" _ _ _
__| | ___ | |_ __| |_ __ ___ _ __ __| | ___ | |_ __| |_ __ ___ _ __
/ _` |/ _ \| __/ _` | '__/ _ \| '_ | / _` |/ _ \| __/ _` | '__/ _ \| '_ |
\__,_|\___/ \__\__,_|_| \___/| .__/ v{} \__,_|\___/ \__\__,_|_| \___/| .__/ v{}
@@ -57,9 +57,9 @@ Usage:
[-w <nb>] [<key>...] [-w <nb>] [<key>...]
dotdrop import [-Vbdfm] [-c <path>] [-p <profile>] [-s <path>] dotdrop import [-Vbdfm] [-c <path>] [-p <profile>] [-s <path>]
[-l <link>] [-i <pattern>...] <path>... [-l <link>] [-i <pattern>...] <path>...
dotdrop compare [-LVb] [-c <path>] [-p <profile>] dotdrop compare [-LVbz] [-c <path>] [-p <profile>]
[-w <nb>] [-C <file>...] [-i <pattern>...] [-w <nb>] [-C <file>...] [-i <pattern>...]
dotdrop update [-VbfdkP] [-c <path>] [-p <profile>] dotdrop update [-VbfdkPz] [-c <path>] [-p <profile>]
[-w <nb>] [-i <pattern>...] [<path>...] [-w <nb>] [-i <pattern>...] [<path>...]
dotdrop remove [-Vbfdk] [-c <path>] [-p <profile>] [<path>...] dotdrop remove [-Vbfdk] [-c <path>] [-p <profile>] [<path>...]
dotdrop files [-VbTG] [-c <path>] [-p <profile>] dotdrop files [-VbTG] [-c <path>] [-p <profile>]
@@ -73,6 +73,7 @@ Options:
-b --no-banner Do not display the banner. -b --no-banner Do not display the banner.
-c --cfg=<path> Path to the config. -c --cfg=<path> Path to the config.
-C --file=<path> Path of dotfile to compare. -C --file=<path> Path of dotfile to compare.
-z --ignore-missing Ignore files in installed folders that are missing.
-d --dry Dry run. -d --dry Dry run.
-D --showdiff Show a diff before overwriting. -D --showdiff Show a diff before overwriting.
-f --force Do not ask user confirmation for anything. -f --force Do not ask user confirmation for anything.
@@ -123,6 +124,7 @@ class Options(AttrMonitor):
self.log = Logger() self.log = Logger()
self.debug = self.args['--verbose'] or ENV_DEBUG in os.environ self.debug = self.args['--verbose'] or ENV_DEBUG in os.environ
self.dry = self.args['--dry'] self.dry = self.args['--dry']
self.ignore_missing_in_dotdrop = self.args['--ignore-missing']
if ENV_NODEBUG in os.environ: if ENV_NODEBUG in os.environ:
# force disabling debugs # force disabling debugs
self.debug = False self.debug = False

View File

@@ -25,7 +25,8 @@ class Updater:
def __init__(self, dotpath, variables, conf, def __init__(self, dotpath, variables, conf,
dry=False, safe=True, debug=False, dry=False, safe=True, debug=False,
ignore=[], showpatch=False): ignore=[], showpatch=False,
ignore_missing_in_dotdrop=False):
"""constructor """constructor
@dotpath: path where dotfiles are stored @dotpath: path where dotfiles are stored
@variables: dictionary of variables for the templates @variables: dictionary of variables for the templates
@@ -44,6 +45,7 @@ class Updater:
self.debug = debug self.debug = debug
self.ignore = ignore self.ignore = ignore
self.showpatch = showpatch self.showpatch = showpatch
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
self.templater = Templategen(variables=self.variables, self.templater = Templategen(variables=self.variables,
base=self.dotpath, base=self.dotpath,
debug=self.debug) debug=self.debug)
@@ -403,7 +405,10 @@ class Updater:
return True return True
def _ignore(self, paths): def _ignore(self, paths):
if must_ignore(paths, self.ignores, debug=self.debug): if must_ignore(
paths, self.ignores, debug=self.debug,
ignore_missing_in_dotdrop=self.ignore_missing_in_dotdrop,
):
if self.debug: if self.debug:
self.log.dbg('ignoring update for {}'.format(paths)) self.log.dbg('ignoring update for {}'.format(paths))
return True return True

View File

@@ -198,8 +198,12 @@ def strip_home(path):
return path return path
def must_ignore(paths, ignores, debug=False): def must_ignore(paths, ignores, debug=False, ignore_missing_in_dotdrop=False):
"""return true if any paths in list matches any ignore patterns""" """return true if any paths in list matches any ignore patterns"""
if ignore_missing_in_dotdrop and \
len(paths) >= 2 and not os.path.exists(paths[1]):
return True
if not ignores: if not ignores:
return False return False
if debug: if debug:

View File

@@ -135,6 +135,7 @@ def _fake_args():
args['--file-only'] = False args['--file-only'] = False
args['--workers'] = 1 args['--workers'] = 1
args['--preserve-mode'] = False args['--preserve-mode'] = False
args['--ignore-missing'] = False
# cmds # cmds
args['profiles'] = False args['profiles'] = False
args['files'] = False args['files'] = False