本文整理汇总了Python中diffoscope.difference.Difference类的典型用法代码示例。如果您正苦于以下问题:Python Difference类的具体用法?Python Difference怎么用?Python Difference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Difference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _compare_using_details
def _compare_using_details(self, other, source):
details = [d for d in self.compare_details(other, source) if d is not None]
if len(details) == 0:
return None
difference = Difference(None, self.name, other.name, source=source)
difference.add_details(details)
return difference
示例2: compare_commented_files
def compare_commented_files(file1, file2, comment=None, source=None):
difference = compare_files(file1, file2, source=source)
if comment:
if difference is None:
difference = Difference(None, file1.name, file2.name)
difference.add_comment(comment)
return difference
示例3: compare_details
def compare_details(self, other, source=None):
differences = []
for field in sorted(set(self.deb822.keys()).union(set(other.deb822.keys()))):
if field.startswith('Checksums-') or field == 'Files':
continue
my_value = ''
if field in self.deb822:
my_value = self.deb822.get_as_string(field).lstrip()
other_value = ''
if field in other.deb822:
other_value = other.deb822.get_as_string(field).lstrip()
differences.append(Difference.from_text(
my_value, other_value,
self.path, other.path, source=field))
# compare Files as string
if self.deb822.get('Files'):
differences.append(Difference.from_text(self.deb822.get_as_string('Files'),
other.deb822.get_as_string('Files'),
self.path, other.path, source='Files'))
else:
differences.append(Difference.from_text(self.deb822.get_as_string('Checksums-Sha256'),
other.deb822.get_as_string('Checksums-Sha256'),
self.path, other.path, source='Checksums-Sha256'))
return differences
示例4: compare_details
def compare_details(self, other, source=None):
differences = []
differences.append(Difference.from_command(SquashfsSuperblock, self.path, other.path))
differences.append(Difference.from_command(SquashfsListing, self.path, other.path))
with SquashfsContainer(self).open() as my_container, \
SquashfsContainer(other).open() as other_container:
differences.extend(my_container.compare(other_container))
return differences
示例5: compare_binary_files
def compare_binary_files(file1, file2, source=None):
import diffoscope.comparators.utils
try:
return Difference.from_command(diffoscope.comparators.utils.Xxd, file1.path, file2.path, source=[file1.name, file2.name])
except RequiredToolNotFound:
hexdump1 = hexdump_fallback(file1.path)
hexdump2 = hexdump_fallback(file2.path)
comment = 'xxd not available in path. Falling back to Python hexlify.\n'
return Difference.from_text(hexdump1, hexdump2, file1.name, file2.name, source, comment)
示例6: compare_binary_files
def compare_binary_files(file1, file2, source=None):
try:
with xxd(file1.path) as xxd1, xxd(file2.path) as xxd2:
return Difference.from_raw_readers(xxd1, xxd2, file1.name, file2.name, source)
except RequiredToolNotFound:
hexdump1 = hexdump_fallback(file1.path)
hexdump2 = hexdump_fallback(file2.path)
comment = 'xxd not available in path. Falling back to Python hexlify.\n'
return Difference.from_text(hexdump1, hexdump2, file1.name, file2.name, source, comment)
示例7: compare_details
def compare_details(self, other, source=None):
differences = []
differences.append(Difference.from_command(ISO9660PVD, self.path, other.path))
differences.append(Difference.from_command(ISO9660Listing, self.path, other.path))
for extension in ('joliet', 'rockridge'):
try:
differences.append(Difference.from_command(ISO9660Listing, self.path, other.path, command_args=(extension,)))
except subprocess.CalledProcessError:
pass # probably no joliet or rockridge data
return differences
示例8: compare_details
def compare_details(self, other, source=None):
differences = []
# look up differences in metadata
zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
Difference.from_command(ZipinfoVerbose, self.path, other.path)
differences.append(zipinfo_difference)
with ZipContainer(self).open() as my_container, \
ZipContainer(other).open() as other_container:
differences.extend(my_container.compare(other_container))
return differences
示例9: _compare_using_details
def _compare_using_details(self, other, source):
details = []
if hasattr(self, 'compare_details'):
details.extend(filter(None, self.compare_details(other, source)))
if self.as_container:
details.extend(filter(None, self.as_container.compare(other.as_container)))
if not details:
return None
difference = Difference(None, self.name, other.name, source=source)
difference.add_details(details)
return difference
示例10: compare_details
def compare_details(self, other, source=None):
differences = []
differences.append(Difference.from_command(ISO9660PVD, self.path, other.path))
differences.append(Difference.from_command(ISO9660Listing, self.path, other.path))
for extension in ('joliet', 'rockridge'):
try:
differences.append(Difference.from_command(ISO9660Listing, self.path, other.path, command_args=(extension,)))
except subprocess.CalledProcessError:
pass # probably no joliet or rockridge data
with LibarchiveContainer(self).open() as my_container, \
LibarchiveContainer(other).open() as other_container:
differences.extend(my_container.compare(other_container))
return differences
示例11: compare
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)
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)
示例12: compare_details
def compare_details(self, other, source=None):
return [Difference.from_text(
json.dumps(self.parsed, indent=4, sort_keys=True),
json.dumps(other.parsed, indent=4, sort_keys=True),
self,
other,
)]
示例13: compare_details
def compare_details(self, other, source=None):
differences = []
differences.append(Difference.from_text_readers(list_libarchive(self.path),
list_libarchive(other.path),
self.path, other.path, source="file list"))
differences.extend(_compare_elf_data(self.path, other.path))
return differences
示例14: compare_details
def compare_details(self, other, source=None):
differences = []
with TarContainer(self).open() as my_container, \
TarContainer(other).open() as other_container:
differences.append(Difference.from_command(TarListing, self.path, other.path))
differences.extend(my_container.compare(other_container))
return differences
示例15: compare_details
def compare_details(self, other, source=None):
differences = []
differences.append(Difference.from_text(
self.magic_file_type, other.magic_file_type, self, other, source='metadata'))
with GzipContainer(self).open() as my_container, \
GzipContainer(other).open() as other_container:
differences.extend(my_container.compare(other_container))
return differences