code wiki / _hdl_build / nx_figures_data_push.nx

nx_figures_data_push.nx source

↩ module page · 111 lines · 5117 B

1// nx_figures_data_push.nx -- push the 3 downloadable dataset files (figures_data.{csv,json,tsv}) to the 2// live wiki doc-root as STATIC ASSETS, so the <a href="/wiki/figures_data.csv" download> links on 3// /wiki/figures.html actually resolve. ADDITIVE: each push is `mkdir -p <wikidir>; cat > <wikidir>/<f>` 4// -- writes exactly that one file, never deletes/clobbers anything else. 5// 6// REUSE: the proven sovereign push spine _offc/nx_aw_push.elf (vault-backed SSH stream). We drive it in 7// its argv mode (argc>=3: src-spec-file + dst-cmd-file) with per-file spec files, so it never collides 8// with the default awpush.src/.dst the page publisher uses. Each nx_aw_push runs as a SEPARATE forked 9// process (its 4GB sys_read_file reservation lives in the child, not here) -- so pushing 3 files from 10// one parent is safe. license_tier: ORIGINAL 11import "nx_syscalls.nx" 12const FD_MAGIC_1024: i64 = 1024 13 14const FD_WIKIDIR: *u8 = "/volume1/homes/elderwesto/nishihost/sites/nishifamily/wiki" as *u8 15const FD_PUSH_ELF: *u8 = "_offc/nx_aw_push.elf" as *u8 16 17func fd_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 18func fd_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != 0 as u8 { dst[o] = s[i]; o = o + 1; i = i + 1 } return o } 19 20// write a NUL-terminated string (known length) to a file (fresh). 21func fd_write_file(path: *u8, content: *u8, clen: i64) -> i64 { 22 let fd: i64 = sys_openat_wr(path, MODE_0644) 23 if fd < 0 { return 0 - 1 } 24 sys_write(fd, content, clen) 25 sys_close(fd) 26 return 0 27} 28 29// fork+exec the push elf with argv = [elf, src_spec, dst_spec]; wait; return child exit code. 30func fd_run(src_spec: *u8, dst_spec: *u8) -> i64 { 31 let pid: i64 = sys_fork() 32 if pid == 0 { 33 let argv: *i64 = sys_mmap(64) as *i64 34 argv[0] = FD_PUSH_ELF as i64 35 argv[1] = src_spec as i64 36 argv[2] = dst_spec as i64 37 argv[3] = 0 38 let envp: *i64 = sys_mmap(16) as *i64 39 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0 40 sys_execve(FD_PUSH_ELF, argv, envp) 41 sys_exit(127) 42 } 43 let st: *i64 = sys_mmap(16) as *i64 44 sys_wait4(pid, st, 0) 45 return (st[0] >> 8) & 0xff 46} 47 48// push web_assets/<fname> -> <wikidir>/<fname>. spec-file paths are tagged by idx so the 3 calls 49// don't share files. returns child exit code. 50func fd_push_one(fname: *u8, idx: i64) -> i64 { 51 // src spec file: contains the local path (web_assets/<fname>) + newline (aw_push trims it). 52 let srcspec: *u8 = sys_mmap(256) 53 var ss: i64 = 0 54 ss = fd_cat(srcspec, ss, "/tmp/figdata_src_" as *u8) 55 srcspec[ss] = (48 + idx) as u8; ss = ss + 1 56 srcspec[ss] = 0 as u8 57 58 let dstspec: *u8 = sys_mmap(256) 59 var ds: i64 = 0 60 ds = fd_cat(dstspec, ds, "/tmp/figdata_dst_" as *u8) 61 dstspec[ds] = (48 + idx) as u8; ds = ds + 1 62 dstspec[ds] = 0 as u8 63 64 // src content = web_assets/<fname>\n 65 let srcbuf: *u8 = sys_mmap(512) 66 var so: i64 = 0 67 so = fd_cat(srcbuf, so, "web_assets/" as *u8) 68 so = fd_cat(srcbuf, so, fname) 69 srcbuf[so] = 10 as u8; so = so + 1 70 srcbuf[so] = 0 as u8 71 if fd_write_file(srcspec, srcbuf, so) != 0 { fd_w(" src-spec write FAIL\n"); return 0 - 1 } 72 73 // dst content = mkdir -p <wikidir>; cat > <wikidir>/<fname>\n 74 let dstbuf: *u8 = sys_mmap(FD_MAGIC_1024) 75 var d: i64 = 0 76 d = fd_cat(dstbuf, d, "mkdir -p " as *u8) 77 d = fd_cat(dstbuf, d, FD_WIKIDIR) 78 d = fd_cat(dstbuf, d, "; cat > " as *u8) 79 d = fd_cat(dstbuf, d, FD_WIKIDIR) 80 d = fd_cat(dstbuf, d, "/" as *u8) 81 d = fd_cat(dstbuf, d, fname) 82 dstbuf[d] = 10 as u8; d = d + 1 83 dstbuf[d] = 0 as u8 84 if fd_write_file(dstspec, dstbuf, d) != 0 { fd_w(" dst-spec write FAIL\n"); return 0 - 1 } 85 86 fd_w(" pushing "); fd_w(fname); fd_w(" -> "); fd_w(FD_WIKIDIR); fd_w("/"); fd_w(fname); fd_w("\n") 87 let rc: i64 = fd_run(srcspec, dstspec) 88 fd_w(" push rc="); 89 let bb: *u8 = sys_mmap(28); var m: i64 = rc; let t: *u8 = sys_mmap(28); var k: i64 = 0 90 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 91 if m == 0 { t[0] = 48 as u8; k = 1 } 92 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 93 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); fd_w("\n") 94 return rc 95} 96 97func main() -> i64 { 98 fd_w("=== FIGURES DATA PUSH: 3 dataset files -> live wiki doc-root (additive static assets) ===\n") 99 var ok: i64 = 0 100 if fd_push_one("figures_data.csv" as *u8, 0) == 0 { ok = ok + 1 } 101 if fd_push_one("figures_data.json" as *u8, 1) == 0 { ok = ok + 1 } 102 if fd_push_one("figures_data.tsv" as *u8, 2) == 0 { ok = ok + 1 } 103 fd_w("=== pushed "); 104 let bb: *u8 = sys_mmap(28); var m: i64 = ok; var k: i64 = 0; let t: *u8 = sys_mmap(28) 105 if m == 0 { t[0] = 48 as u8; k = 1 } 106 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 107 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k) 108 fd_w("/3 data files LIVE ===\n") 109 if ok == 3 { sys_exit(0); return 0 } 110 sys_exit(1); return 1 111}