From 2d7d1bd9f76176ae81970f64e0ccb9540b9a62d1 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sat, 12 Sep 2015 21:56:32 +0800 Subject: [PATCH 01/17] delete debug script --- Accessories/__init__.py | 1 - Accessories/reJudge.py | 74 ----------------------------------------- Accessories/utils.py | 61 --------------------------------- 3 files changed, 136 deletions(-) delete mode 100644 Accessories/__init__.py delete mode 100644 Accessories/reJudge.py delete mode 100755 Accessories/utils.py diff --git a/Accessories/__init__.py b/Accessories/__init__.py deleted file mode 100644 index 3ed9fd0..0000000 --- a/Accessories/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'root' diff --git a/Accessories/reJudge.py b/Accessories/reJudge.py deleted file mode 100644 index dc1ad2e..0000000 --- a/Accessories/reJudge.py +++ /dev/null @@ -1,74 +0,0 @@ -import django -from contest.models import * -from problem.models import * -from submission.models import Submission - -import redis - -from judge.judger_controller.tasks import judge -from judge.judger_controller.settings import redis_config - -django.setup() - - -def rejudge(submission): - # for submission in submission: - # submission_id = submission.id - # try: - # command = "%s run -t -i --privileged --rm=true " \ - # "-v %s:/var/judger/test_case/ " \ - # "-v %s:/var/judger/code/ " \ - # "%s " \ - # "python judge/judger/run.py " \ - # "--solution_id %s --time_limit %s --memory_limit %s --test_case_id %s" % \ - # (docker_config["docker_path"], - # test_case_dir, - # source_code_dir, - # docker_config["image_name"], - # submission_id, str(time_limit), str(memory_limit), test_case_id) - # subprocess.call(command, shell=docker_config["shell"]) - # except Exception as e: - # print e - return - - -def easy_rejudge(submissions, map_table, user_id, contest_id=None): - try: - user = User.objects.get(pk=user_id) - except User.DoesNotExist: - print "User.DoesNotExist!" - return - problemDict = {} - for oldSubmission in submission: - problem_id = map_table[oldSubmission.problem_id] - - if problem_id in problemDict: - problem = problemDict[problem_id] - else: - try: - p = Problem.objects.get(pk=problem_id) - except Problem.DoesNotExist: - print " Problem.DoesNotExist!" + str(problem_id) - continue - problem = p - problemDict[problem_id] = p - - submission = Submission.objects.create( - user_id=user_id, - language=oldSubmission.language, - code=oldSubmission.code, - contest_id=contest_id, - problem_id=problem_id, - originResult=oldSubmission.result - ) - try: - judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id) - except Exception: - print "error!" - continue - - r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"]) - r.incr("judge_queue_length") - - return - diff --git a/Accessories/utils.py b/Accessories/utils.py deleted file mode 100755 index 17ab096..0000000 --- a/Accessories/utils.py +++ /dev/null @@ -1,61 +0,0 @@ -import django -from contest.models import * -from problem.models import * -django.setup() -def add_exist_problem_to_contest(problems, contest_id): - try: - contest = Contest.objects.get(pk=contest_id) - except Contest.DoesNotExist: - print "Contest Doesn't Exist!" - return - i = 1 - for problem in problems: - print "Add the problem:" - print problem.title - print "The sort Index is" + str(i) + " You Can modify it latter as you like~" - ContestProblem.objects.create(contest=contest, sort_index=str(i), - title=problem.title, description=problem.description, - input_description=problem.input_description, - output_description=problem.output_description, - samples=problem.samples, - test_case_id=problem.test_case_id, - hint=problem.hint, - created_by=problem.created_by, - time_limit=problem.time_limit, - memory_limit=problem.memory_limit) - i += 1 - return -def add_contest_problem_to_problem(contest_id): - try: - contest = Contest.objects.get(pk=contest_id) - except Contest.DoesNotExist: - print "Contest Doesn't Exist!" - return - #Get all problems in this contest - problems = ContestProblem.objects.filter(contest=contest) - - #get a tag - try: - tag = ProblemTag.objects.get(name=contest.title) - except ProblemTag.DoesNotExist: - tag = ProblemTag.objects.create(name=contest.title) - - #for each problem - for problem in problems: - print "Add problem to problem list:" - print problem.title - p = Problem.objects.create(title=problem.title, - description=problem.description, - input_description=problem.input_description, - output_description=problem.output_description, - samples=problem.samples, - test_case_id=problem.test_case_id, - hint=problem.hint, - created_by=problem.created_by, - time_limit=problem.time_limit, - memory_limit=problem.memory_limit, - visible = False, - difficulty = 0, - source = contest.title) - p.tags.add(tag) - return \ No newline at end of file From 34246f734592ee3867a10365a2f639f1576d8139 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 13 Sep 2015 10:58:48 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=93=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3=E7=9A=84=20Python=20=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/release/fis-conf.js | 13 ---------- tools/static_md5.py | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 13 deletions(-) delete mode 100644 static/release/fis-conf.js create mode 100644 tools/static_md5.py diff --git a/static/release/fis-conf.js b/static/release/fis-conf.js deleted file mode 100644 index f0935c3..0000000 --- a/static/release/fis-conf.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Created by virusdefender on 8/25/15. - */ - -fis.match('*.{js,css,png,gif}', { - useHash: true // 开启 md5 戳 -}); - -fis.config.set( -'roadmap.path', -[{reg:'*.html',isHtmlLike : true} -]) -; \ No newline at end of file diff --git a/tools/static_md5.py b/tools/static_md5.py new file mode 100644 index 0000000..db1b281 --- /dev/null +++ b/tools/static_md5.py @@ -0,0 +1,51 @@ +# coding=utf-8 +import hashlib +import re +import os +import shutil + +template_src_path = "template/src/" +template_release_path = "template/release/" + +static_src_path = "static/src/" +static_release_path = "static/release/" + +# 删除模板的 release 文件夹 +shutil.rmtree(template_release_path) +# 复制一份模板文件夹到 release +shutil.copytree(template_src_path, template_release_path) + +# 删除静态文件的 release 文件夹 +shutil.rmtree(static_release_path) +# 复制一份静态文件文件夹到 release +shutil.copytree(static_src_path, static_release_path) + +r = re.compile(r'') + +name_map = {} + + +def do(match): + js_path = match.group(1).lstrip("/static/") + + if not os.path.exists(static_release_path + js_path): + return match.group(0) + + if js_path in name_map: + md5 = name_map[js_path] + else: + # rename + md5 = hashlib.md5(open(static_release_path + js_path, "r").read()).hexdigest() + os.rename(static_release_path + js_path, static_release_path + js_path + "?v=" + md5) + return '' % (js_path + "?v=" + md5,) + + +for root, dirs, files in os.walk(template_release_path): + for name in files: + html_path = os.path.join(root, name) + html_content = open(html_path, "r").read() + replaced_html_content = re.sub(r, do, html_content) + + f = open(html_path, "w") + f.write(replaced_html_content) + f.close() From e6c9916a126b2361379123ae64c207f5edd93f9c Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 13 Sep 2015 11:47:12 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- oj/local_settings.py | 2 +- template/src/oj/index.html | 2 +- template/src/oj_base.html | 4 ---- tools/static_md5.py | 30 +++++++++++++++++++----------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 1fbe8ef..31d2215 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,5 @@ static/release/img static/src/upload_image/* build.txt tmp/ -test_case/ \ No newline at end of file +test_case/ +release/ \ No newline at end of file diff --git a/oj/local_settings.py b/oj/local_settings.py index 51e9095..e61ec9c 100644 --- a/oj/local_settings.py +++ b/oj/local_settings.py @@ -34,7 +34,7 @@ REDIS_CACHE = { DEBUG = True # 同理 这是 web 服务器的上传路径 -TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/') +TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/') ALLOWED_HOSTS = [] diff --git a/template/src/oj/index.html b/template/src/oj/index.html index c8c1d8f..41f5d23 100644 --- a/template/src/oj/index.html +++ b/template/src/oj/index.html @@ -5,7 +5,7 @@ 青岛大学在线评测平台 - 首页 - +