From ba78806faaa2a5a4397592a01c357e63cea8d0ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E5=BF=83=E7=A6=BE?= Date: Mon, 29 Apr 2019 03:19:51 +0800 Subject: [PATCH 1/4] Run additional settings `before_compile`, `after_compile` --- dockerjudge/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dockerjudge/__init__.py b/dockerjudge/__init__.py index 499c35b..44e8cd0 100644 --- a/dockerjudge/__init__.py +++ b/dockerjudge/__init__.py @@ -36,7 +36,11 @@ def judge(settings, source='', tests=(), timeout=1, client=docker.from_env()): network_disabled=True, tty=True) try: container.exec_run(['sh', '-c', 'echo ' + shlex.quote(source) + ' > ' + settings['source']]) + if 'before_compile' in settings: + container.exec_run(settings['before_compile']) compiler = container.exec_run(settings['compile'], demux=True) + if 'before_compile' in settings: + container.exec_run(settings['after_compile']) if not compiler.exit_code: threads = [] for stdin, stdout in tests: From 81263613101c194c84d9e7e75e83a04feedb0b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E5=BF=83=E7=A6=BE?= Date: Thu, 2 May 2019 18:20:20 +0800 Subject: [PATCH 2/4] Run additional settings `before_judge`, `after_judge` --- dockerjudge/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/dockerjudge/__init__.py b/dockerjudge/__init__.py index 44e8cd0..bbac9dd 100644 --- a/dockerjudge/__init__.py +++ b/dockerjudge/__init__.py @@ -18,15 +18,19 @@ def run(self): finally: del self._target, self._args, self._kwargs -def _judge(container, command, stdin='', stdout='', timeout=1): +def _judge(container, commands, stdio, timeout=1): 'Run each test case' - result = container.exec_run(['sh', '-c', 'echo ' + shlex.quote(stdin) + ' | timeout -k ' - + (str(timeout) + ' ') * 2 + command], demux=True) + if commands[0]: + container.exec_run(commands[0]) + result = container.exec_run(['sh', '-c', 'echo ' + shlex.quote(stdio[0]) + ' | timeout -k ' + + (str(timeout) + ' ') * 2 + commands[1]], demux=True) + if commands[2]: + container.exec_run(commands[2]) if result.exit_code == 124: return 'TLE' if result.exit_code: return 'RE' - if result.output[0].decode().rstrip() != stdout.rstrip(): + if result.output[0].decode().rstrip() != stdio[1].rstrip(): return 'WA' return 'AC' @@ -45,7 +49,10 @@ def judge(settings, source='', tests=(), timeout=1, client=docker.from_env()): threads = [] for stdin, stdout in tests: threads.append(Thread(target=_judge, - args=(container, settings['judge'], stdin, stdout, timeout))) + args=(container, (settings.get('before_judge'), + settings['judge'], + settings.get('after_judge')), + (stdin, stdout), timeout))) threads[-1].start() result = [] for thread in threads: From 6f55caa50cb36f6dd0313ab13c3fcc7f35d8e479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E5=BF=83=E7=A6=BE?= Date: Thu, 2 May 2019 18:29:41 +0800 Subject: [PATCH 3/4] Bump version number to v0.2 Run additional settings `before_compile`, `after_compile`, `before_judge` and `after_judge`. --- README.md | 1 + setup.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 setup.py diff --git a/README.md b/README.md index b978d70..4b52097 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # docker-judge [![Build Status](https://www.travis-ci.org/wangxinhe2006/docker-judge.svg)](https://www.travis-ci.org/wangxinhe2006/docker-judge) +[![License](https://img.shields.io/github/license/wangxinhe2006/docker-judge.svg)](![License](https://img.shields.io/github/license/wangxinhe2006/docker-judge.svg) A Docker Based Online Judge Engine diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e240789 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name="dockerjudge", + version="0.2", + author="汪心禾", + author_email="wangxinhe06@gmail.com", + description="A Docker Based Online Judge Engine", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/wangxinhe2006/docker-judge", + packages=setuptools.find_packages(), + classifiers=[ + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", + "Operating System :: OS Independent", + ], +) From 50c2e5883aa20e04fd9b200c2b3714b251cc9be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E5=BF=83=E7=A6=BE?= Date: Thu, 2 May 2019 18:31:13 +0800 Subject: [PATCH 4/4] Fix typing error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b52097..3b6b336 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # docker-judge [![Build Status](https://www.travis-ci.org/wangxinhe2006/docker-judge.svg)](https://www.travis-ci.org/wangxinhe2006/docker-judge) -[![License](https://img.shields.io/github/license/wangxinhe2006/docker-judge.svg)](![License](https://img.shields.io/github/license/wangxinhe2006/docker-judge.svg) +[![License](https://img.shields.io/github/license/wangxinhe2006/docker-judge.svg)](https://img.shields.io/github/license/wangxinhe2006/docker-judge.svg) A Docker Based Online Judge Engine