Unverified Commit 4764db2b authored by Julien Palard's avatar Julien Palard
Browse files

Allow to update the env from the pre-check script.

parent 981672b3
...@@ -4,6 +4,7 @@ celery -A hkis worker ...@@ -4,6 +4,7 @@ celery -A hkis worker
import asyncio import asyncio
from functools import partial from functools import partial
import json
from random import choice from random import choice
from typing import Optional from typing import Optional
import os import os
...@@ -145,7 +146,7 @@ def congrats(language): ...@@ -145,7 +146,7 @@ def congrats(language):
) )
def run_pre_check(tmpdir, pre_check: str, env=None): def run_pre_check(tmpdir, pre_check: str, env=None) -> dict:
"""Run a pre-check script outside the sandbox before the actual check.""" """Run a pre-check script outside the sandbox before the actual check."""
with open(os.path.join(tmpdir, "pre_check.py"), "w") as pre_check_file: with open(os.path.join(tmpdir, "pre_check.py"), "w") as pre_check_file:
pre_check_file.write(pre_check) pre_check_file.write(pre_check)
...@@ -165,6 +166,10 @@ def run_pre_check(tmpdir, pre_check: str, env=None): ...@@ -165,6 +166,10 @@ def run_pre_check(tmpdir, pre_check: str, env=None):
pre_check_result.stdout, pre_check_result.stdout,
pre_check_result.stderr, pre_check_result.stderr,
) )
try:
return json.loads(pre_check_result.stdout)
except json.JSONDecodeError:
return {}
@shared_task @shared_task
...@@ -181,7 +186,9 @@ def check_answer_task(answer: dict): ...@@ -181,7 +186,9 @@ def check_answer_task(answer: dict):
if "language" in answer: if "language" in answer:
firejail_env["LANGUAGE"] = answer["language"] firejail_env["LANGUAGE"] = answer["language"]
if "pre_check" in answer and answer["pre_check"]: if "pre_check" in answer and answer["pre_check"]:
run_pre_check(tmpdir, answer["pre_check"], env=firejail_env) firejail_env.update(
run_pre_check(tmpdir, answer["pre_check"], env=firejail_env)
)
prof_proc = Popen( prof_proc = Popen(
["firejail"] ["firejail"]
+ FIREJAIL_OPTIONS + FIREJAIL_OPTIONS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment