mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 09:04:18 +00:00
rebase
This commit is contained in:
@@ -32,11 +32,15 @@ class Comparator:
|
|||||||
self.log.dbg('comparing {} and {}'.format(left, right))
|
self.log.dbg('comparing {} and {}'.format(left, right))
|
||||||
self.log.dbg('ignore pattern(s): {}'.format(ignore))
|
self.log.dbg('ignore pattern(s): {}'.format(ignore))
|
||||||
if not os.path.isdir(left):
|
if not os.path.isdir(left):
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('is file')
|
||||||
return self._comp_file(left, right, ignore)
|
return self._comp_file(left, right, ignore)
|
||||||
return self._comp_dir(left, right, ignore)
|
return self._comp_dir(left, right, ignore)
|
||||||
|
|
||||||
def _comp_file(self, left, right, ignore):
|
def _comp_file(self, left, right, ignore):
|
||||||
"""compare a file"""
|
"""compare a file"""
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('compare file {} with {}'.format(left, right))
|
||||||
if utils.must_ignore([left, right], ignore, debug=self.debug):
|
if utils.must_ignore([left, right], ignore, debug=self.debug):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
self.log.dbg('ignoring diff {} and {}'.format(left, right))
|
self.log.dbg('ignoring diff {} and {}'.format(left, right))
|
||||||
@@ -45,6 +49,8 @@ class Comparator:
|
|||||||
|
|
||||||
def _comp_dir(self, left, right, ignore):
|
def _comp_dir(self, left, right, ignore):
|
||||||
"""compare a directory"""
|
"""compare a directory"""
|
||||||
|
if self.debug:
|
||||||
|
self.log.dbg('compare directory {} with {}'.format(left, right))
|
||||||
if not os.path.exists(right):
|
if not os.path.exists(right):
|
||||||
return ''
|
return ''
|
||||||
if utils.must_ignore([left, right], ignore, debug=self.debug):
|
if utils.must_ignore([left, right], ignore, debug=self.debug):
|
||||||
@@ -61,6 +67,7 @@ class Comparator:
|
|||||||
ignore, debug=self.debug):
|
ignore, debug=self.debug):
|
||||||
continue
|
continue
|
||||||
ret.append('=> \"{}\" does not exist on local\n'.format(i))
|
ret.append('=> \"{}\" does not exist on local\n'.format(i))
|
||||||
|
# handle files only in dotpath file
|
||||||
for i in comp.right_only:
|
for i in comp.right_only:
|
||||||
if utils.must_ignore([os.path.join(right, i)],
|
if utils.must_ignore([os.path.join(right, i)],
|
||||||
ignore, debug=self.debug):
|
ignore, debug=self.debug):
|
||||||
@@ -86,6 +93,12 @@ class Comparator:
|
|||||||
diff = self._diff(lfile, rfile, header=True)
|
diff = self._diff(lfile, rfile, header=True)
|
||||||
ret.append(diff)
|
ret.append(diff)
|
||||||
|
|
||||||
|
# recursively compare subdirs
|
||||||
|
for i in comp.common_dirs:
|
||||||
|
subleft = os.path.join(left, i)
|
||||||
|
subright = os.path.join(right, i)
|
||||||
|
ret.extend(self._comp_dir(subleft, subright, ignore))
|
||||||
|
|
||||||
return ''.join(ret)
|
return ''.join(ret)
|
||||||
|
|
||||||
def _diff(self, left, right, header=False):
|
def _diff(self, left, right, header=False):
|
||||||
|
|||||||
@@ -72,21 +72,33 @@ class TestCompare(unittest.TestCase):
|
|||||||
d1, c1 = create_random_file(fold_config)
|
d1, c1 = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d1))
|
self.assertTrue(os.path.exists(d1))
|
||||||
self.addCleanup(clean, d1)
|
self.addCleanup(clean, d1)
|
||||||
|
|
||||||
d2, c2 = create_random_file(fold_subcfg)
|
d2, c2 = create_random_file(fold_subcfg)
|
||||||
self.assertTrue(os.path.exists(d2))
|
self.assertTrue(os.path.exists(d2))
|
||||||
self.addCleanup(clean, d2)
|
self.addCleanup(clean, d2)
|
||||||
|
|
||||||
d3, c3 = create_random_file(fold_tmp)
|
d3, c3 = create_random_file(fold_tmp)
|
||||||
self.assertTrue(os.path.exists(d3))
|
self.assertTrue(os.path.exists(d3))
|
||||||
self.addCleanup(clean, d3)
|
self.addCleanup(clean, d3)
|
||||||
|
|
||||||
d4, c4 = create_random_file(fold_tmp, binary=True)
|
d4, c4 = create_random_file(fold_tmp, binary=True)
|
||||||
self.assertTrue(os.path.exists(d4))
|
self.assertTrue(os.path.exists(d4))
|
||||||
self.addCleanup(clean, d4)
|
self.addCleanup(clean, d4)
|
||||||
|
|
||||||
d5 = get_tempdir()
|
d5 = get_tempdir()
|
||||||
self.assertTrue(os.path.exists(d5))
|
self.assertTrue(os.path.exists(d5))
|
||||||
self.addCleanup(clean, d5)
|
self.addCleanup(clean, d5)
|
||||||
|
|
||||||
d6, _ = create_random_file(d5)
|
d6, _ = create_random_file(d5)
|
||||||
self.assertTrue(os.path.exists(d6))
|
self.assertTrue(os.path.exists(d6))
|
||||||
|
|
||||||
|
d9 = get_tempdir()
|
||||||
|
self.assertTrue(os.path.exists(d9))
|
||||||
|
self.addCleanup(clean, d9)
|
||||||
|
d9sub = os.path.join(d9, get_string(5))
|
||||||
|
create_dir(d9sub)
|
||||||
|
d9f1, _ = create_random_file(d9sub)
|
||||||
|
|
||||||
# create the config file
|
# create the config file
|
||||||
profile = get_string(5)
|
profile = get_string(5)
|
||||||
confpath = create_fake_config(dotfilespath,
|
confpath = create_fake_config(dotfilespath,
|
||||||
@@ -97,7 +109,7 @@ class TestCompare(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
o = load_options(confpath, profile)
|
o = load_options(confpath, profile)
|
||||||
o.longkey = True
|
o.longkey = True
|
||||||
dfiles = [d1, d2, d3, d4, d5]
|
dfiles = [d1, d2, d3, d4, d5, d9]
|
||||||
|
|
||||||
# import the files
|
# import the files
|
||||||
o.import_path = dfiles
|
o.import_path = dfiles
|
||||||
@@ -105,33 +117,45 @@ class TestCompare(unittest.TestCase):
|
|||||||
o = load_options(confpath, profile)
|
o = load_options(confpath, profile)
|
||||||
|
|
||||||
# compare the files
|
# compare the files
|
||||||
expected = {d1: True, d2: True, d3: True, d4: True, d5: True}
|
expected = {d1: True, d2: True, d3: True, d4: True,
|
||||||
|
d5: True, d9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(o, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify file
|
# modify file
|
||||||
edit_content(d1, get_string(20))
|
edit_content(d1, get_string(20))
|
||||||
expected = {d1: False, d2: True, d3: True, d4: True, d5: True}
|
expected = {d1: False, d2: True, d3: True, d4: True,
|
||||||
|
d5: True, d9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(o, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify binary file
|
# modify binary file
|
||||||
edit_content(d4, bytes(get_string(20), 'ascii'), binary=True)
|
edit_content(d4, bytes(get_string(20), 'ascii'), binary=True)
|
||||||
expected = {d1: False, d2: True, d3: True, d4: False, d5: True}
|
expected = {d1: False, d2: True, d3: True, d4: False,
|
||||||
|
d5: True, d9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(o, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# add file in directory
|
# add file in directory
|
||||||
d7, _ = create_random_file(d5)
|
d7, _ = create_random_file(d5)
|
||||||
self.assertTrue(os.path.exists(d7))
|
self.assertTrue(os.path.exists(d7))
|
||||||
expected = {d1: False, d2: True, d3: True, d4: False, d5: False}
|
expected = {d1: False, d2: True, d3: True, d4: False,
|
||||||
|
d5: False, d9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(o, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify all files
|
# modify all files
|
||||||
edit_content(d2, get_string(20))
|
edit_content(d2, get_string(20))
|
||||||
edit_content(d3, get_string(21))
|
edit_content(d3, get_string(21))
|
||||||
expected = {d1: False, d2: False, d3: False, d4: False, d5: False}
|
expected = {d1: False, d2: False, d3: False, d4: False,
|
||||||
|
d5: False, d9: True}
|
||||||
|
results = self.compare(o, tmp, len(dfiles))
|
||||||
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
|
# edit sub file
|
||||||
|
edit_content(d9f1, get_string(12))
|
||||||
|
expected = {d1: False, d2: False, d3: False, d4: False,
|
||||||
|
d5: False, d9: False}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(o, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user