1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-08 01:34:23 +00:00

modes install and compare

This commit is contained in:
deadc0de6
2020-11-12 22:24:09 +01:00
parent c07a865809
commit 2bb684d3da
8 changed files with 349 additions and 108 deletions

View File

@@ -10,7 +10,8 @@ import filecmp
# local imports
from dotdrop.logger import Logger
from dotdrop.utils import must_ignore, uniq_list, diff
from dotdrop.utils import must_ignore, uniq_list, diff, \
get_file_perm
class Comparator:
@@ -31,6 +32,7 @@ class Comparator:
if self.debug:
self.log.dbg('comparing {} and {}'.format(left, right))
self.log.dbg('ignore pattern(s): {}'.format(ignore))
# test type of file
if os.path.isdir(left) and not os.path.isdir(right):
return '\"{}\" is a dir while \"{}\" is a file\n'.format(left,
@@ -38,14 +40,32 @@ class Comparator:
if not os.path.isdir(left) and os.path.isdir(right):
return '\"{}\" is a file while \"{}\" is a dir\n'.format(left,
right)
# test content
if not os.path.isdir(left):
if self.debug:
self.log.dbg('is file')
return self._comp_file(left, right, ignore)
ret = self._comp_file(left, right, ignore)
if not ret:
ret = self._comp_mode(left, right)
return ret
if self.debug:
self.log.dbg('is directory')
return self._comp_dir(left, right, ignore)
ret = self._comp_dir(left, right, ignore)
if not ret:
ret = self._comp_mode(left, right)
return ret
def _comp_mode(self, left, right):
"""compare mode"""
left_mode = get_file_perm(left)
right_mode = get_file_perm(right)
if left_mode == right_mode:
return ''
ret = 'modes differ ({} vs {})\n'.format(left_mode, right_mode)
return ret
def _comp_file(self, left, right, ignore):
"""compare a file"""