Created
March 6, 2020 14:41
-
-
Save thewtex/1e89d91263280af856f1916d876e690f to your computer and use it in GitHub Desktop.
Prepare a Zarr Directory Store for deployment on a Netlify Site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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