Debug dongle test code
This commit is contained in:
62
scripts/download_xterm.py
Normal file
62
scripts/download_xterm.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Pre-build script for PlatformIO
|
||||
Downloads xterm.js files for local hosting (optional)
|
||||
|
||||
To use local files instead of CDN, run:
|
||||
python scripts/download_xterm.py --local
|
||||
|
||||
Then update data/index.html to use local paths instead of CDN URLs.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
# This script runs before build but doesn't do anything by default
|
||||
# The HTML uses CDN links which work fine when you have internet
|
||||
|
||||
def main():
|
||||
# Check if --local flag was passed
|
||||
if '--local' in sys.argv:
|
||||
try:
|
||||
import urllib.request
|
||||
|
||||
data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data')
|
||||
js_dir = os.path.join(data_dir, 'js')
|
||||
css_dir = os.path.join(data_dir, 'css')
|
||||
|
||||
os.makedirs(js_dir, exist_ok=True)
|
||||
os.makedirs(css_dir, exist_ok=True)
|
||||
|
||||
files = [
|
||||
('https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.min.js',
|
||||
os.path.join(js_dir, 'xterm.min.js')),
|
||||
('https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.min.css',
|
||||
os.path.join(css_dir, 'xterm.min.css')),
|
||||
('https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.min.js',
|
||||
os.path.join(js_dir, 'xterm-addon-fit.min.js')),
|
||||
('https://cdn.jsdelivr.net/npm/xterm-addon-web-links@0.9.0/lib/xterm-addon-web-links.min.js',
|
||||
os.path.join(js_dir, 'xterm-addon-web-links.min.js')),
|
||||
]
|
||||
|
||||
for url, path in files:
|
||||
if not os.path.exists(path):
|
||||
print(f'Downloading {url}...')
|
||||
urllib.request.urlretrieve(url, path)
|
||||
print(f' -> {path}')
|
||||
|
||||
print('\nLocal files downloaded!')
|
||||
print('Update index.html to use local paths:')
|
||||
print(' <link rel="stylesheet" href="/css/xterm.min.css">')
|
||||
print(' <script src="/js/xterm.min.js"></script>')
|
||||
print(' etc.')
|
||||
|
||||
except Exception as e:
|
||||
print(f'Warning: Could not download xterm.js files: {e}')
|
||||
print('The HTML will use CDN links instead.')
|
||||
|
||||
# Normal build - do nothing
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user