[[fetch]]
files = ["checker.py"]
from js import document, console
from checker import validate
from pyscript import when
def save_temp(filename, content):
with open(f"/tmp/{filename}", "w") as f:
f.write(content)
return f"/tmp/{filename}"
@when('change', '#master')
@when('change', '#test')
async def processFile(*args):
res_div = document.getElementById('results')
master_input = document.getElementById('master')
test_input = document.getElementById('test')
if master_input.files.length == 0 or test_input.files.length == 0:
res_div.innerText = ""
return
res_div.innerText = "Validating..."
try:
master_file = master_input.files.item(0)
test_file = test_input.files.item(0)
m_cont = await master_file.text()
t_cont = await test_file.text()
m_path = save_temp("m.nc", m_cont)
t_path = save_temp("t.nc", t_cont)
result = validate(m_path, t_path)
if result.get("valid"):
res_div.innerText = "Validation Passed"
else:
issue = result.get("issue", "Unknown error")
res_div.innerText = f"Validation Failed: {issue}"
except Exception as e:
import traceback
console.error(traceback.format_exc())
res_div.innerText = f"Error in checker script: {str(e)}"