mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-08 11:24:16 +00:00
linting
This commit is contained in:
@@ -38,33 +38,28 @@ class Comparator:
|
||||
ignore = []
|
||||
local_path = os.path.expanduser(local_path)
|
||||
deployed_path = os.path.expanduser(deployed_path)
|
||||
self.log.dbg('comparing {} and {}'.format(
|
||||
local_path,
|
||||
deployed_path,
|
||||
))
|
||||
self.log.dbg('ignore pattern(s): {}'.format(ignore))
|
||||
self.log.dbg(f'comparing {local_path} and {deployed_path}')
|
||||
self.log.dbg(f'ignore pattern(s): {ignore}')
|
||||
|
||||
# test type of file
|
||||
if os.path.isdir(local_path) and not os.path.isdir(deployed_path):
|
||||
return '\"{}\" is a dir while \"{}\" is a file\n'.format(
|
||||
local_path,
|
||||
deployed_path,
|
||||
)
|
||||
ret = f'\"{local_path}\" is a dir'
|
||||
ret += f' while \"{deployed_path}\" is a file\n'
|
||||
return ret
|
||||
if not os.path.isdir(local_path) and os.path.isdir(deployed_path):
|
||||
return '\"{}\" is a file while \"{}\" is a dir\n'.format(
|
||||
local_path,
|
||||
deployed_path,
|
||||
)
|
||||
ret = f'\"{local_path}\" is a file'
|
||||
ret += f' while \"{deployed_path}\" is a dir\n'
|
||||
return ret
|
||||
|
||||
# test content
|
||||
if not os.path.isdir(local_path):
|
||||
self.log.dbg('{} is a file'.format(local_path))
|
||||
self.log.dbg(f'{local_path} is a file')
|
||||
ret = self._comp_file(local_path, deployed_path, ignore)
|
||||
if not ret:
|
||||
ret = self._comp_mode(local_path, deployed_path, mode=mode)
|
||||
return ret
|
||||
|
||||
self.log.dbg('{} is a directory'.format(local_path))
|
||||
self.log.dbg(f'{local_path} is a directory')
|
||||
|
||||
ret = self._comp_dir(local_path, deployed_path, ignore)
|
||||
if not ret:
|
||||
@@ -82,79 +77,68 @@ class Comparator:
|
||||
deployed_mode = get_file_perm(deployed_path)
|
||||
if local_mode == deployed_mode:
|
||||
return ''
|
||||
msg = 'mode differ {} ({:o}) and {} ({:o})'
|
||||
self.log.dbg(msg.format(local_path, local_mode, deployed_path,
|
||||
deployed_mode))
|
||||
ret = 'modes differ for {} ({:o}) vs {:o}\n'
|
||||
return ret.format(deployed_path, deployed_mode, local_mode)
|
||||
msg = f'mode differ {local_path} ({local_mode:o}) '
|
||||
msg += f'and {deployed_path} ({deployed_mode:o})'
|
||||
self.log.dbg(msg)
|
||||
ret = f'modes differ for {deployed_path} '
|
||||
ret += f'({deployed_mode:o}) vs {local_mode:o}\n'
|
||||
return ret
|
||||
|
||||
def _comp_file(self, local_path, deployed_path, ignore):
|
||||
"""compare a file"""
|
||||
self.log.dbg('compare file {} with {}'.format(
|
||||
local_path,
|
||||
deployed_path,
|
||||
))
|
||||
self.log.dbg(f'compare file {local_path} with {deployed_path}')
|
||||
if (self.ignore_missing_in_dotdrop and not
|
||||
os.path.exists(local_path)) \
|
||||
or must_ignore([local_path, deployed_path], ignore,
|
||||
debug=self.debug):
|
||||
self.log.dbg('ignoring diff {} and {}'.format(
|
||||
local_path,
|
||||
deployed_path,
|
||||
))
|
||||
self.log.dbg(f'ignoring diff {local_path} and {deployed_path}')
|
||||
return ''
|
||||
return self._diff(local_path, deployed_path)
|
||||
|
||||
def _comp_dir(self, local_path, deployed_path, ignore):
|
||||
"""compare a directory"""
|
||||
self.log.dbg('compare directory {} with {}'.format(
|
||||
local_path,
|
||||
deployed_path,
|
||||
))
|
||||
self.log.dbg(f'compare directory {local_path} with {deployed_path}')
|
||||
if not os.path.exists(deployed_path):
|
||||
return ''
|
||||
if (self.ignore_missing_in_dotdrop and not
|
||||
os.path.exists(local_path)) \
|
||||
or must_ignore([local_path, deployed_path], ignore,
|
||||
debug=self.debug):
|
||||
self.log.dbg('ignoring diff {} and {}'.format(
|
||||
local_path,
|
||||
deployed_path,
|
||||
))
|
||||
self.log.dbg(f'ignoring diff {local_path} and {deployed_path}')
|
||||
return ''
|
||||
if not os.path.isdir(deployed_path):
|
||||
return '\"{}\" is a file\n'.format(deployed_path)
|
||||
return f'\"{deployed_path}\" is a file\n'
|
||||
|
||||
return self._compare_dirs(local_path, deployed_path, ignore)
|
||||
|
||||
def _compare_dirs(self, local_path, deployed_path, ignore):
|
||||
"""compare directories"""
|
||||
self.log.dbg('compare {} and {}'.format(local_path, deployed_path))
|
||||
self.log.dbg(f'compare {local_path} and {deployed_path}')
|
||||
ret = []
|
||||
comp = filecmp.dircmp(local_path, deployed_path)
|
||||
|
||||
# handle files only in deployed dir
|
||||
self.log.dbg('files only in deployed dir: {}'.format(comp.left_only))
|
||||
self.log.dbg(f'files only in deployed dir: {comp.left_only}')
|
||||
for i in comp.left_only:
|
||||
if self.ignore_missing_in_dotdrop or \
|
||||
must_ignore([os.path.join(local_path, i)],
|
||||
ignore, debug=self.debug):
|
||||
continue
|
||||
ret.append('=> \"{}\" does not exist on destination\n'.format(i))
|
||||
ret.append(f'=> \"{i}\" does not exist on destination\n')
|
||||
|
||||
# handle files only in dotpath dir
|
||||
self.log.dbg('files only in dotpath dir: {}'.format(comp.right_only))
|
||||
self.log.dbg(f'files only in dotpath dir: {comp.right_only}')
|
||||
for i in comp.right_only:
|
||||
if must_ignore([os.path.join(deployed_path, i)],
|
||||
ignore, debug=self.debug):
|
||||
continue
|
||||
|
||||
if not self.ignore_missing_in_dotdrop:
|
||||
ret.append('=> \"{}\" does not exist in dotdrop\n'.format(i))
|
||||
ret.append(f'=> \"{i}\" does not exist in dotdrop\n')
|
||||
|
||||
# same local_path and deployed_path but different type
|
||||
funny = comp.common_funny
|
||||
self.log.dbg('files with different types: {}'.format(funny))
|
||||
self.log.dbg(f'files with different types: {funny}')
|
||||
for i in funny:
|
||||
source_file = os.path.join(local_path, i)
|
||||
deployed_file = os.path.join(deployed_path, i)
|
||||
@@ -166,13 +150,13 @@ class Comparator:
|
||||
continue
|
||||
short = os.path.basename(source_file)
|
||||
# file vs dir
|
||||
ret.append('=> different type: \"{}\"\n'.format(short))
|
||||
ret.append(f'=> different type: \"{short}\"\n')
|
||||
|
||||
# content is different
|
||||
funny = comp.diff_files
|
||||
funny.extend(comp.funny_files)
|
||||
funny = uniq_list(funny)
|
||||
self.log.dbg('files with different content: {}'.format(funny))
|
||||
self.log.dbg(f'files with different content: {funny}')
|
||||
for i in funny:
|
||||
source_file = os.path.join(local_path, i)
|
||||
deployed_file = os.path.join(deployed_path, i)
|
||||
@@ -198,5 +182,5 @@ class Comparator:
|
||||
diff_cmd=self.diff_cmd, debug=self.debug)
|
||||
if header:
|
||||
lshort = os.path.basename(local_path)
|
||||
out = '=> diff \"{}\":\n{}'.format(lshort, out)
|
||||
out = f'=> diff \"{lshort}\":\n{out}'
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user