1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 05:39:43 +00:00

ignore dotdropbak for update/compare (#102)

This commit is contained in:
deadc0de6
2019-03-13 08:24:10 +01:00
parent 2f35636c04
commit 8dacabae0e
4 changed files with 15 additions and 7 deletions

View File

@@ -49,7 +49,8 @@ def cmd_install(o):
base=o.dotpath, workdir=o.workdir,
diff=o.install_diff, debug=o.debug,
totemp=tmpdir,
showdiff=o.install_showdiff)
showdiff=o.install_showdiff,
backup_suffix=o.install_backup_suffix)
installed = []
for dotfile in dotfiles:
preactions = []
@@ -116,7 +117,8 @@ def cmd_compare(o, tmp):
debug=o.debug)
inst = Installer(create=o.create, backup=o.backup,
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)
for dotfile in selected:

View File

@@ -17,11 +17,10 @@ import dotdrop.utils as utils
class Installer:
BACKUP_SUFFIX = '.dotdropbak'
def __init__(self, base='.', create=True, backup=True,
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
@base: directory path where to search for templates
@create: create directory hierarchy if missing when installing
@@ -33,6 +32,7 @@ class Installer:
@diff: diff when installing if True
@totemp: deploy to this path instead of dotfile dst if not None
@showdiff: show the diff before overwriting (or asking for)
@backup_suffix: suffix for dotfile backup file
"""
self.create = create
self.backup = backup
@@ -44,6 +44,7 @@ class Installer:
self.diff = diff
self.totemp = totemp
self.showdiff = showdiff
self.backup_suffix = backup_suffix
self.comparing = False
self.action_executed = False
self.log = Logger()
@@ -367,7 +368,7 @@ class Installer:
"""backup file pointed by path"""
if self.dry:
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))
os.rename(path, dst)

View File

@@ -18,6 +18,7 @@ from dotdrop.config import Cfg
ENV_PROFILE = 'DOTDROP_PROFILE'
ENV_CONFIG = 'DOTDROP_CONFIG'
ENV_NOBANNER = 'DOTDROP_NOBANNER'
BACKUP_SUFFIX = '.dotdropbak'
PROFILE = socket.gethostname()
if ENV_PROFILE in os.environ:
@@ -157,16 +158,19 @@ class Options(AttrMonitor):
self.install_keys = self.args['<key>']
self.install_diff = not self.args['--nodiff']
self.install_showdiff = self.showdiff or self.args['--showdiff']
self.install_backup_suffix = BACKUP_SUFFIX
# "compare" specifics
self.compare_dopts = self.args['--dopts']
self.compare_focus = self.args['--file']
self.compare_ignore = self.args['--ignore']
self.compare_ignore.append('*{}'.format(self.install_backup_suffix))
# "import" specifics
self.import_path = self.args['<path>']
# "update" specifics
self.update_path = self.args['<path>']
self.update_iskey = self.args['--key']
self.update_ignore = self.args['--ignore']
self.update_ignore.append('*{}'.format(self.install_backup_suffix))
self.update_showpatch = self.args['--show-patch']
# "detail" specifics
self.detail_keys = self.args['<key>']

View File

@@ -16,6 +16,7 @@ from dotdrop.dotfile import Dotfile
from dotdrop.installer import Installer
from dotdrop.action import Action
from dotdrop.dotdrop import cmd_install
from dotdrop.options import BACKUP_SUFFIX
from dotdrop.linktypes import LinkTypes
from dotdrop.utils import header
@@ -208,7 +209,7 @@ exec bspwm
self.assertTrue(os.path.realpath(dst7) == os.path.realpath(dir2))
# make sure backup is there
b = dst4 + Installer.BACKUP_SUFFIX
b = dst4 + BACKUP_SUFFIX
self.assertTrue(os.path.exists(b))
self.assertTrue(filecmp.cmp(f1, dst1, shallow=True))