Simple python script converting polygon package to domjudge(kattis) package
Project description
Polygon2DOMjudge
What is this
It is a simple python script converting polygon package to DOMjudge (kattis) package.
Install
From PyPI (stable release, has been used in some contests)
pipx install p2d
From source (latest version, under development with new features)
pipx install git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge
CLI Example
First, you should build full package from Polygon and download the Linux package to your local.
[!WARNING] If you download the standard package and then run
doall.sh
to build the full package by yourself, the linebreaks will be CRLF. Make sure you convert the linebreaks to LF before running the script because DOMjudge is running on Linux.
# Download the full package from Polygon to /path/to/polygon-package.zip
$ p2d --code A --color "#FF0000" -o /path/to/domjudge-package.zip /path/to/polygon-package.zip
Run this command to make a package from /path/to/polygon-package.zip
to /path/to/domjudge-package.zip
and set code
and color
.
You can omit the output path, and the default output path will be in the current working directory and named as {{ code }}.zip
.
All available parameters are:
--code
: problem short name in DOMjudge contest.--color
: problem color in DOMjudge.--default
: force use the default output validator.--validator-flags
: add some flags to the output validator, only works when--default
is set.--auto
: use the default output validator if the checker is defined in config and can be replaced by the default one.--memory-limit
: override the memory limit for DOMjudge package (in MB), default is using the memory limit defined in polygon package.--output-limit
: override the output limit for DOMjudge package (in MB), default is using the default output limit in DOMjudge setting.--hide-sample
: hide the sample input and output from the problem statement, no sample data will be available for the contestants (force True if this is an interactive problem). When this is not set to True and the sample output is different from the main and correct solution (usually both are correct answers), the sample output will be replaced with the one shipped with problem statement. But the sample input will not be replaced because DOMjudge does not support different sample input from the one downloaded.--external-id
: specify the external id of the problem in DOMjudge, default is using the problem short-name in polygon.--with-statement
: include the pdf statement in the DOMjudge package.--with-attachments
: include attachments (e.g. local testing tools for interactive problem) in the DOMjudge package.--testset
: specify the testset to convert, must specify the testset name if the problem has multiple testsets.
Convert the whole contest
You can use p2d-contest
to get a script to convert all problems in a contest.
# Download the contest.xml from Polygon first
$ p2d-contest /path/to/contest.xml > convert.sh
Config
In config.toml, you can change some special checker's validator's flags, which will be used to replace the checker with the default output validator when --auto
is set.
[!NOTE] You should not edit this file directly, instead, you should create a new file named
config.toml
or something else and pass it to the script with--config
parameter. The script will merge the default config with your config.
Environment Variable
Don't change them unless you know what you are doing.
CONFIG_PATH
TESTLIB_PATH
API Example
[!WARNING] The API is not stable and may change in the future.
This is an example to convert all problems in a contest defined in problems.yaml
to DOMjudge package.
import yaml
from pathlib import Path
from p2d import convert
polygon = Path('/path/to/polygon-packages')
domjudge = Path('/path/to/domjudge-packages')
with open(domjudge / 'problems.yaml') as f:
problems = yaml.safe_load(f)
for problem in problems:
prob_id = problem['id']
convert(
polygon / f'{prob_id}.zip',
domjudge / f'{prob_id}.zip',
short_name=problem['label'],
color=problem['rgb'],
)
Known Issues
- For interactive problems, you must validate the output in the interactors, because DOMjudge cannot handle
tout
stream like Polygon. - For multi-pass problems, you may need to call
tout.open(make_new_file_in_a_dir(argv[3], "nextpass.in"))
to get the next pass input file when there exists a next pass.
Development
# install
poetry install
# build
poetry build
# run unittest
poetry run pytest
# release
./release.sh ${your version}
Polygon2DOMjudge
这是什么
这是一个简单的将 polygon 题目包转换成 DOMjudge (kattis) 题目包的 python 脚本。
安装
从 PyPI(稳定版本, 已经在一些比赛中使用过)
pipx install p2d
从源码(最新版本,正在开发中,有新的特性)
pipx install git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge
命令行使用示例
首先,你需要从 Polygon 构建 完整的 题目包并将 Linux 题目包下载到本地。
[!WARNING] 如果你下载了标准的题目包并且运行
doall.sh
来构建完整的题目包,那么换行符将会是 CRLF。 在运行脚本之前,请确保将换行符转换为 LF,因为 DOMjudge 是在 Linux 上运行的。
# 首先从 Polygon 下载完整的 Linux 题目包到本地
$ ./bin/p2d --code A --color "#FF0000" -o /path/to/domjudge-package.zip /path/to/polygon-package.zip
运行此命令可以从 /path/to/polygon-package.zip
处题目包转换为 /path/to/domjudge-package.zip
,并设置 code
和 color
属性。
你可以省略输出路径,输出路径将会在当前工作目录中,并命名为 {{ code }}.zip
。
所有可用的命令行参数如下:
--code
: 题目在 DOMjudge 比赛中的 short name。--color
: 题目在 DOMjudge 中的颜色。--default
: 强制使用 DOMjudge 默认的输出校验器。--validator-flags
: 为输出校验器添加一些命令行参数,仅在--default
被设置时生效。--auto
: 自动使用 DOMjudge 默认的输出校验器,即如果 checker 在配置文件中被定义,则使用默认的输出校验器与合适的命令行参数替代。--memory-limit
: 覆盖 DOMjudge 题目包的内存限制,如果不设置,则使用 Polygon 题目包中的内存限制。--output-limit
: 覆盖 DOMjudge 题目包的输出限制,如果不设置,则使用 DOMjudge 设置中默认的输出限制。--hide-sample
: 隐藏题面中的样例输入输出,不会为选手提供样例数据(如果是交互题,则此参数强制为 True)。 当此参数不设置为 True 且样例输出与标程的输出不同时 (通常两者都是符合要求的答案), 样例输出将会被替换为题面中提供的样例输出。但是样例输入不会被替换,因为 DOMjudge 不支持下载的样例输入与实际使用的不同。--external-id
: 指定题目在 DOMjudge 中的 external id,如果不设置,则使用 Polygon 中的题目 short-name。--with-statement
: 在 DOMjudge 题目包中包含 pdf 题面。--with-attachments
: 在 DOMjudge 题目包中包含附件(例如交互题的本地测试工具)。--testset
: 指定要转换的测试点集,如果题目有多个测试点集,则必须指定测试点集的名称。
转换整个比赛
你可以使用 p2d-contest
来获取一个脚本来转换整个比赛中的题目。
# 首先从 Polygon 下载 contest.xml
$ ./bin/p2d-contest /path/to/contest.xml > convert.sh
配置
在 config.toml 文件中,你可以设置一些特殊的 checker 的输出校验器参数,这会在 --auto
参数被设置时用来将 checker 替换为默认的输出校验器。
[!NOTE] 你不应该直接编辑这个文件,而是应该创建一个新的文件,命名为
config.toml
或其他名称,并使用--config
参数将其传递给脚本。脚本将会合并默认配置和你的配置。
环境变量
某些时候可能会有用。但如果你不知道你在干啥,请不要随便修改。
CONFIG_PATH
TESTLIB_PATH
API 使用示例
[!WARNING] API 不是稳定的,可能会在未来的版本中发生变化。
这是一个将 problems.yaml
中定义的比赛中的所有题目转换为 DOMjudge 题目包的示例。
import yaml
from pathlib import Path
from p2d import convert
polygon = Path('/path/to/polygon-packages')
domjudge = Path('/path/to/domjudge-packages')
with open(domjudge / 'problems.yaml') as f:
problems = yaml.safe_load(f)
for problem in problems:
prob_id = problem['id']
convert(
polygon / f'{prob_id}.zip',
domjudge / f'{prob_id}.zip',
short_name=problem['label'],
color=problem['rgb'],
)
开发
# install
poetry install
# build
poetry build
# run unittest
poetry run pytest
# release
./release.sh ${your version}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file p2d-0.3.0.tar.gz
.
File metadata
- Download URL: p2d-0.3.0.tar.gz
- Upload date:
- Size: 60.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d73864e678d175b7976e50f87afc5f9e84570835d50205490ed557bb0b21976c |
|
MD5 | 6565e1093fe66cb9d540e490e151209e |
|
BLAKE2b-256 | 90dba5dee074fc7a0f95569fe8e9d6340b041abbdeb82017fda7c92a250fe371 |
File details
Details for the file p2d-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: p2d-0.3.0-py3-none-any.whl
- Upload date:
- Size: 61.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba1d0753577645c6468817a91aaba58999713b9ab878d4a9a8938aec907524a4 |
|
MD5 | 4016c706d579a9c5d0600e244b047d0b |
|
BLAKE2b-256 | b570f0454ba7e3db026b6519407122c88ad2f80d33ea22e4c396a3e51597b8b8 |