mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-07 09:25:44 +00:00
ignore dotdropbak for update/compare (#102)
This commit is contained in:
@@ -49,7 +49,8 @@ def cmd_install(o):
|
|||||||
base=o.dotpath, workdir=o.workdir,
|
base=o.dotpath, workdir=o.workdir,
|
||||||
diff=o.install_diff, debug=o.debug,
|
diff=o.install_diff, debug=o.debug,
|
||||||
totemp=tmpdir,
|
totemp=tmpdir,
|
||||||
showdiff=o.install_showdiff)
|
showdiff=o.install_showdiff,
|
||||||
|
backup_suffix=o.install_backup_suffix)
|
||||||
installed = []
|
installed = []
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
preactions = []
|
preactions = []
|
||||||
@@ -116,7 +117,8 @@ def cmd_compare(o, tmp):
|
|||||||
debug=o.debug)
|
debug=o.debug)
|
||||||
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)
|
||||||
comp = Comparator(diffopts=o.compare_dopts, debug=o.debug)
|
comp = Comparator(diffopts=o.compare_dopts, debug=o.debug)
|
||||||
|
|
||||||
for dotfile in selected:
|
for dotfile in selected:
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ import dotdrop.utils as utils
|
|||||||
|
|
||||||
class Installer:
|
class Installer:
|
||||||
|
|
||||||
BACKUP_SUFFIX = '.dotdropbak'
|
|
||||||
|
|
||||||
def __init__(self, base='.', create=True, backup=True,
|
def __init__(self, base='.', create=True, backup=True,
|
||||||
dry=False, safe=False, workdir='~/.config/dotdrop',
|
dry=False, safe=False, workdir='~/.config/dotdrop',
|
||||||
debug=False, diff=True, totemp=None, showdiff=False):
|
debug=False, diff=True, totemp=None, showdiff=False,
|
||||||
|
backup_suffix='.dotdropbak'):
|
||||||
"""constructor
|
"""constructor
|
||||||
@base: directory path where to search for templates
|
@base: directory path where to search for templates
|
||||||
@create: create directory hierarchy if missing when installing
|
@create: create directory hierarchy if missing when installing
|
||||||
@@ -33,6 +32,7 @@ class Installer:
|
|||||||
@diff: diff when installing if True
|
@diff: diff when installing if True
|
||||||
@totemp: deploy to this path instead of dotfile dst if not None
|
@totemp: deploy to this path instead of dotfile dst if not None
|
||||||
@showdiff: show the diff before overwriting (or asking for)
|
@showdiff: show the diff before overwriting (or asking for)
|
||||||
|
@backup_suffix: suffix for dotfile backup file
|
||||||
"""
|
"""
|
||||||
self.create = create
|
self.create = create
|
||||||
self.backup = backup
|
self.backup = backup
|
||||||
@@ -44,6 +44,7 @@ class Installer:
|
|||||||
self.diff = diff
|
self.diff = diff
|
||||||
self.totemp = totemp
|
self.totemp = totemp
|
||||||
self.showdiff = showdiff
|
self.showdiff = showdiff
|
||||||
|
self.backup_suffix = backup_suffix
|
||||||
self.comparing = False
|
self.comparing = False
|
||||||
self.action_executed = False
|
self.action_executed = False
|
||||||
self.log = Logger()
|
self.log = Logger()
|
||||||
@@ -367,7 +368,7 @@ class Installer:
|
|||||||
"""backup file pointed by path"""
|
"""backup file pointed by path"""
|
||||||
if self.dry:
|
if self.dry:
|
||||||
return
|
return
|
||||||
dst = path.rstrip(os.sep) + self.BACKUP_SUFFIX
|
dst = path.rstrip(os.sep) + self.backup_suffix
|
||||||
self.log.log('backup {} to {}'.format(path, dst))
|
self.log.log('backup {} to {}'.format(path, dst))
|
||||||
os.rename(path, dst)
|
os.rename(path, dst)
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from dotdrop.config import Cfg
|
|||||||
ENV_PROFILE = 'DOTDROP_PROFILE'
|
ENV_PROFILE = 'DOTDROP_PROFILE'
|
||||||
ENV_CONFIG = 'DOTDROP_CONFIG'
|
ENV_CONFIG = 'DOTDROP_CONFIG'
|
||||||
ENV_NOBANNER = 'DOTDROP_NOBANNER'
|
ENV_NOBANNER = 'DOTDROP_NOBANNER'
|
||||||
|
BACKUP_SUFFIX = '.dotdropbak'
|
||||||
|
|
||||||
PROFILE = socket.gethostname()
|
PROFILE = socket.gethostname()
|
||||||
if ENV_PROFILE in os.environ:
|
if ENV_PROFILE in os.environ:
|
||||||
@@ -157,16 +158,19 @@ class Options(AttrMonitor):
|
|||||||
self.install_keys = self.args['<key>']
|
self.install_keys = self.args['<key>']
|
||||||
self.install_diff = not self.args['--nodiff']
|
self.install_diff = not self.args['--nodiff']
|
||||||
self.install_showdiff = self.showdiff or self.args['--showdiff']
|
self.install_showdiff = self.showdiff or self.args['--showdiff']
|
||||||
|
self.install_backup_suffix = BACKUP_SUFFIX
|
||||||
# "compare" specifics
|
# "compare" specifics
|
||||||
self.compare_dopts = self.args['--dopts']
|
self.compare_dopts = self.args['--dopts']
|
||||||
self.compare_focus = self.args['--file']
|
self.compare_focus = self.args['--file']
|
||||||
self.compare_ignore = self.args['--ignore']
|
self.compare_ignore = self.args['--ignore']
|
||||||
|
self.compare_ignore.append('*{}'.format(self.install_backup_suffix))
|
||||||
# "import" specifics
|
# "import" specifics
|
||||||
self.import_path = self.args['<path>']
|
self.import_path = self.args['<path>']
|
||||||
# "update" specifics
|
# "update" specifics
|
||||||
self.update_path = self.args['<path>']
|
self.update_path = self.args['<path>']
|
||||||
self.update_iskey = self.args['--key']
|
self.update_iskey = self.args['--key']
|
||||||
self.update_ignore = self.args['--ignore']
|
self.update_ignore = self.args['--ignore']
|
||||||
|
self.update_ignore.append('*{}'.format(self.install_backup_suffix))
|
||||||
self.update_showpatch = self.args['--show-patch']
|
self.update_showpatch = self.args['--show-patch']
|
||||||
# "detail" specifics
|
# "detail" specifics
|
||||||
self.detail_keys = self.args['<key>']
|
self.detail_keys = self.args['<key>']
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from dotdrop.dotfile import Dotfile
|
|||||||
from dotdrop.installer import Installer
|
from dotdrop.installer import Installer
|
||||||
from dotdrop.action import Action
|
from dotdrop.action import Action
|
||||||
from dotdrop.dotdrop import cmd_install
|
from dotdrop.dotdrop import cmd_install
|
||||||
|
from dotdrop.options import BACKUP_SUFFIX
|
||||||
from dotdrop.linktypes import LinkTypes
|
from dotdrop.linktypes import LinkTypes
|
||||||
from dotdrop.utils import header
|
from dotdrop.utils import header
|
||||||
|
|
||||||
@@ -208,7 +209,7 @@ exec bspwm
|
|||||||
self.assertTrue(os.path.realpath(dst7) == os.path.realpath(dir2))
|
self.assertTrue(os.path.realpath(dst7) == os.path.realpath(dir2))
|
||||||
|
|
||||||
# make sure backup is there
|
# make sure backup is there
|
||||||
b = dst4 + Installer.BACKUP_SUFFIX
|
b = dst4 + BACKUP_SUFFIX
|
||||||
self.assertTrue(os.path.exists(b))
|
self.assertTrue(os.path.exists(b))
|
||||||
|
|
||||||
self.assertTrue(filecmp.cmp(f1, dst1, shallow=True))
|
self.assertTrue(filecmp.cmp(f1, dst1, shallow=True))
|
||||||
|
|||||||
Reference in New Issue
Block a user