Skip to content

Instantly share code, notes, and snippets.

@thewtex
Created March 6, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewtex/1e89d91263280af856f1916d876e690f to your computer and use it in GitHub Desktop.
Save thewtex/1e89d91263280af856f1916d876e690f to your computer and use it in GitHub Desktop.
Prepare a Zarr Directory Store for deployment on a Netlify Site
#!/usr/bin/env python3
"""Netlify does not serve hidden files, i.e files starting with a '.'. Copy Zarr
hidden files and generate a '_redirects' file for Zarr DirectoryStore
deployment.
References:
- https://docs.netlify.com/routing/redirects/#syntax-for-the-redirects-file
- https://community.netlify.com/t/hidden-files-removed-in-zip-deploy/8997
"""
import os
import argparse
import pathlib
import shutil
zarr_files = {
'.zmetadata',
'.zgroup',
'.zattrs',
'.zarray',
}
def main(store):
with open(os.path.join(store, '_redirects'), 'w') as fp:
for (dirpath, dirs, files) in os.walk(store):
found = zarr_files.intersection(files)
for filename in found:
path = pathlib.Path(dirpath, filename)
from_path = path.relative_to(store)
path_visible = pathlib.Path(dirpath, filename[1:])
to_path = path_visible.relative_to(store)
fp.write('/{0} /{1}\n'.format(from_path, to_path))
shutil.copyfile(path, path_visible)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('store', help='Path to the Zarr DirectoryStore')
args = parser.parse_args()
main(args.store)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment