Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def compare_details(self, other, source=None):
difference = Difference.from_text(self.dumps(self), self.dumps(other),
self.path, other.path)
if difference:
return [difference]
difference = Difference.from_text(self.dumps(self, sort_keys=False),
self.dumps(other, sort_keys=False),
self.path, other.path,
comment="ordering differences only")
return [difference]
def compare(self, other, source=None):
my_encoding = self.encoding or 'utf-8'
other_encoding = other.encoding or 'utf-8'
try:
with codecs.open(self.path, 'r', encoding=my_encoding) as my_content, \
codecs.open(other.path, 'r', encoding=other_encoding) as other_content:
difference = Difference.from_text_readers(my_content, other_content, self.name, other.name, source)
# Check if difference is only in line order.
if difference and order_only_difference(difference.unified_diff):
difference.add_comment("ordering differences only")
if my_encoding != other_encoding:
if difference is None:
difference = Difference(None, self.path, other.path, source)
difference.add_details([Difference.from_text(my_encoding, other_encoding, None, None, source='encoding')])
return difference
except (LookupError, UnicodeDecodeError):
# unknown or misdetected encoding
return self.compare_bytes(other, source)
def compare(self, other, source=None):
from .utils.compare import compare_files
differences = []
try:
listing_diff = Difference.from_text('\n'.join(list_files(self.path)),
'\n'.join(list_files(other.path)),
self.path, other.path, source='file list')
if listing_diff:
differences.append(listing_diff)
except RequiredToolNotFound:
logger.info("Unable to find 'getfacl'.")
differences.extend(compare_meta(self.name, other.name))
my_container = DirectoryContainer(self)
other_container = DirectoryContainer(other)
my_names = my_container.get_member_names()
other_names = other_container.get_member_names()
to_compare = set(my_names).intersection(other_names)
to_compare = set(filter_excludes(to_compare))
with Progress(len(to_compare)) as p:
for name in sorted(to_compare):
my_file = my_container.get_member(name)
def compare_details(self, other, source=None):
return [Difference.from_text(
describe_index(self.path),
describe_index(other.path),
self.path,
other.path,
)]
def compare_details(self, other, source=None):
differences = []
my_fs = ''
other_fs = ''
if hasattr(self.as_container, 'fs'):
my_fs = self.as_container.fs
if hasattr(other.as_container, 'fs'):
other_fs = other.as_container.fs
if my_fs != other_fs:
differences.append(Difference.from_text(my_fs, other_fs, None, None, source="filesystem"))
return differences
def compare_meta(path1, path2):
logger.debug('compare_meta(%s, %s)', path1, path2)
differences = []
try:
differences.append(Difference.from_command(Stat, path1, path2))
except RequiredToolNotFound:
logger.warning("'stat' not found! Is PATH wrong?")
if os.path.islink(path1) or os.path.islink(path2):
return [d for d in differences if d is not None]
try:
lsattr1 = lsattr(path1)
lsattr2 = lsattr(path2)
differences.append(Difference.from_text(
lsattr1, lsattr2, path1, path2, source="lsattr"))
except RequiredToolNotFound:
logger.info("Unable to find 'lsattr'.")
try:
differences.append(Difference.from_command(Getfacl, path1, path2))
except RequiredToolNotFound:
logger.info("Unable to find 'getfacl'.")
return [d for d in differences if d is not None]
def compare_details(self, other, source=None):
return [Difference.from_text(self.magic_file_type, other.magic_file_type, self, other, source='metadata')]
def compare_bytes(self, other, source=None):
from .compare import compare_binary_files
# Don't attempt to compare directories with any other type as binaries
if os.path.isdir(self.path) or os.path.isdir(other.path):
return Difference.from_text(
"type: {}".format(self.file_type),
"type: {}".format(other.file_type),
self.name,
other.name,
source,
)
return compare_binary_files(self, other, source)