mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 13:56:44 +00:00
Option to ignore missing files update and compare
This commit is contained in:
@@ -16,7 +16,7 @@ from dotdrop.utils import must_ignore, uniq_list, diff, \
|
||||
|
||||
class Comparator:
|
||||
|
||||
def __init__(self, diff_cmd='', debug=False):
|
||||
def __init__(self, diff_cmd='', debug=False, ignore_missing_in_dotdrop=False):
|
||||
"""constructor
|
||||
@diff_cmd: diff command to use
|
||||
@debug: enable debug
|
||||
@@ -24,6 +24,7 @@ class Comparator:
|
||||
self.diff_cmd = diff_cmd
|
||||
self.debug = debug
|
||||
self.log = Logger()
|
||||
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
|
||||
|
||||
def compare(self, left, right, ignore=[]):
|
||||
"""diff left (dotdrop dotfile) and right (deployed file)"""
|
||||
@@ -111,7 +112,9 @@ class Comparator:
|
||||
if must_ignore([os.path.join(right, i)],
|
||||
ignore, debug=self.debug):
|
||||
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
|
||||
funny = comp.common_funny
|
||||
|
||||
@@ -80,7 +80,8 @@ def _dotfile_update(o, path, key=False):
|
||||
updater = Updater(o.dotpath, o.variables, o.conf,
|
||||
dry=o.dry, safe=o.safe, debug=o.debug,
|
||||
ignore=o.update_ignore,
|
||||
showpatch=o.update_showpatch)
|
||||
showpatch=o.update_showpatch,
|
||||
ignore_missing_in_dotdrop=o.ignore_missing_in_dotdrop)
|
||||
if key:
|
||||
return updater.update_key(path)
|
||||
return updater.update_path(path)
|
||||
@@ -97,7 +98,8 @@ def _dotfile_compare(o, dotfile, tmp):
|
||||
workdir=o.workdir, debug=o.debug,
|
||||
backup_suffix=o.install_backup_suffix,
|
||||
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
|
||||
newvars = dotfile.get_dotfile_variables()
|
||||
|
||||
@@ -43,7 +43,7 @@ OPT_LINK = {
|
||||
LinkTypes.LINK.name.lower(): LinkTypes.LINK,
|
||||
LinkTypes.LINK_CHILDREN.name.lower(): LinkTypes.LINK_CHILDREN}
|
||||
|
||||
BANNER = """ _ _ _
|
||||
BANNER = r""" _ _ _
|
||||
__| | ___ | |_ __| |_ __ ___ _ __
|
||||
/ _` |/ _ \| __/ _` | '__/ _ \| '_ |
|
||||
\__,_|\___/ \__\__,_|_| \___/| .__/ v{}
|
||||
@@ -57,9 +57,9 @@ Usage:
|
||||
[-w <nb>] [<key>...]
|
||||
dotdrop import [-Vbdfm] [-c <path>] [-p <profile>] [-s <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>...]
|
||||
dotdrop update [-VbfdkP] [-c <path>] [-p <profile>]
|
||||
dotdrop update [-VbfdkPz] [-c <path>] [-p <profile>]
|
||||
[-w <nb>] [-i <pattern>...] [<path>...]
|
||||
dotdrop remove [-Vbfdk] [-c <path>] [-p <profile>] [<path>...]
|
||||
dotdrop files [-VbTG] [-c <path>] [-p <profile>]
|
||||
@@ -73,6 +73,7 @@ Options:
|
||||
-b --no-banner Do not display the banner.
|
||||
-c --cfg=<path> Path to the config.
|
||||
-C --file=<path> Path of dotfile to compare.
|
||||
-z --ignore-missing Ignore files in installed folders that are missing.
|
||||
-d --dry Dry run.
|
||||
-D --showdiff Show a diff before overwriting.
|
||||
-f --force Do not ask user confirmation for anything.
|
||||
@@ -123,6 +124,7 @@ class Options(AttrMonitor):
|
||||
self.log = Logger()
|
||||
self.debug = self.args['--verbose'] or ENV_DEBUG in os.environ
|
||||
self.dry = self.args['--dry']
|
||||
self.ignore_missing_in_dotdrop = self.args['--ignore-missing']
|
||||
if ENV_NODEBUG in os.environ:
|
||||
# force disabling debugs
|
||||
self.debug = False
|
||||
|
||||
@@ -25,7 +25,8 @@ class Updater:
|
||||
|
||||
def __init__(self, dotpath, variables, conf,
|
||||
dry=False, safe=True, debug=False,
|
||||
ignore=[], showpatch=False):
|
||||
ignore=[], showpatch=False,
|
||||
ignore_missing_in_dotdrop=False):
|
||||
"""constructor
|
||||
@dotpath: path where dotfiles are stored
|
||||
@variables: dictionary of variables for the templates
|
||||
@@ -44,6 +45,7 @@ class Updater:
|
||||
self.debug = debug
|
||||
self.ignore = ignore
|
||||
self.showpatch = showpatch
|
||||
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
|
||||
self.templater = Templategen(variables=self.variables,
|
||||
base=self.dotpath,
|
||||
debug=self.debug)
|
||||
@@ -403,7 +405,10 @@ class Updater:
|
||||
return True
|
||||
|
||||
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:
|
||||
self.log.dbg('ignoring update for {}'.format(paths))
|
||||
return True
|
||||
|
||||
@@ -198,8 +198,12 @@ def strip_home(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"""
|
||||
if ignore_missing_in_dotdrop and \
|
||||
len(paths) >= 2 and not os.path.exists(paths[1]):
|
||||
return True
|
||||
|
||||
if not ignores:
|
||||
return False
|
||||
if debug:
|
||||
|
||||
@@ -135,6 +135,7 @@ def _fake_args():
|
||||
args['--file-only'] = False
|
||||
args['--workers'] = 1
|
||||
args['--preserve-mode'] = False
|
||||
args['--ignore-missing'] = False
|
||||
# cmds
|
||||
args['profiles'] = False
|
||||
args['files'] = False
|
||||
|
||||
Reference in New Issue
Block a user