def vsizip_5(): # make file in memory fmain = gdal.VSIFOpenL('/vsizip/vsimem/bigdepthzip.zip', 'wb') if fmain is None: gdaltest.post_reason('fail') return 'fail' filename = "a" for i in range(1000): filename = filename + "/a" finside = gdal.VSIFOpenL('/vsizip/vsimem/bigdepthzip.zip/' + filename, 'wb') if finside is None: gdaltest.post_reason('fail') return 'fail' gdal.VSIFCloseL(finside) gdal.VSIFCloseL(fmain) # read recursive and validate content res = gdal.ReadDirRecursive("/vsizip/vsimem/bigdepthzip.zip") if res is None: gdaltest.post_reason('fail read') return 'fail' if len(res) != 1001: gdaltest.post_reason('wrong size: ' + str(len(res))) return 'fail' if res[10] != 'a/a/a/a/a/a/a/a/a/a/a/': gdaltest.post_reason('bad content: ' + res[10]) return 'fail' return 'success'
def test_vsizip_4(): # read recursive and validate content res = gdal.ReadDirRecursive("/vsizip/data/testzip.zip") assert res is not None, 'fail read' assert (res == ['subdir/', 'subdir/subdir/', 'subdir/subdir/uint16.tif', 'subdir/subdir/test_rpc.txt', 'subdir/test_rpc.txt', 'test_rpc.txt', 'uint16.tif']), 'bad content'
def test_gdal2tiles_vsimem(): gdal2tiles.main( argv=['-q', '../../gcore/data/byte.tif', '/vsimem/gdal2tiles']) assert set(gdal.ReadDirRecursive('/vsimem/gdal2tiles')) == set([ '14/', '14/2837/', '14/2837/9833.png', '14/2838/', '14/2838/9833.png', 'googlemaps.html', 'leaflet.html', 'openlayers.html', 'tilemapresource.xml' ]) gdal.RmdirRecursive('/vsimem/gdal2tiles')
def vsizip_4(): # read recursive and validate content res = gdal.ReadDirRecursive("/vsizip/data/testzip.zip") if res is None: gdaltest.post_reason('fail read') return 'fail' if res != ['subdir/', 'subdir/subdir/', 'subdir/subdir/uint16.tif', \ 'subdir/subdir/test_rpc.txt', 'subdir/test_rpc.txt', \ 'test_rpc.txt', 'uint16.tif']: gdaltest.post_reason('bad content') print(res) return 'fail' return 'success'
def test_vsizip_5(): # make file in memory fmain = gdal.VSIFOpenL('/vsizip/vsimem/bigdepthzip.zip', 'wb') assert fmain is not None filename = "a" + "/a" * 1000 finside = gdal.VSIFOpenL('/vsizip/vsimem/bigdepthzip.zip/' + filename, 'wb') assert finside is not None gdal.VSIFCloseL(finside) gdal.VSIFCloseL(fmain) # read recursive and validate content res = gdal.ReadDirRecursive("/vsizip/vsimem/bigdepthzip.zip") assert res is not None, 'fail read' assert len(res) == 1001, ('wrong size: ' + str(len(res))) assert res[10] == 'a/a/a/a/a/a/a/a/a/a/a/', ('bad content: ' + res[10]) gdal.Unlink("/vsimem/bigdepthzip.zip")
def misc_6_internal(datatype, nBands, setDriversDone): ds = gdal.GetDriverByName('MEM').Create('', 10, 10, nBands, datatype) if nBands > 0: ds.GetRasterBand(1).Fill(255) ds.SetGeoTransform([2, 1.0 / 10, 0, 49, 0, -1.0 / 10]) ds.SetProjection( 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.01745329251994328]]' ) ds.SetMetadata(['a']) for i in range(gdal.GetDriverCount()): drv = gdal.GetDriver(i) md = drv.GetMetadata() if ('DCAP_CREATECOPY' in md or 'DCAP_CREATE' in md) and 'DCAP_RASTER' in md: # print ('drv = %s, nBands = %d, datatype = %s' % (drv.ShortName, nBands, gdal.GetDataTypeName(datatype))) skip = False # FIXME: A few cases that crashes and should be investigated if drv.ShortName == 'JPEG2000': if (nBands == 2 or nBands >= 5) or \ not (datatype == gdal.GDT_Byte or datatype == gdal.GDT_Int16 or datatype == gdal.GDT_UInt16): skip = True if skip is False: dirname = 'tmp/tmp/tmp_%s_%d_%s' % ( drv.ShortName, nBands, gdal.GetDataTypeName(datatype)) try: os.mkdir(dirname) except OSError: try: os.stat(dirname) # Hum the directory already exists... Not expected, but let's try to go on except OSError: reason = 'Cannot create %s before drv = %s, nBands = %d, datatype = %s' % ( dirname, drv.ShortName, nBands, gdal.GetDataTypeName(datatype)) gdaltest.post_reason(reason) return 'fail' filename = get_filename(drv, dirname) dst_ds = drv.CreateCopy(filename, ds) has_succeeded = dst_ds is not None dst_ds = None size = 0 stat = gdal.VSIStatL(filename) if stat is not None: size = stat.size try: shutil.rmtree(dirname) except OSError: reason = 'Cannot remove %s after drv = %s, nBands = %d, datatype = %s' % ( dirname, drv.ShortName, nBands, gdal.GetDataTypeName(datatype)) gdaltest.post_reason(reason) return 'fail' if has_succeeded and drv.ShortName not in setDriversDone and nBands > 0: setDriversDone.add(drv.ShortName) # The first list of drivers fail to detect short writing # The second one is because they are verbose in stderr if 'DCAP_VIRTUALIO' in md and size != 0 and \ drv.ShortName not in ['JPEG2000', 'KMLSUPEROVERLAY', 'HF2', 'ZMap', 'DDS'] and \ drv.ShortName not in ['GIF', 'JP2ECW', 'JP2Lura']: for j in range(10): truncated_size = (size * j) / 10 vsimem_filename = ( '/vsimem/test_truncate/||maxlength=%d||' % truncated_size) + get_filename(drv, '')[1:] # print('drv = %s, nBands = %d, datatype = %s, truncated_size = %d' % (drv.ShortName, nBands, gdal.GetDataTypeName(datatype), truncated_size)) dst_ds = drv.CreateCopy(vsimem_filename, ds) error_detected = False if dst_ds is None: error_detected = True else: gdal.ErrorReset() dst_ds = None if gdal.GetLastErrorMsg() != '': error_detected = True if not error_detected: msg = 'write error not decteded with with drv = %s, nBands = %d, datatype = %s, truncated_size = %d' % ( drv.ShortName, nBands, gdal.GetDataTypeName(datatype), truncated_size) print(msg) gdaltest.post_reason(msg) fl = gdal.ReadDirRecursive('/vsimem/test_truncate') if fl is not None: for myf in fl: gdal.Unlink('/vsimem/test_truncate/' + myf) fl = gdal.ReadDirRecursive( '/vsimem/test_truncate') if fl is not None: print(fl) if drv.ShortName not in [ 'ECW', 'JP2ECW', 'VRT', 'XPM', 'JPEG2000', 'FIT', 'RST', 'INGR', 'USGSDEM', 'KMLSUPEROVERLAY', 'GMT' ]: dst_ds = drv.CreateCopy( filename, ds, callback=misc_6_interrupt_callback_class().cbk) if dst_ds is not None: gdaltest.post_reason( 'interruption did not work with drv = %s, nBands = %d, datatype = %s' % (drv.ShortName, nBands, gdal.GetDataTypeName(datatype))) dst_ds = None try: shutil.rmtree(dirname) except OSError: pass return 'fail' dst_ds = None try: shutil.rmtree(dirname) except OSError: pass try: os.mkdir(dirname) except OSError: reason = 'Cannot create %s before drv = %s, nBands = %d, datatype = %s' % ( dirname, drv.ShortName, nBands, gdal.GetDataTypeName(datatype)) gdaltest.post_reason(reason) return 'fail' ds = None return 'success'