def test_archive_zip(data_dir):
    # .zip
    archive = open_archive(str(data_dir.join('geodata/roads-folders.zip')))
    assert isinstance(archive, ZipArchive)

    assert sorted(list(x.name for x in archive)) == sorted(itertools.chain(*([
        'roads-{0:02d}/'.format(i),
        'roads-{0:02d}/roads-{0:02d}.shp'.format(i),
        'roads-{0:02d}/roads-{0:02d}.shx'.format(i),
        'roads-{0:02d}/roads-{0:02d}.dbf'.format(i),
        'roads-{0:02d}/roads-{0:02d}.prj'.format(i),
    ] for i in xrange(4))))

    assert archive.get('roads-00/roads-00.shp').open().read(4) \
        == b'\x00\x00\x27\x0a'
def test_archive_zip(data_dir):
    # .zip
    archive = open_archive(str(data_dir.join('geodata/roads-folders.zip')))
    assert isinstance(archive, ZipArchive)

    assert sorted(list(x.name for x in archive)) == sorted(
        itertools.chain(*([
            'roads-{0:02d}/'.format(i),
            'roads-{0:02d}/roads-{0:02d}.shp'.format(i),
            'roads-{0:02d}/roads-{0:02d}.shx'.format(i),
            'roads-{0:02d}/roads-{0:02d}.dbf'.format(i),
            'roads-{0:02d}/roads-{0:02d}.prj'.format(i),
        ] for i in xrange(4))))

    assert archive.get('roads-00/roads-00.shp').open().read(4) \
        == b'\x00\x00\x27\x0a'
def find_shapefiles(archive_filename):
    # ------------------------------------------------------------
    # Note: to find stuff recursively in an archive, we need
    #       to extract the sub-archives first. For that, we need
    #       a temporary directory and to make sure we delete it
    #       once we're done..
    # ------------------------------------------------------------

    found = defaultdict(dict)  # {basename: {ext: ArchivedFile()}}

    archive = open_archive(archive_filename)
    for member in archive:
        basename, ext = os.path.splitext(member.name)
        ext = ext[1:]  # Strip leading dot
        ext_low = ext.lower()

        if ext_low in SHP_EXT or ext_low in SHP_REL_EXT:
            found[basename][ext] = member

    return dict(found)
Пример #4
0
def find_shapefiles(archive_filename):
    # ------------------------------------------------------------
    # Note: to find stuff recursively in an archive, we need
    #       to extract the sub-archives first. For that, we need
    #       a temporary directory and to make sure we delete it
    #       once we're done..
    # ------------------------------------------------------------

    found = defaultdict(dict)  # {basename: {ext: ArchivedFile()}}

    archive = open_archive(archive_filename)
    for member in archive:
        basename, ext = os.path.splitext(member.name)
        ext = ext[1:]  # Strip leading dot
        ext_low = ext.lower()

        if ext_low in SHP_EXT or ext_low in SHP_REL_EXT:
            found[basename][ext] = member

    return dict(found)