本文整理汇总了Python中diffoscope.difference.Difference.from_text方法的典型用法代码示例。如果您正苦于以下问题:Python Difference.from_text方法的具体用法?Python Difference.from_text怎么用?Python Difference.from_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类diffoscope.difference.Difference
的用法示例。
在下文中一共展示了Difference.from_text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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
示例2: compare
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
def compare(self, other, source=None):
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()
for name in sorted(set(my_names).intersection(other_names)):
my_file = my_container.get_member(name)
other_file = other_container.get_member(name)
inner_difference = diffoscope.comparators.compare_files(
my_file, other_file, source=name)
meta_differences = compare_meta(my_file.name, other_file.name)
if meta_differences and not inner_difference:
inner_difference = Difference(None, my_file.path, other_file.path)
if inner_difference:
inner_difference.add_details(meta_differences)
differences.append(inner_difference)
if not differences:
return None
difference = Difference(None, self.path, other.path, source)
difference.add_details(differences)
return difference
示例3: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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,
)]
示例4: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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
示例5: compare_binary_files
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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)
示例6: compare_rpm_headers
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
def compare_rpm_headers(path1, path2):
# compare headers
with get_temporary_directory() as rpmdb_dir:
rpm.addMacro("_dbpath", rpmdb_dir)
ts = rpm.TransactionSet()
ts.setVSFlags(-1)
header1 = get_rpm_header(path1, ts)
header2 = get_rpm_header(path2, ts)
return Difference.from_text(header1, header2, path1, path2, source="header")
示例7: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
def compare_details(self, other, source=None):
differences = []
# look up differences in metadata
content1 = get_ar_content(self.path)
content2 = get_ar_content(other.path)
differences.append(Difference.from_text(
content1, content2, self.path, other.path, source="metadata"))
differences.extend(_compare_elf_data(self.path, other.path))
return differences
示例8: compare_binary_files
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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)
示例9: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
def compare_details(self, other, source=None):
differences = []
my_content = get_ar_content(self.path)
other_content = get_ar_content(other.path)
differences.append(Difference.from_text(
my_content, other_content, self.path, other.path, source="metadata"))
with DebContainer(self).open() as my_container, \
DebContainer(other).open() as other_container:
differences.extend(my_container.compare(other_container))
return differences
示例10: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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
示例11: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
def compare_details(self, other, source=None):
differences = []
with FsImageContainer(self).open() as my_container, \
FsImageContainer(other).open() as other_container:
my_fs = ''
other_fs = ''
if hasattr(my_container, 'fs'):
my_fs = my_container.fs
if hasattr(other_container, 'fs'):
other_fs = other_container.fs
if my_fs != other_fs:
differences.append(Difference.from_text(my_fs, other_fs,
None, None, source="filesystem"))
differences.extend(my_container.compare(other_container))
return differences
示例12: compare
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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)
示例13: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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
differences.append(Difference.from_text(self.deb822.get_as_string('Files'),
other.deb822.get_as_string('Files'),
self.path, other.path, source='Files'))
with DebControlContainer(self).open() as my_container, \
DebControlContainer(other).open() as other_container:
differences.extend(my_container.compare(other_container))
return differences
示例14: compare_meta
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
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.warn("'stat' not found! Is PATH wrong?")
try:
lsattr1 = lsattr(path1)
lsattr2 = lsattr(path2)
differences.append(Difference.from_text(
lsattr1, lsattr2, path1, path2, source="lattr"))
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]
示例15: compare_details
# 需要导入模块: from diffoscope.difference import Difference [as 别名]
# 或者: from diffoscope.difference.Difference import from_text [as 别名]
def compare_details(self, other, source=None):
differences = []
# Check for fat binaries, trigger a difference if the architectures differ
my_archs = MachoFile.get_arch_from_macho(self.path)
other_archs = MachoFile.get_arch_from_macho(other.path)
differences.append(Difference.from_text('\n'.join(my_archs),
'\n'.join(other_archs),
self.name, other.name, source='architectures'))
# Compare common architectures for differences
for common_arch in set(my_archs) & set(other_archs):
differences.append(Difference.from_command(OtoolHeaders, self.path, other.path, command_args=[common_arch],
comment="Mach-O headers for architecture %s" % common_arch))
differences.append(Difference.from_command(OtoolLibraries, self.path, other.path, command_args=[common_arch],
comment="Mach-O load commands for architecture %s" % common_arch))
differences.append(Difference.from_command(OtoolDisassemble, self.path, other.path, command_args=[common_arch],
comment="Code for architecture %s" % common_arch))
return differences