1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-16 11:41:11 +00:00

Add dotfile-specific ignore_missing option

This commit is contained in:
Marcel Robitaille
2020-12-12 00:41:05 -05:00
parent b4d7791a60
commit fdc6c91e08
4 changed files with 28 additions and 21 deletions

View File

@@ -59,6 +59,7 @@ class CfgYaml:
key_dotfile_noempty = 'ignoreempty' key_dotfile_noempty = 'ignoreempty'
key_dotfile_template = 'template' key_dotfile_template = 'template'
key_dotfile_chmod = 'chmod' key_dotfile_chmod = 'chmod'
key_dotfile_ignore_missing = 'ignore_missing_in_dotdrop'
# profile # profile
key_profile_dotfiles = 'dotfiles' key_profile_dotfiles = 'dotfiles'

View File

@@ -93,13 +93,15 @@ def _dotfile_compare(o, dotfile, tmp):
returns True if same returns True if same
""" """
t = _get_templater(o) t = _get_templater(o)
ignore_missing_in_dotdrop = o.ignore_missing_in_dotdrop or \
dotfile.ignore_missing_in_dotdrop
inst = Installer(create=o.create, backup=o.backup, inst = Installer(create=o.create, backup=o.backup,
dry=o.dry, base=o.dotpath, dry=o.dry, base=o.dotpath,
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) ignore_missing_in_dotdrop=ignore_missing_in_dotdrop)
# add dotfile variables # add dotfile variables
newvars = dotfile.get_dotfile_variables() newvars = dotfile.get_dotfile_variables()

View File

