Exemplo n.º 1
0
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?")
    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="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]
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 def compare(self, other, source=None):
     differences = []
     try:
         find_diff = Difference.from_command(FindAll, self.path, other.path)
         if find_diff:
             differences.append(find_diff)
     except RequiredToolNotFound:
         logger.info("Unable to find 'getfacl'.")
     differences.extend(compare_meta(self.name, other.name))
     with DirectoryContainer(self).open() as my_container, \
          DirectoryContainer(other).open() as other_container:
         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)
             with my_file.get_content(), other_file.get_content():
                 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
Exemplo n.º 5
0
 def validate(self, check_hash="sha1", check_signature=True):
     """
     See :meth:`validate_checksums` for ``check_hash``, and
     :meth:`validate_signature` if ``check_signature`` is True.
     """
     self.validate_checksums(check_hash)
     if check_signature:
         self.validate_signature(check_signature)
     else:
         logger.info("Not checking signature")
Exemplo n.º 6
0
 def validate(self, check_hash="sha1", check_signature=True):
     """
     See :meth:`validate_checksums` for ``check_hash``, and
     :meth:`validate_signature` if ``check_signature`` is True.
     """
     self.validate_checksums(check_hash)
     if check_signature:
         self.validate_signature(check_signature)
     else:
         logger.info("Not checking signature")
Exemplo n.º 7
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    signal.signal(signal.SIGTERM, sigterm_handler)
    parsed_args = None
    try:
        parser = create_parser()
        parsed_args = parser.parse_args(args)
        sys.exit(run_diffoscope(parsed_args))
    except KeyboardInterrupt:
        logger.info('Keyboard Interrupt')
        sys.exit(2)
    except Exception:
        traceback.print_exc()
        if parsed_args and parsed_args.debugger:
            import pdb
            pdb.post_mortem()
        sys.exit(2)
Exemplo n.º 8
0
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]
Exemplo n.º 9
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    signal.signal(signal.SIGTERM, sigterm_handler)
    parsed_args = None
    try:
        parser = create_parser()
        parsed_args = parser.parse_args(args)
        sys.exit(run_diffoscope(parsed_args))
    except KeyboardInterrupt:
        logger.info('Keyboard Interrupt')
        sys.exit(2)
    except Exception:
        traceback.print_exc()
        if parsed_args and parsed_args.debugger:
            import pdb
            pdb.post_mortem()
        sys.exit(2)
    finally:
        clean_all_temp_files()