mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-05 21:58:02 +00:00
add instignore for #195
This commit is contained in:
@@ -137,9 +137,12 @@ def cmd_install(o):
|
||||
if not tmp:
|
||||
continue
|
||||
src = tmp
|
||||
ignores = list(set(o.install_ignore + dotfile.instignore))
|
||||
ignores = patch_ignores(ignores, dotfile.dst, debug=o.debug)
|
||||
r, err = inst.install(t, src, dotfile.dst,
|
||||
actionexec=pre_actions_exec,
|
||||
noempty=dotfile.noempty)
|
||||
noempty=dotfile.noempty,
|
||||
ignore=ignores)
|
||||
if tmp:
|
||||
tmp = os.path.join(o.dotpath, tmp)
|
||||
if os.path.exists(tmp):
|
||||
|
||||
@@ -19,8 +19,9 @@ class Dotfile(DictParser):
|
||||
|
||||
def __init__(self, key, dst, src,
|
||||
actions=[], trans_r=None, trans_w=None,
|
||||
link=LinkTypes.NOLINK, cmpignore=[],
|
||||
noempty=False, upignore=[]):
|
||||
link=LinkTypes.NOLINK, noempty=False,
|
||||
cmpignore=[], upignore=[],
|
||||
instignore=[]):
|
||||
"""
|
||||
constructor
|
||||
@key: dotfile key
|
||||
@@ -30,12 +31,12 @@ class Dotfile(DictParser):
|
||||
@trans_r: transformation to change dotfile before it is installed
|
||||
@trans_w: transformation to change dotfile before updating it
|
||||
@link: link behavior
|
||||
@cmpignore: patterns to ignore when comparing
|
||||
@noempty: ignore empty template if True
|
||||
@upignore: patterns to ignore when updating
|
||||
@cmpignore: patterns to ignore when comparing
|
||||
@instignore: patterns to ignore when installing
|
||||
"""
|
||||
self.actions = actions
|
||||
self.cmpignore = cmpignore
|
||||
self.dst = dst
|
||||
self.key = key
|
||||
self.link = LinkTypes.get(link)
|
||||
@@ -44,6 +45,8 @@ class Dotfile(DictParser):
|
||||
self.trans_r = trans_r
|
||||
self.trans_w = trans_w
|
||||
self.upignore = upignore
|
||||
self.cmpignore = cmpignore
|
||||
self.instignore = instignore
|
||||
|
||||
if self.link != LinkTypes.NOLINK and \
|
||||
(
|
||||
|
||||
@@ -48,7 +48,9 @@ class Installer:
|
||||
self.action_executed = False
|
||||
self.log = Logger()
|
||||
|
||||
def install(self, templater, src, dst, actionexec=None, noempty=False):
|
||||
def install(self, templater, src, dst,
|
||||
actionexec=None, noempty=False,
|
||||
ignore=[]):
|
||||
"""
|
||||
install src to dst using a template
|
||||
@templater: the templater object
|
||||
@@ -56,6 +58,7 @@ class Installer:
|
||||
@dst: dotfile destination path in the FS
|
||||
@actionexec: action executor callback
|
||||
@noempty: render empty template flag
|
||||
@ignore: pattern to ignore when installing
|
||||
|
||||
return
|
||||
- True, None : success
|
||||
@@ -83,9 +86,10 @@ class Installer:
|
||||
if isdir:
|
||||
return self._handle_dir(templater, src, dst,
|
||||
actionexec=actionexec,
|
||||
noempty=noempty)
|
||||
noempty=noempty, ignore=ignore)
|
||||
return self._handle_file(templater, src, dst,
|
||||
actionexec=actionexec, noempty=noempty)
|
||||
actionexec=actionexec,
|
||||
noempty=noempty, ignore=ignore)
|
||||
|
||||
def link(self, templater, src, dst, actionexec=None):
|
||||
"""
|
||||
@@ -272,11 +276,19 @@ class Installer:
|
||||
return tmp
|
||||
|
||||
def _handle_file(self, templater, src, dst,
|
||||
actionexec=None, noempty=False):
|
||||
actionexec=None, noempty=False,
|
||||
ignore=[]):
|
||||
"""install src to dst when is a file"""
|
||||
if self.debug:
|
||||
self.log.dbg('generate template for {}'.format(src))
|
||||
self.log.dbg('ignore empty: {}'.format(noempty))
|
||||
self.log.dbg('ignore pattern: {}'.format(ignore))
|
||||
|
||||
if utils.must_ignore([src, dst], ignore, debug=self.debug):
|
||||
if self.debug:
|
||||
self.log.dbg('ignoring install of {} to {}'.format(src, dst))
|
||||
return False, None
|
||||
|
||||
if utils.samefile(src, dst):
|
||||
# symlink loop
|
||||
err = 'dotfile points to itself: {}'.format(dst)
|
||||
@@ -310,7 +322,9 @@ class Installer:
|
||||
err = 'installing {} to {}'.format(src, dst)
|
||||
return False, err
|
||||
|
||||
def _handle_dir(self, templater, src, dst, actionexec=None, noempty=False):
|
||||
def _handle_dir(self, templater, src, dst,
|
||||
actionexec=None, noempty=False,
|
||||
ignore=[]):
|
||||
"""install src to dst when is a directory"""
|
||||
if self.debug:
|
||||
self.log.dbg('install dir {}'.format(src))
|
||||
@@ -328,7 +342,8 @@ class Installer:
|
||||
res, err = self._handle_file(templater, f,
|
||||
os.path.join(dst, entry),
|
||||
actionexec=actionexec,
|
||||
noempty=noempty)
|
||||
noempty=noempty,
|
||||
ignore=ignore)
|
||||
if not res and err:
|
||||
# error occured
|
||||
ret = res, err
|
||||
@@ -341,7 +356,8 @@ class Installer:
|
||||
res, err = self._handle_dir(templater, f,
|
||||
os.path.join(dst, entry),
|
||||
actionexec=actionexec,
|
||||
noempty=noempty)
|
||||
noempty=noempty,
|
||||
ignore=ignore)
|
||||
if not res and err:
|
||||
# error occured
|
||||
ret = res, err
|
||||
|
||||
@@ -225,6 +225,7 @@ class Options(AttrMonitor):
|
||||
if a.kind == Action.pre]
|
||||
self.install_default_actions_post = [a for a in self.default_actions
|
||||
if a.kind == Action.post]
|
||||
self.install_ignore = self.instignore
|
||||
# "compare" specifics
|
||||
self.compare_dopts = self.args['--dopts']
|
||||
self.compare_focus = self.args['--file']
|
||||
|
||||
@@ -17,7 +17,6 @@ class Settings(DictParser):
|
||||
# settings item keys
|
||||
key_backup = 'backup'
|
||||
key_banner = 'banner'
|
||||
key_cmpignore = 'cmpignore'
|
||||
key_create = 'create'
|
||||
key_default_actions = 'default_actions'
|
||||
key_dotpath = 'dotpath'
|
||||
@@ -28,6 +27,8 @@ class Settings(DictParser):
|
||||
key_link_on_import = 'link_on_import'
|
||||
key_showdiff = 'showdiff'
|
||||
key_upignore = 'upignore'
|
||||
key_cmpignore = 'cmpignore'
|
||||
key_instignore = 'instignore'
|
||||
key_workdir = 'workdir'
|
||||
key_minversion = 'minversion'
|
||||
|
||||
@@ -36,18 +37,18 @@ class Settings(DictParser):
|
||||
key_import_configs = 'import_configs'
|
||||
key_import_variables = 'import_variables'
|
||||
|
||||
def __init__(self, backup=True, banner=True, cmpignore=[],
|
||||
def __init__(self, backup=True, banner=True,
|
||||
create=True, default_actions=[], dotpath='dotfiles',
|
||||
ignoreempty=True, import_actions=[], import_configs=[],
|
||||
import_variables=[], keepdot=False,
|
||||
link_dotfile_default=LinkTypes.NOLINK,
|
||||
link_on_import=LinkTypes.NOLINK, longkey=False,
|
||||
showdiff=False, upignore=[], workdir='~/.config/dotdrop',
|
||||
upignore=[], cmpignore=[], instignore=[],
|
||||
workdir='~/.config/dotdrop', showdiff=False,
|
||||
minversion=None):
|
||||
self.backup = backup
|
||||
self.banner = banner
|
||||
self.create = create
|
||||
self.cmpignore = cmpignore
|
||||
self.default_actions = default_actions
|
||||
self.dotpath = dotpath
|
||||
self.ignoreempty = ignoreempty
|
||||
@@ -58,6 +59,8 @@ class Settings(DictParser):
|
||||
self.longkey = longkey
|
||||
self.showdiff = showdiff
|
||||
self.upignore = upignore
|
||||
self.cmpignore = cmpignore
|
||||
self.instignore = instignore
|
||||
self.workdir = workdir
|
||||
self.link_dotfile_default = LinkTypes.get(link_dotfile_default)
|
||||
self.link_on_import = LinkTypes.get(link_on_import)
|
||||
@@ -85,11 +88,12 @@ class Settings(DictParser):
|
||||
self.key_workdir: self.workdir,
|
||||
self.key_minversion: self.minversion,
|
||||
}
|
||||
self._serialize_seq(self.key_cmpignore, dic)
|
||||
self._serialize_seq(self.key_default_actions, dic)
|
||||
self._serialize_seq(self.key_import_actions, dic)
|
||||
self._serialize_seq(self.key_import_configs, dic)
|
||||
self._serialize_seq(self.key_import_variables, dic)
|
||||
self._serialize_seq(self.key_cmpignore, dic)
|
||||
self._serialize_seq(self.key_upignore, dic)
|
||||
self._serialize_seq(self.key_instignore, dic)
|
||||
|
||||
return {self.key_yaml: dic}
|
||||
|
||||
Reference in New Issue
Block a user