def vsizip_3(): fmain = gdal.VSIFOpenL("/vsizip/vsimem/test3.zip", "wb") f = gdal.VSIFOpenL("/vsizip/vsimem/test3.zip/foo", "wb") gdal.VSIFWriteL("foo", 1, 3, f) gdal.VSIFCloseL(f) f = gdal.VSIFOpenL("/vsizip/vsimem/test3.zip/bar", "wb") gdal.VSIFWriteL("bar", 1, 3, f) gdal.VSIFCloseL(f) gdal.VSIFCloseL(fmain) gdal.ReadDir("/vsizip/vsimem/test3.zip") f = gdal.VSIFOpenL("/vsizip/vsimem/test3.zip/baz", "wb") gdal.VSIFWriteL("baz", 1, 3, f) gdal.VSIFCloseL(f) res = gdal.ReadDir("/vsizip/vsimem/test3.zip") gdal.Unlink("/vsimem/test3.zip") if res != ['foo', 'bar', 'baz']: print(res) return 'fail' return 'success'
def ogr_libkml_check_write_dir(): if not ogrtest.have_read_libkml: return 'skip' ret = ogr_libkml_check_write('/vsimem/libkmldir') files = gdal.ReadDir('/vsimem/libkmldir') for filename in files: gdal.Unlink('/vsimem/libkmldir/' + filename) gdal.Rmdir('/vsimem/libkmldir') return ret
def identify_2(): if gdaltest.IdentifyDriver is None: return 'skip' file_list = gdal.ReadDir( 'data' ) dr = gdal.IdentifyDriver( 'data/byte.pnm.aux.xml', file_list ) if dr is not None: gdaltest.post_reason( 'Got a driver for byte.pnm.aux.xml!' ) return 'fail' return 'success'
def identify_1(): try: gdaltest.IdentifyDriver = gdal.IdentifyDriver except: gdaltest.IdentifyDriver = None return 'skip' file_list = gdal.ReadDir( 'data' ) dr = gdal.IdentifyDriver( 'data/byte.tif', file_list ) if dr is None or dr.GetDescription() != 'GTiff': gdaltest.post_reason( 'Got wrong driver for byte.tif' ) return 'fail' return 'success'
def vsizip_2(): fmain = gdal.VSIFOpenL("/vsizip/vsimem/test2.zip/foo.bar", "wb") if fmain is None: gdaltest.post_reason('fail 1') return 'fail' gdal.VSIFWriteL("12345", 1, 5, fmain) gdal.VSIFCloseL(fmain) content = gdal.ReadDir("/vsizip/vsimem/test2.zip") if content != ['foo.bar']: gdaltest.post_reason('bad content 1') print(content) return 'fail' # Now append a second file fmain = gdal.VSIFOpenL("/vsizip/vsimem/test2.zip/bar.baz", "wb") if fmain is None: gdaltest.post_reason('fail 2') return 'fail' gdal.VSIFWriteL("67890", 1, 5, fmain) gdal.ErrorReset() gdal.PushErrorHandler('CPLQuietErrorHandler') content = gdal.ReadDir("/vsizip/vsimem/test2.zip") gdal.PopErrorHandler() if gdal.GetLastErrorMsg() != 'Cannot read a zip file being written': gdaltest.post_reason('expected error') print(gdal.GetLastErrorMsg()) return 'fail' if content != None: gdaltest.post_reason('bad content 2') print(content) return 'fail' gdal.VSIFCloseL(fmain) content = gdal.ReadDir("/vsizip/vsimem/test2.zip") if content != ['foo.bar', 'bar.baz']: gdaltest.post_reason('bad content 3') print(content) return 'fail' fmain = gdal.VSIFOpenL("/vsizip/vsimem/test2.zip/foo.bar", "rb") if fmain is None: gdaltest.post_reason('fail 3') return 'fail' data = gdal.VSIFReadL(1, 5, fmain) gdal.VSIFCloseL(fmain) if data.decode('ASCII') != '12345': print(data) return 'fail' fmain = gdal.VSIFOpenL("/vsizip/vsimem/test2.zip/bar.baz", "rb") if fmain is None: gdaltest.post_reason('fail 4') return 'fail' data = gdal.VSIFReadL(1, 5, fmain) gdal.VSIFCloseL(fmain) if data.decode('ASCII') != '67890': print(data) return 'fail' gdal.Unlink("/vsimem/test2.zip") return 'success'