Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from wangxinhe2006/dev
Browse files Browse the repository at this point in the history
Bump version number to v0.2
  • Loading branch information
wxh06 authored May 2, 2019
2 parents 3e4982f + 50c2e58 commit 0351132
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)](https://img.shields.io/github/license/wangxinhe2006/docker-judge.svg)

A Docker Based Online Judge Engine

Expand Down
21 changes: 16 additions & 5 deletions dockerjudge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -36,12 +40,19 @@ 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:
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:
Expand Down
23 changes: 23 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
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",
],
)

0 comments on commit 0351132

Please sign in to comment.