mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 16:49:42 +00:00
diff static
This commit is contained in:
@@ -30,17 +30,6 @@ class Comparator:
|
||||
self.log = Logger(debug=self.debug)
|
||||
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
|
||||
|
||||
def compare2(self, local_path, deployed_path, ignore=None, mode=None):
|
||||
"""
|
||||
diff local_path (dotdrop dotfile) and
|
||||
deployed_path (destination file)
|
||||
If mode is None, rights will be read from local_path
|
||||
"""
|
||||
local_tree = FTreeDir(local_path, ignores=ignore, debug=self.debug)
|
||||
deploy_tree = FTreeDir(deployed_path, ignores=ignore, debug=self.debug)
|
||||
lonly, ronly, common = local_tree.compare(deploy_tree)
|
||||
# TODO
|
||||
|
||||
def compare(self, local_path, deployed_path, ignore=None, mode=None):
|
||||
"""
|
||||
diff local_path (dotdrop dotfile) and
|
||||
@@ -125,7 +114,40 @@ class Comparator:
|
||||
if not os.path.isdir(deployed_path):
|
||||
return f'\"{deployed_path}\" is a file\n'
|
||||
|
||||
return self._compare_dirs(local_path, deployed_path, ignore)
|
||||
# return self._compare_dirs(local_path, deployed_path, ignore)
|
||||
return self._compare_dirs2(local_path, deployed_path, ignore)
|
||||
|
||||
def _compare_dirs2(self, local_path, deployed_path, ignore):
|
||||
"""compare directories"""
|
||||
self.log.dbg(f'compare dirs {local_path} and {deployed_path}')
|
||||
ret = []
|
||||
|
||||
local_tree = FTreeDir(local_path, ignores=ignore, debug=self.debug)
|
||||
deploy_tree = FTreeDir(deployed_path, ignores=ignore, debug=self.debug)
|
||||
lonly, ronly, common = local_tree.compare(deploy_tree)
|
||||
|
||||
if not self.ignore_missing_in_dotdrop:
|
||||
for i in lonly:
|
||||
ret.append(f'=> \"{i}\" does not exist on destination\n')
|
||||
for i in ronly:
|
||||
ret.append(f'=> \"{i}\" does not exist in dotdrop\n')
|
||||
|
||||
# test for content difference
|
||||
# and mode difference
|
||||
self.log.dbg(f'common files {common}')
|
||||
for i in common:
|
||||
source_file = os.path.join(local_path, i)
|
||||
deployed_file = os.path.join(deployed_path, i)
|
||||
diff = self._diff(source_file, deployed_file, header=True)
|
||||
if diff:
|
||||
ret.append(diff)
|
||||
continue
|
||||
ret = self._comp_mode(local_path, deployed_path)
|
||||
if ret:
|
||||
short = os.path.basename(source_file)
|
||||
ret.append(f'=> different type: \"{short}\"\n')
|
||||
|
||||
return ''.join(ret)
|
||||
|
||||
def _compare_dirs(self, local_path, deployed_path, ignore):
|
||||
"""compare directories"""
|
||||
|
||||
@@ -13,10 +13,11 @@ from dotdrop.utils import must_ignore
|
||||
|
||||
|
||||
class FTreeDir:
|
||||
"""directory tree for comparison"""
|
||||
|
||||
def __init__(self, path, ignores=None, debug=False):
|
||||
self.path = path
|
||||
self.ignores
|
||||
self.ignores = ignores
|
||||
self.debug = debug
|
||||
self.entries = []
|
||||
if os.path.exists(path) and os.path.isdir(path):
|
||||
@@ -24,8 +25,8 @@ class FTreeDir:
|
||||
|
||||
def _walk(self):
|
||||
for root, _, files in os.walk(self.path):
|
||||
for f in files:
|
||||
fpath = os.path.join(root, f)
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
if must_ignore([fpath], ignores=self.ignores,
|
||||
debug=self.debug):
|
||||
continue
|
||||
@@ -42,4 +43,4 @@ class FTreeDir:
|
||||
left_only = set(self.entries) - set(other.entries)
|
||||
right_only = set(other.entries) - set(self.entries)
|
||||
in_both = set(self.entries) & set(other.entries)
|
||||
return left_only, right_only, in_both
|
||||
return list(left_only), list(right_only), list(in_both)
|
||||
|
||||
@@ -129,7 +129,8 @@ class TestCompare(unittest.TestCase):
|
||||
expected = {df1: True, df2: True, df3: True, df4: True,
|
||||
df5: True, df9: True}
|
||||
results = self.compare(opt, tmp, len(dfiles))
|
||||
self.assertTrue(results == expected)
|
||||
self.maxDiff = None
|
||||
self.assertEqual(results, expected)
|
||||
|
||||
# modify file
|
||||
edit_content(df1, get_string(20))
|
||||
|
||||
Reference in New Issue
Block a user