mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-06 00:53:04 +00:00
workdir compare
This commit is contained in:
@@ -8,6 +8,7 @@ entry point
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import fnmatch
|
||||
from concurrent import futures
|
||||
|
||||
# local imports
|
||||
@@ -20,7 +21,7 @@ from dotdrop.comparator import Comparator
|
||||
from dotdrop.importer import Importer
|
||||
from dotdrop.utils import get_tmpdir, removepath, \
|
||||
uniq_list, patch_ignores, dependencies_met, \
|
||||
adapt_workers, check_version
|
||||
adapt_workers, check_version, pivot_path
|
||||
from dotdrop.linktypes import LinkTypes
|
||||
from dotdrop.exceptions import YamlException, \
|
||||
UndefinedException, UnmetDependency
|
||||
@@ -379,6 +380,44 @@ def cmd_install(opts):
|
||||
return True
|
||||
|
||||
|
||||
def _workdir_enum(opts):
|
||||
workdir_files = []
|
||||
for root, dirs, files in os.walk(opts.workdir):
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
workdir_files.append(fpath)
|
||||
|
||||
for dotfile in opts.dotfiles:
|
||||
src = os.path.join(opts.dotpath, dotfile.src)
|
||||
if dotfile.link == LinkTypes.NOLINK:
|
||||
# ignore not link files
|
||||
continue
|
||||
if not Templategen.is_template(src):
|
||||
# ignore not template
|
||||
continue
|
||||
newpath = pivot_path(dotfile.dst, opts.workdir,
|
||||
striphome=True, logger=None)
|
||||
if os.path.isdir(newpath):
|
||||
# recursive
|
||||
pattern = '{}/*'.format(newpath)
|
||||
files = workdir_files.copy()
|
||||
for f in files:
|
||||
if fnmatch.fnmatch(f, pattern):
|
||||
workdir_files.remove(f)
|
||||
# only checks children
|
||||
children = [f.path for f in os.scandir(newpath)]
|
||||
for c in children:
|
||||
if c in workdir_files:
|
||||
workdir_files.remove(c)
|
||||
else:
|
||||
if newpath in workdir_files:
|
||||
workdir_files.remove(newpath)
|
||||
for w in workdir_files:
|
||||
line = '=> \"{}\" does not exist in dotdrop'
|
||||
LOG.log(line.format(w))
|
||||
return len(workdir_files)
|
||||
|
||||
|
||||
def cmd_compare(opts, tmp):
|
||||
"""compare dotfiles and return True if all identical"""
|
||||
dotfiles = opts.dotfiles
|
||||
@@ -424,6 +463,10 @@ def cmd_compare(opts, tmp):
|
||||
same = False
|
||||
cnt += 1
|
||||
|
||||
# TODO
|
||||
if _workdir_enum(opts) > 0:
|
||||
same = False
|
||||
|
||||
LOG.log('\n{} dotfile(s) compared.'.format(cnt))
|
||||
return same
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ class Installer:
|
||||
self.totemp = None
|
||||
|
||||
# install the dotfile to a temp directory
|
||||
tmpdst = self._pivot_path(dst, tmpdir)
|
||||
tmpdst = utils.pivot_path(dst, tmpdir, logger=self.log)
|
||||
ret, err = self.install(templater, src, tmpdst,
|
||||
LinkTypes.NOLINK,
|
||||
is_template=is_template,
|
||||
@@ -260,7 +260,8 @@ class Installer:
|
||||
if is_template:
|
||||
self.log.dbg('is a template')
|
||||
self.log.dbg('install to {}'.format(self.workdir))
|
||||
tmp = self._pivot_path(dst, self.workdir, striphome=True)
|
||||
tmp = utils.pivot_path(dst, self.workdir,
|
||||
striphome=True, logger=self.log)
|
||||
ret, err = self.install(templater, src, tmp,
|
||||
LinkTypes.NOLINK,
|
||||
actionexec=actionexec,
|
||||
@@ -326,7 +327,8 @@ class Installer:
|
||||
self.log.dbg('child is a template')
|
||||
self.log.dbg('install to {} and symlink'
|
||||
.format(self.workdir))
|
||||
tmp = self._pivot_path(subdst, self.workdir, striphome=True)
|
||||
tmp = utils.pivot_path(subdst, self.workdir,
|
||||
striphome=True, logger=self.log)
|
||||
ret2, err2 = self.install(templater, subsrc, tmp,
|
||||
LinkTypes.NOLINK,
|
||||
actionexec=actionexec,
|
||||
@@ -698,17 +700,6 @@ class Installer:
|
||||
self.log.log('backup {} to {}'.format(path, dst))
|
||||
os.rename(path, dst)
|
||||
|
||||
def _pivot_path(self, path, newdir, striphome=False):
|
||||
"""change path to be under newdir"""
|
||||
self.log.dbg('pivot new dir: \"{}\"'.format(newdir))
|
||||
self.log.dbg('strip home: {}'.format(striphome))
|
||||
if striphome:
|
||||
path = utils.strip_home(path)
|
||||
sub = path.lstrip(os.sep)
|
||||
new = os.path.join(newdir, sub)
|
||||
self.log.dbg('pivot \"{}\" to \"{}\"'.format(path, new))
|
||||
return new
|
||||
|
||||
def _exec_pre_actions(self, actionexec):
|
||||
"""execute action executor"""
|
||||
if self.action_executed:
|
||||
|
||||
@@ -478,3 +478,17 @@ def check_version():
|
||||
if version.parse(VERSION) < version.parse(latest):
|
||||
msg = 'A new version of dotdrop is available ({})'
|
||||
LOG.warn(msg.format(latest))
|
||||
|
||||
|
||||
def pivot_path(path, newdir, striphome=False, logger=None):
|
||||
"""change path to be under newdir"""
|
||||
if logger:
|
||||
logger.dbg('pivot new dir: \"{}\"'.format(newdir))
|
||||
logger.dbg('strip home: {}'.format(striphome))
|
||||
if striphome:
|
||||
path = strip_home(path)
|
||||
sub = path.lstrip(os.sep)
|
||||
new = os.path.join(newdir, sub)
|
||||
if logger:
|
||||
logger.dbg('pivot \"{}\" to \"{}\"'.format(path, new))
|
||||
return new
|
||||
|
||||
Reference in New Issue
Block a user