mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge.vj4: 修复.ini配置读取异常的问题
This commit is contained in:
1 parent
f3be3fc787
commit
ec2b95c91a
2 files changed
+31
-3
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.1.6",
|
"version": "2.1.7",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "masnn",
|
"author": "masnn",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
import { Dictionary } from 'lodash';
|
import { Dictionary } from 'lodash';
|
||||||
import { FormatError, SystemError } from './error';
|
import { FormatError, SystemError } from './error';
|
||||||
import { parseTimeMS, parseMemoryMB, ensureFile } from './utils';
|
import { parseTimeMS, parseMemoryMB, ensureFile } from './utils';
|
||||||
@@ -192,7 +193,7 @@ async function readAutoCases(folder, { next }) {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
export = async function readYamlCases(folder: string, cfg: Dictionary<any>, args) {
|
export async function readYamlCases(folder: string, cfg: Dictionary<any>, args) {
|
||||||
const config: any = {
|
const config: any = {
|
||||||
checker_type: 'default',
|
checker_type: 'default',
|
||||||
count: 0,
|
count: 0,
|
||||||
@@ -263,4 +264,31 @@ export = async function readYamlCases(folder: string, cfg: Dictionary<any>, args
|
|||||||
config.count = c.count;
|
config.count = c.count;
|
||||||
}
|
}
|
||||||
return Object.assign(cfg, config);
|
return Object.assign(cfg, config);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
function convertIniConfig(ini: string) {
|
||||||
|
const f = ini.split('\n');
|
||||||
|
const count = parseInt(f[0], 10);
|
||||||
|
const res = { cases: [] };
|
||||||
|
for (let i = 1; i <= count; i++) {
|
||||||
|
const [input, output, time, score, memory] = f[i].split('|');
|
||||||
|
const cur = {
|
||||||
|
input: `input/${input}`, output: `output/${output}`, score: parseInt(score, 10), time: `${time}s`, memory: '128m',
|
||||||
|
};
|
||||||
|
if (!Number.isNaN(parseInt(memory, 10))) cur.memory = `${Math.floor(parseInt(memory, 10) / 1024)}m`;
|
||||||
|
res.cases.push(cur);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function readCases(folder: string, cfg: Record<string, any>, args) {
|
||||||
|
const iniConfig = path.resolve(folder, 'config.ini');
|
||||||
|
const yamlConfig = path.resolve(folder, 'config.yaml');
|
||||||
|
let config;
|
||||||
|
if (fs.existsSync(yamlConfig)) {
|
||||||
|
config = { ...yaml.safeLoad(fs.readFileSync(yamlConfig).toString()) as object, ...cfg };
|
||||||
|
} else if (fs.existsSync(iniConfig)) {
|
||||||
|
config = { ...convertIniConfig(fs.readFileSync(iniConfig).toString()), ...cfg };
|
||||||
|
}
|
||||||
|
return await readYamlCases(folder, config, args);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user