feat(license): 接入授权平台客户端门禁(license-v2/lease-v2)并烧入交付版信任根
This commit is contained in:
60
release/testdata/gen_testdata.py
vendored
60
release/testdata/gen_testdata.py
vendored
@@ -886,7 +886,7 @@ def build_project_data(rng, cfg, words, m_idx, bid_local=True):
|
||||
|
||||
# ---------------- 项目主循环 ----------------
|
||||
|
||||
def gen_projects(hc, sc, dd, cfg, rng, words, log):
|
||||
def gen_projects(hc, sc, dd, cfg, rng, words, log, start=0):
|
||||
y_a, y_b = _ym_range(cfg)
|
||||
pver = _parser_vers(dd)[0] # 工程线版本
|
||||
n = int(cfg["n_project"])
|
||||
@@ -898,7 +898,7 @@ def gen_projects(hc, sc, dd, cfg, rng, words, log):
|
||||
log(" 软暂停:第 %d/%d 个项目处停止(已生成的保留)。" % (i + 1, n))
|
||||
break
|
||||
stem = rng.choice(words.stems).strip()[:22]
|
||||
name = "测试项目%03d-%s" % (i + 1, stem)
|
||||
name = "测试项目%03d-%s" % (start + i + 1, stem)
|
||||
sha_src = hashlib.sha256(("testdata-src|%s" % name).encode("utf-8")).hexdigest()
|
||||
src_name = "%s_%s.cos4" % (sha_src, name)
|
||||
_, _, m_idx = _rand_ym(rng, y_a, y_b)
|
||||
@@ -1401,6 +1401,48 @@ def delete_testdata(dd, keep_files=False, log=print):
|
||||
|
||||
# ---------------- 编排入口 ----------------
|
||||
|
||||
def _has_col(con, table, col):
|
||||
try:
|
||||
return any(r[1] == col for r in con.execute('PRAGMA table_info("%s")' % table))
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def _clean_orphans(con, parent="batches", pcol="batch_id"):
|
||||
"""删除孤儿子表行(父批次/会话已不存在),避免新批次复用 id 时撞唯一约束。
|
||||
只删 batch_id/session_id 不在父表里的行,从不碰任何有效数据。"""
|
||||
try:
|
||||
tabs = [r[0] for r in con.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table'").fetchall()]
|
||||
# 保险:父表为空时绝不反删子表(否则 NOT IN(空) 会全删)
|
||||
pcount = con.execute('SELECT COUNT(*) FROM "%s"' % parent).fetchone()[0]
|
||||
if pcount == 0:
|
||||
con.commit()
|
||||
return
|
||||
for t in tabs:
|
||||
if t == parent or not _has_col(con, t, pcol):
|
||||
continue
|
||||
con.execute('DELETE FROM "%s" WHERE "%s" NOT IN (SELECT id FROM "%s")'
|
||||
% (t, pcol, parent))
|
||||
if parent == "batches":
|
||||
if _has_col(con, "norms", "bill_id"):
|
||||
con.execute("DELETE FROM norms WHERE bill_id NOT IN (SELECT id FROM bills)")
|
||||
if _has_col(con, "norm_res", "norm_id"):
|
||||
con.execute("DELETE FROM norm_res WHERE norm_id NOT IN (SELECT id FROM norms)")
|
||||
else:
|
||||
if _has_col(con, "s_norms", "bill_id"):
|
||||
con.execute("DELETE FROM s_norms WHERE bill_id NOT IN (SELECT id FROM s_bills)")
|
||||
if _has_col(con, "s_norm_res", "norm_id"):
|
||||
con.execute("DELETE FROM s_norm_res WHERE norm_id NOT IN (SELECT id FROM s_norms)")
|
||||
con.commit()
|
||||
except Exception:
|
||||
try:
|
||||
con.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
raise
|
||||
|
||||
|
||||
def run(cfg, log=print):
|
||||
global REF_DIR
|
||||
REF_DIR = (cfg.get("ref_dir") or "").strip() or None
|
||||
@@ -1410,7 +1452,10 @@ def run(cfg, log=print):
|
||||
return False
|
||||
th, ts = ensure_test_dbs(dd, log)
|
||||
hc = _open_db(th)
|
||||
_clean_orphans(hc, "batches", "batch_id")
|
||||
sc = _open_db(ts) if os.path.exists(ts) else None
|
||||
if sc is not None:
|
||||
_clean_orphans(sc, "sessions", "session_id")
|
||||
rng = random.Random() # 每次运行真随机(不固定种子)
|
||||
words = Words(hc)
|
||||
log("参考库目录:%s" % _disp(os.path.dirname(db_paths(dd)[0])))
|
||||
@@ -1423,7 +1468,16 @@ def run(cfg, log=print):
|
||||
log("== 后台项目(%d 份,清单 %d~%d/项目,定额 %d~%d/清单,工料机 %d~%d/定额)==" % (
|
||||
cfg["n_project"], cfg["bill_lo"], cfg["bill_hi"],
|
||||
cfg["norm_lo"], cfg["norm_hi"], cfg["res_lo"], cfg["res_hi"]))
|
||||
st.update(gen_projects(hc, sc, dd, cfg, rng, words, log))
|
||||
chunk = int(cfg.get("chunk", 0) or 0)
|
||||
if chunk > 0 and chunk < int(cfg["n_project"]):
|
||||
total = int(cfg["n_project"]); off = 0
|
||||
while off < total:
|
||||
piece = dict(cfg); piece["n_project"] = min(chunk, total - off)
|
||||
log(" —— 分批推进:第 %d~%d / %d 份 ——" % (off + 1, off + piece["n_project"], total))
|
||||
st.update(gen_projects(hc, sc, dd, piece, rng, words, log, start=off))
|
||||
off += piece["n_project"]
|
||||
else:
|
||||
st.update(gen_projects(hc, sc, dd, cfg, rng, words, log))
|
||||
if int(cfg.get("n_market", 0)) or int(cfg.get("n_info", 0)):
|
||||
log("== 市场价/信息价 ==")
|
||||
st.update(gen_prices(hc, dd, cfg, rng, words, log))
|
||||
|
||||
Reference in New Issue
Block a user