Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an internal method LibraryCheckerProblem.download_checker_cpp() #624

Merged
merged 2 commits into from
Nov 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions onlinejudge/service/library_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import pathlib
import re
import subprocess
import sys
Expand Down Expand Up @@ -57,10 +58,10 @@ def download_system_cases(self, *, session: Optional[requests.Session] = None) -
files += [(file.name, file.read_bytes()) for file in path.glob('out/*.out')]
return onlinejudge._implementation.testcase_zipper.extract_from_files(iter(files))

def _get_cloned_repository_path(self):
def _get_cloned_repository_path(self) -> pathlib.Path:
return utils.cache_dir / 'library-checker-problems'

def _generate_test_cases_in_cloned_repository(self):
def _generate_test_cases_in_cloned_repository(self) -> None:
path = self._get_cloned_repository_path()

try:
Expand Down Expand Up @@ -93,7 +94,7 @@ def _generate_test_cases_in_cloned_repository(self):
log.error("the generate.py failed: check https://github.com/yosupo06/library-checker-problems/issues")
raise

def _get_problem_directory_path(self):
def _get_problem_directory_path(self) -> pathlib.Path:
path = self._get_cloned_repository_path()
problems = toml.load(path / 'problems.toml')
return path / problems['problems'][self.problem_id]['dir']
Expand All @@ -115,6 +116,12 @@ def from_url(cls, url: str) -> Optional['LibraryCheckerProblem']:
return cls(problem_id=m.group(1))
return None

def download_checker_cpp(self) -> bytes:
self._generate_test_cases_in_cloned_repository()
path = self._get_problem_directory_path()
with open(str(path / "checker.cpp"), "rb") as fh:
return fh.read()


onlinejudge.dispatch.services += [LibraryCheckerService]
onlinejudge.dispatch.problems += [LibraryCheckerProblem]