def METHOD_NAME(filename1, filename2):
    import filecmp, os
    try:
        os.stat(filename1)
    except OSError:
        raise Exception("Error while reading '%s'." % filename1)
    try:
        os.stat(filename2)
    except OSError:
        raise Exception("Error while reading '%s'." % filename2)
    if filecmp.cmp(filename2,filename1,0):
        return True
    try:
        try:
            from osgeo import gdal
            from osgeo.osr import SpatialReference
        except ImportError:
            import gdal
            from osr import SpatialReference
        gdal.PushErrorHandler('CPLQuietErrorHandler')
        file1 = gdal.Open(filename1)
        gdal.PopErrorHandler()
        if file1 == None:
            raise Exception("Error while reading '%s' via GDAL." % filename1)
        file2 = gdal.Open(filename2)
        gdal.PopErrorHandler()
        if file2 == None:
            raise Exception("Error while reading '%s' via GDAL." % filename2)
        # Check image checksums
        print ("Checking checksums...")
        for band_num in range(1,file2.RasterCount+1):
            if file1.GetRasterBand(band_num).Checksum() != \
               file2.GetRasterBand(band_num).Checksum():
                raise Exception("Checksum of band '%s' differs: '%s' != '%s'." \
                                % (band_num, \
                                file1.GetRasterBand(band_num).Checksum(), \
                                file2.GetRasterBand(band_num).Checksum()))
            else:
                print ("Checksum of band '%s' matches and is '%s'." % \
                      (band_num, file1.GetRasterBand(band_num).Checksum()))
        # Check image size
        print "Checking size..."
        if file1.RasterXSize != file2.RasterXSize or \
           file1.RasterYSize != file2.RasterYSize:
            raise Exception("Size differs: '%s x %s' != '%s x %s'." % \
                            (file1.RasterXSize, file1.RasterYSize, 
                             file2.RasterXSize, file2.RasterYSize))
        # Check extent
        print ("Checking extent...")
        EPSILON = 1e-8
        extent1 = extent_from_ds(file1)
        extent2 = extent_from_ds(file2)
        if max([
            abs(extent1[i] - extent2[i]) for i in range(0, 4)
        ]) >= EPSILON:
            raise Exception("Extent differs: '%s' != '%s'." % \
                            ((', '.join(map(str, extent1))), 
                             (', '.join(map(str, extent2)))))
        # Check resolution
        print ("Checking resolution...")
        resolution1 = resolution_from_ds(file1)
        resolution2 = resolution_from_ds(file2)
        if resolution1[0] != resolution2[0] or resolution1[1] != resolution2[1]:
            raise Exception("Resolution differs: '%s' != '%s'." % \
                            ((', '.join(map(str, resolution1))), 
                             (', '.join(map(str, resolution2)))))
        # Check projection
        print ("Checking projection...")
        if file1.GetProjection() != file2.GetProjection():
            raise Exception("Projection differs.")
        # Check GCPs
        print ("Checking GCPs...")
        if file1.GetGCPCount() != file2.GetGCPCount():
            raise Exception("Number of GCPs differs: '%s' != '%s'." % \
                            (file1.GetGCPCount(), file2.GetGCPCount()))
        # Check GCP projection
        print ("Checking GCP projection...")
        if file1.GetGCPProjection() != file2.GetGCPProjection():
            raise Exception("GCP projection differs.")
        # Check metadata
        print ("Checking metadata...")
        file1_md = file1.GetMetadata()
        file2_md = file2.GetMetadata()
        if file1_md.keys() != file2_md.keys():
            raise Exception("Metadata keys don't match.")
        diffkeys = [k for k in file1_md if file1_md[k] != file2_md[k]]
        error = ""
        for k in diffkeys:
            error += "    %s: %s != %s\n" % (k, file1_md[k], file2_md[k])
        if len(diffkeys) > 0:
            raise Exception("Metadata not equal:\n%s" % error)
    except Exception as e:
        raise Exception("Comparison via GDAL failed: '%s'" % e)