v3: gstack-code-gen 生成
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .bundle import TestDataBundle
|
||||
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass
|
||||
class TestDataBundle:
|
||||
base_path: Path
|
||||
format: str = "json"
|
||||
|
||||
def cobol_input(self) -> Path:
|
||||
return self.base_path / "cobol" / "input.bin"
|
||||
|
||||
def spark_input_dir(self) -> Path:
|
||||
return self.base_path / "spark" / "input"
|
||||
|
||||
def native_input(self) -> Path:
|
||||
return self.base_path / "native" / "input.json"
|
||||
|
||||
def ensure_dirs(self):
|
||||
for d in [self.base_path / "cobol",
|
||||
self.base_path / "spark" / "input",
|
||||
self.base_path / "native"]:
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
from tempfile import TemporaryDirectory
|
||||
_tmp = TemporaryDirectory()
|
||||
_b = TestDataBundle(base_path=Path(_tmp.name))
|
||||
assert _b.cobol_input().name == "input.bin"
|
||||
_b.ensure_dirs()
|
||||
assert _b.cobol_input().parent.exists()
|
||||
_tmp.cleanup()
|
||||
@@ -0,0 +1,30 @@
|
||||
import json, hashlib
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class DiskCache:
|
||||
def __init__(self, d=".cache"):
|
||||
self.d = Path(d)
|
||||
self.d.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def _p(self, k):
|
||||
return self.d / f"{hashlib.sha256(k.encode()).hexdigest()}.json"
|
||||
|
||||
def get(self, k):
|
||||
p = self._p(k)
|
||||
return json.loads(p.read_text()) if p.exists() else None
|
||||
|
||||
def set(self, k, v):
|
||||
self._p(k).write_text(json.dumps(v))
|
||||
|
||||
|
||||
class ReportStore:
|
||||
def __init__(self, base="./reports"):
|
||||
self.b = Path(base)
|
||||
|
||||
def save_history(self, prog, status, matched, dur):
|
||||
t = self.b / "trends" / f"{prog}.jsonl"
|
||||
t.parent.mkdir(parents=True, exist_ok=True)
|
||||
import datetime
|
||||
t.write_text(json.dumps({"ts": datetime.datetime.now().isoformat(), "status": status,
|
||||
"fields_matched": matched, "duration_s": dur}) + "\n")
|
||||
Reference in New Issue
Block a user