def get_directory(*, problem: onlinejudge.type.Problem, contest: Optional[onlinejudge.type.Contest], config: Dict[str, Any]) -> pathlib.Path: # prepare params service = problem.get_service() for name in ('contest_id', 'contest_slug'): contest_id = getattr(problem, name, None) if contest_id: break else: contest_id = '' for name in ('problem_id', 'problem_slug', 'problem_no', 'task_id', 'task_slug', 'task_no', 'alphabet', 'index'): problem_id = getattr(problem, name, None) if problem_id: break else: problem_id, = urllib.parse.urlparse( problem.get_url()).path.lstrip('/').replace('/', '-'), params = { 'service_name': service.get_name(), 'service_domain': urllib.parse.urlparse(service.get_url()).netloc, 'contest_id': contest_id, 'problem_id': problem_id, } # generate the path problem_pattern = config.get('problem_directory', '.') if 'problem_directory' not in config: logger.info( 'setting "problem_directory" is not found in your config; use %s', repr(problem_pattern)) problem_directory = pathlib.Path( problem_pattern.format(**params)).expanduser() if contest is None: return problem_directory contest_pattern = config.get('contest_directory', '{problem_id}') if 'contest_directory' not in config: logger.info( 'setting "contest_directory" is not found in your config; use %s', repr(contest_pattern)) contest_directory = pathlib.Path( contest_pattern.format(**params)).expanduser() return contest_directory / problem_directory
def get_directory(*, problem: onlinejudge.type.Problem, contest: Optional[onlinejudge.type.Contest]) -> pathlib.Path: # prepare params service = problem.get_service() for name in ('contest_id', 'contest_slug'): contest_id = getattr(problem, name, None) if contest_id: break else: contest_id = '' for name in ('problem_id', 'problem_slug', 'problem_no', 'task_id', 'task_slug', 'task_no', 'alphabet', 'index'): problem_id = getattr(problem, name, None) if problem_id: break else: problem_id, = urllib.parse.urlparse( problem.get_url()).path.lstrip('/').replace('/', '-'), params = { 'service_name': service.get_name(), 'service_domain': urllib.parse.urlparse(service.get_url()).netloc, 'contest_id': contest_id, 'problem_id': problem_id, } # generate the path problem_pattern = "{problem_id}" #config.get('problem_directory', '.') problem_directory = pathlib.Path( problem_pattern.format(**params)).expanduser() if contest is None: return problem_directory contest_pattern = "./Contests/{service_name}_{contest_id}" contest_directory = pathlib.Path( contest_pattern.format(**params)).expanduser() return contest_directory / problem_directory