Extends the Test Datasheet Pipeline on AD2:C:\Shares\testdatadb to
generate web-published datasheets for the SCMVAS-Mxxx (obsolete) and
SCMHVAS-Mxxxx (replacement) High Voltage Input Module product lines.
Both are tested either with the existing TESTHV3 software (production
VASLOG .DAT logs) or in Engineering with plain .txt output.
Key changes on AD2 (all deployed 2026-04-12 with dated backups):
- parsers/spec-reader.js: getSpecs() returns a `{_family:'SCMVAS',
_noSpecs:true}` sentinel for SCMVAS/SCMHVAS/VAS-M/HVAS-M model prefixes
so the export pipeline does not silently skip them for missing specs.
- templates/datasheet-exact.js: new Accuracy-only template branch
(generateSCMVASDatasheet + helpers) that mirrors the existing shipped
format byte-for-byte. Extraction regex covers both QuickBASIC STR$()
output formats: scientific-with-trailing-status-digit (98.4% of
records) and plain-decimal (1.6% of records above QB's threshold).
- parsers/vaslog-engtxt.js (new): parses the Engineering-Tested .txt
files in TS-3R\LOGS\VASLOG\VASLOG - Engineering Tested\. Filename SN
regex strips optional trailing 14-digit timestamp; in-file "SN:"
header is the authoritative source when the filename is malformed.
- database/import.js: LOG_TYPES grows a VASLOG_ENG entry with
subfolder + recursive flags. Pre-existing 7 log types keep their
implicit recursive=true behaviour (config.recursive !== false).
importFiles() routes VASLOG_ENG paths before the generic loop so a
VASLOG - Engineering Tested/*.txt path does not mis-dispatch to the
multiline parser.
- database/export-datasheets.js: VASLOG_ENG records are written
verbatim via fs.copyFileSync(source_file, For_Web/<SN>.TXT) for true
byte-level pass-through, with a graceful raw_data fallback when the
source file is no longer on disk.
Deploy outcome:
- 27,503 SCMVAS/SCMHVAS datasheets rendered (27,065 from scientific +
438 from plain-decimal PASS lines, post-patch rerun)
- 434 Engineering-Tested .txt files pass-through-copied to For_Web
- 0 errors across both batches
Repo layout added here:
- scmvas-hvas-research/: discovery artifacts (source .BAS, hvin.dat,
sample .DAT + .txt, binary-format notes, IMPLEMENTATION_PLAN.md)
- implementation/: staged final code + deploy helpers + local test
harness + per-step verification scripts
- backups/pre-deploy-20260412/: independent local snapshot of the 4
AD2 files replaced, pulled byte-for-byte before deploy
All helper scripts fetch the AD2 password at runtime from the SOPS
vault (clients/dataforth/ad2.sops.yaml). None of the committed files
contain the plaintext credential. Known vault-entry hygiene issue
(stale shell-escape backslash before the `!`) is documented in the
fetcher comments and stripped at read-time; flagged separately for
cleanup.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
91 lines
3.8 KiB
Python
91 lines
3.8 KiB
Python
"""Targeted import of the 434 VASLOG Engineering-Tested .txt files.
|
|
|
|
Runs node import.js --file <batch> to import directly, then counts VASLOG_ENG
|
|
records in the DB. Avoids the slow full-import walk.
|
|
"""
|
|
import base64, os, subprocess, yaml, paramiko, sys
|
|
|
|
HOST = '192.168.0.6'
|
|
USER = 'sysadmin'
|
|
REMOTE_DIR = r'C:\Shares\test\TS-3R\LOGS\VASLOG\VASLOG - Engineering Tested'
|
|
|
|
def pwd():
|
|
r = subprocess.run(['sops', '-d', 'D:/vault/clients/dataforth/ad2.sops.yaml'],
|
|
capture_output=True, text=True, timeout=30, check=True)
|
|
return yaml.safe_load(r.stdout)['credentials']['password'].replace('\\', '')
|
|
|
|
def ps(c, cmd, to=600):
|
|
enc = base64.b64encode(cmd.encode('utf-16-le')).decode()
|
|
stdin, stdout, stderr = c.exec_command(f'powershell -NoProfile -EncodedCommand {enc}', timeout=to)
|
|
out = stdout.read().decode('utf-8', 'replace')
|
|
err = stderr.read().decode('utf-8', 'replace')
|
|
rc = stdout.channel.recv_exit_status()
|
|
return out, err, rc
|
|
|
|
def main():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=pwd(), timeout=30, banner_timeout=45,
|
|
look_for_keys=False, allow_agent=False)
|
|
sys.stdout.flush()
|
|
try:
|
|
print('[STEP 1] List Engineering-Tested .txt files on AD2', flush=True)
|
|
out, err, rc = ps(c, f'Get-ChildItem -LiteralPath "{REMOTE_DIR}" -File -Filter *.txt | ForEach-Object {{ $_.FullName }}')
|
|
files = [l.strip() for l in out.splitlines() if l.strip()]
|
|
print(f' found {len(files)} .txt files', flush=True)
|
|
|
|
if not files:
|
|
print(' [WARN] no files found', flush=True)
|
|
return
|
|
|
|
print('[STEP 2] Build PowerShell command array and invoke import.js --file', flush=True)
|
|
# Build a PS array literal to pass to node. We chunk to avoid CLI length limits.
|
|
CHUNK = 50
|
|
total_imported = 0
|
|
total_parsed = 0
|
|
for i in range(0, len(files), CHUNK):
|
|
batch = files[i:i+CHUNK]
|
|
# PowerShell @() array with paths quoted
|
|
quoted = ','.join(f'"{p}"' for p in batch)
|
|
script = (
|
|
r'cd C:\Shares\testdatadb; ' +
|
|
f'$files = @({quoted}); ' +
|
|
r'& node database/import.js --file @files 2>&1'
|
|
)
|
|
out, err, rc = ps(c, script, to=300)
|
|
lines = out.splitlines()
|
|
# Print a summary tail of each chunk
|
|
tail = [l for l in lines if 'records' in l.lower() or 'total' in l.lower() or 'error' in l.lower()]
|
|
print(f' chunk {i//CHUNK + 1} ({len(batch)} files): rc={rc}', flush=True)
|
|
for t in tail[-4:]:
|
|
print(f' {t}', flush=True)
|
|
if err.strip() and 'CLIXML' not in err:
|
|
print(f' STDERR: {err[:400]}', flush=True)
|
|
|
|
print('[STEP 3] Count VASLOG_ENG in DB', flush=True)
|
|
script = (
|
|
r'cd C:\Shares\testdatadb; & node -e "'
|
|
r"const db=require('./database/db');"
|
|
r"(async()=>{const r=await db.queryOne(\"SELECT COUNT(*) c FROM test_records WHERE log_type='VASLOG_ENG'\");"
|
|
r'console.log(\"VASLOG_ENG rows: \"+r.c);await db.close();})();"'
|
|
)
|
|
out, err, rc = ps(c, script, to=60)
|
|
print(out, flush=True)
|
|
if err.strip() and 'CLIXML' not in err:
|
|
print(f' STDERR: {err[:400]}', flush=True)
|
|
|
|
print('[STEP 4] Cleanup scratch files on AD2', flush=True)
|
|
sftp = c.open_sftp()
|
|
for scratch in ['C:/Shares/testdatadb/_gen_one.js', 'C:/Shares/testdatadb/_count.js']:
|
|
try:
|
|
sftp.remove(scratch)
|
|
print(f' removed {scratch}', flush=True)
|
|
except Exception as e:
|
|
print(f' [WARN] {scratch}: {e}', flush=True)
|
|
sftp.close()
|
|
finally:
|
|
c.close()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|