esp32emu / tools /deploy.py
HelloSun's picture
ESP32 emulator update
a281c6e verified
Raw History Blame Contribute Delete
1.97 kB
#!/usr/bin/env python3
"""Upload the static site to a Hugging Face Space. Usage: HF_TOKEN=... python3 tools/deploy.py [user/space]"""
import os, shutil, sys, tempfile
from huggingface_hub import HfApi
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
repo = sys.argv[1] if len(sys.argv) > 1 else 'HelloSun/esp32emu'
token = os.environ.get('HF_TOKEN')
if not token: sys.exit('ERROR: environment variable HF_TOKEN is not set (export HF_TOKEN=hf_...)')
stage = tempfile.mkdtemp()
def cp(src, dst=None):
d = os.path.join(stage, dst or os.path.basename(src)); os.makedirs(os.path.dirname(d), exist_ok=True)
if os.path.isdir(src): shutil.copytree(src, d, ignore=shutil.ignore_patterns('*.bin', '*.elf', '*.wasm', '__pycache__', 'rom', '*.ppm', '*.png'))
else: shutil.copy(src, d)
for f in ('index.html', 'style.css', 'app.js', 'assets.js'): cp(os.path.join(root, 'web', f))
cp(os.path.join(root, 'web', 'js'), 'js')
cp(os.path.join(root, 'README.md'))
cp(os.path.join(root, 'wasm', 'xtensa.c'), 'wasm/xtensa.c'); cp(os.path.join(root, 'wasm', 'build.sh'), 'wasm/build.sh')
cp(os.path.join(root, 'firmware', 'dosvga32'), 'firmware/dosvga32'); cp(os.path.join(root, 'firmware', 'README.md'), 'firmware/README.md')
cp(os.path.join(root, 'tools'), 'tools'); cp(os.path.join(root, 'scripts'), 'scripts'); cp(os.path.join(root, 'docs'), 'docs'); cp(os.path.join(root, 'package.json'))
ar = os.path.join(root, 'dist', 'esp32emu-source.tar.gz')
if os.path.exists(ar): cp(ar, 'downloads/esp32emu-source.tar.gz')
open(os.path.join(stage, '.gitattributes'), 'w').write('# keep everything as normal git files (no LFS) so the static site is served directly\n')
api = HfApi(token=token)
api.create_repo(repo, repo_type='space', space_sdk='static', exist_ok=True)
api.upload_folder(folder_path=stage, repo_id=repo, repo_type='space', commit_message='ESP32 emulator update', delete_patterns=['*'])
print('uploaded to https://huggingface.co/spaces/' + repo)