@@ -22,7 +22,8 @@ class Dotfile(DictParser):
actions=[], trans_r=None, trans_w=None, actions=[], trans_r=None, trans_w=None,
link=LinkTypes.NOLINK, noempty=False, link=LinkTypes.NOLINK, noempty=False,
cmpignore=[], upignore=[], cmpignore=[], upignore=[],
instignore=[], template=True, chmod=None): instignore=[], template=True, chmod=None,
ignore_missing_in_dotdrop=False):
""" """
constructor constructor
@key: dotfile key @key: dotfile key
@@ -52,6 +53,7 @@ class Dotfile(DictParser):
self.instignore = instignore self.instignore = instignore
self.template = template self.template = template
self.chmod = chmod self.chmod = chmod
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
if self.link != LinkTypes.NOLINK and \ if self.link != LinkTypes.NOLINK and \
( (

View File

@@ -108,7 +108,7 @@ class Updater:
self.log.err(msg.format(dtpath)) self.log.err(msg.format(dtpath))
return False return False
if self._ignore([path, dtpath]): if self._ignore([path, dtpath], dotfile):
self.log.sub('\"{}\" ignored'.format(dotfile.key)) self.log.sub('\"{}\" ignored'.format(dotfile.key))
return True return True
# apply write transformation if any # apply write transformation if any
@@ -122,9 +122,9 @@ class Updater:
# handle the pointed file # handle the pointed file
if os.path.isdir(new_path): if os.path.isdir(new_path):
ret = self._handle_dir(new_path, dtpath) ret = self._handle_dir(new_path, dtpath, dotfile)
else: else:
ret = self._handle_file(new_path, dtpath) ret = self._handle_file(new_path, dtpath, dotfile)
if fsmode != dfmode: if fsmode != dfmode:
# mirror rights # mirror rights
@@ -205,9 +205,9 @@ class Updater:
except OSError as e: except OSError as e:
self.log.err(e) self.log.err(e)
def _handle_file(self, path, dtpath, compare=True): def _handle_file(self, path, dtpath, dotfile, compare=True):
"""sync path (deployed file) and dtpath (dotdrop dotfile path)""" """sync path (deployed file) and dtpath (dotdrop dotfile path)"""
if self._ignore([path, dtpath]): if self._ignore([path, dtpath], dotfile):
self.log.sub('\"{}\" ignored'.format(dtpath)) self.log.sub('\"{}\" ignored'.format(dtpath))
return True return True
if self.debug: if self.debug:
@@ -245,29 +245,29 @@ class Updater:
return False return False
return True return True
def _handle_dir(self, path, dtpath): def _handle_dir(self, path, dtpath, dotfile):
"""sync path (deployed dir) and dtpath (dotdrop dir path)""" """sync path (deployed dir) and dtpath (dotdrop dir path)"""
if self.debug: if self.debug:
self.log.dbg('handle update for dir {} to {}'.format(path, dtpath)) self.log.dbg('handle update for dir {} to {}'.format(path, dtpath))
# paths must be absolute (no tildes) # paths must be absolute (no tildes)
path = os.path.expanduser(path) path = os.path.expanduser(path)
dtpath = os.path.expanduser(dtpath) dtpath = os.path.expanduser(dtpath)
if self._ignore([path, dtpath]): if self._ignore([path, dtpath], dotfile):
self.log.sub('\"{}\" ignored'.format(dtpath)) self.log.sub('\"{}\" ignored'.format(dtpath))
return True return True
# find the differences # find the differences
diff = filecmp.dircmp(path, dtpath, ignore=None) diff = filecmp.dircmp(path, dtpath, ignore=None)
# handle directories diff # handle directories diff
ret = self._merge_dirs(diff) ret = self._merge_dirs(diff, dotfile)
self._mirror_rights(path, dtpath) self._mirror_rights(path, dtpath)
return ret return ret
def _merge_dirs(self, diff): def _merge_dirs(self, diff, dotfile):
"""Synchronize directories recursively.""" """Synchronize directories recursively."""
left, right = diff.left, diff.right left, right = diff.left, diff.right
if self.debug: if self.debug:
self.log.dbg('sync dir {} to {}'.format(left, right)) self.log.dbg('sync dir {} to {}'.format(left, right))
if self._ignore([left, right]): if self._ignore([left, right], dotfile):
return True return True
# create dirs that don't exist in dotdrop # create dirs that don't exist in dotdrop
@@ -278,7 +278,7 @@ class Updater:
continue continue
# match to dotdrop dotpath # match to dotdrop dotpath
new = os.path.join(right, toadd) new = os.path.join(right, toadd)
if self._ignore([exist, new]): if self._ignore([exist, new], dotfile):
self.log.sub('\"{}\" ignored'.format(exist)) self.log.sub('\"{}\" ignored'.format(exist))
continue continue
if self.dry: if self.dry:
@@ -311,7 +311,7 @@ class Updater:
if not os.path.isdir(old): if not os.path.isdir(old):
# ignore files for now # ignore files for now
continue continue
if self._ignore([old]): if self._ignore([old], dotfile):
continue continue
if self.dry: if self.dry:
self.log.dry('would rm -r {}'.format(old)) self.log.dry('would rm -r {}'.format(old))
@@ -331,14 +331,14 @@ class Updater:
for f in fdiff: for f in fdiff:
fleft = os.path.join(left, f) fleft = os.path.join(left, f)
fright = os.path.join(right, f) fright = os.path.join(right, f)
if self._ignore([fleft, fright]): if self._ignore([fleft, fright], dotfile):
continue continue
if self.dry: if self.dry:
self.log.dry('would cp {} {}'.format(fleft, fright)) self.log.dry('would cp {} {}'.format(fleft, fright))
continue continue
if self.debug: if self.debug:
self.log.dbg('cp {} {}'.format(fleft, fright)) self.log.dbg('cp {} {}'.format(fleft, fright))
self._handle_file(fleft, fright, compare=False) self._handle_file(fleft, fright, dotfile, compare=False)
# copy files that don't exist in dotdrop # copy files that don't exist in dotdrop
for toadd in diff.left_only: for toadd in diff.left_only:
@@ -347,7 +347,7 @@ class Updater:
# ignore dirs, done above # ignore dirs, done above
continue continue
new = os.path.join(right, toadd) new = os.path.join(right, toadd)
if self._ignore([exist, new]): if self._ignore([exist, new], dotfile):
continue continue
if self.dry: if self.dry:
self.log.dry('would cp {} {}'.format(exist, new)) self.log.dry('would cp {} {}'.format(exist, new))
@@ -366,7 +366,7 @@ class Updater:
if os.path.isdir(new): if os.path.isdir(new):
# ignore dirs, done above # ignore dirs, done above
continue continue
if self._ignore([new]): if self._ignore([new], dotfile):
continue continue
if self.dry: if self.dry:
self.log.dry('would rm {}'.format(new)) self.log.dry('would rm {}'.format(new))
@@ -385,7 +385,7 @@ class Updater:
# Recursively decent into common subdirectories. # Recursively decent into common subdirectories.
for subdir in diff.subdirs.values(): for subdir in diff.subdirs.values():
self._merge_dirs(subdir) self._merge_dirs(subdir, dotfile)
# Nothing more to do here. # Nothing more to do here.
return True return True
@@ -404,10 +404,12 @@ class Updater:
return False return False
return True return True
def _ignore(self, paths): def _ignore(self, paths, dotfile):
ignore_missing_in_dotdrop = self.ignore_missing_in_dotdrop or \
dotfile.ignore_missing_in_dotdrop
if must_ignore( if must_ignore(
paths, self.ignores, debug=self.debug, paths, self.ignores, debug=self.debug,
ignore_missing_in_dotdrop=self.ignore_missing_in_dotdrop, ignore_missing_in_dotdrop=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))