Files
dssc/dsflow/demo.py
T
lucioandClaude Opus 5.5 60532a4043 Rebuild the UI on vendored Textual; make the checkout self-contained
The internal servers have no access to outside package repositories and
run Python 3.8/3.9, so the UI moves from hand-drawn curses to Textual
6.2.1 (the last release supporting 3.8.1), vendored with its pure-Python
dependencies in vendor/. The launcher puts vendor/ first on sys.path, so a
plain checkout runs with no pip and no network.

- dsflow/: the single script split into a package (pure moves of the
  backend sections); action rules moved to ops.py, free of Textual
- dsflow/ui/: tabs, detail pane, live sanity-run panel, log viewer,
  modal dialogs, filter, themes, mouse support
- tests/test_ui.py: headless UI tests through Textual's pilot
- tools/vendor.py (refresh vendor/), tools/screenshots.py (README images)
- README, CLAUDE.md, TODO and the feature doc updated for the new layout,
  the Python 3.8.1 floor and the vendoring rules

Verified: 11 tests green on Python 3.12 and 3.8.20; the shipped file set
runs under `python -I -S` on both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-24 03:24:21 -07:00

255 lines
9.8 KiB
Python

"""--demo: a sandbox workspace driven by a fake dssc, so every action can be tried without a vault."""
import json
import os
import shutil
from .common import ME, sha1_file
FAKE_DSSC = r'''#!/usr/bin/env python3
"""Fake dssc for the dsflow_tui demo. Vault state lives in $DSSC_FAKE_VAULT."""
import hashlib, json, os, sys, time, getpass
VAULT = os.environ["DSSC_FAKE_VAULT"]
ROOT = os.path.dirname(os.path.realpath(VAULT))
ME = os.environ.get("USER") or getpass.getuser()
time.sleep(0.03)
def load():
with open(VAULT) as fh:
return json.load(fh)
def save(v):
with open(VAULT + ".tmp", "w") as fh:
json.dump(v, fh, indent=1)
os.replace(VAULT + ".tmp", VAULT)
def ab(f): return os.path.join(ROOT, f)
def sha(f):
try:
with open(ab(f), "rb") as fh:
return hashlib.sha1(fh.read()).hexdigest()
except OSError:
return None
def modified(v, f): return sha(f) != v["files"][f]["hash"]
def bump(ver):
a, b = ver.rsplit(".", 1)
return "%s.%d" % (a, int(b) + 1)
def die(msg):
sys.stderr.write("dssc: %s\n" % msg)
sys.exit(1)
def parse(argv, valued):
flags, vals, pos, i = set(), {}, [], 0
while i < len(argv):
a = argv[i]
if a.startswith("-") and len(a) > 1:
if a in valued:
vals[a] = argv[i + 1]
i += 2
continue
flags.add(a)
else:
pos.append(a)
i += 1
return flags, vals, pos
def targets(v, pos):
out = []
for p in pos or ["."]:
r = os.path.relpath(os.path.realpath(p), ROOT)
if r == ".":
out += sorted(v["files"])
elif r in v["files"]:
out.append(r)
else:
out += [f for f in sorted(v["files"]) if f.startswith(r.rstrip("/") + "/")]
return out
def fetch(v, f, ver, note):
e, mode = v["files"][f], os.stat(ab(f)).st_mode & 0o777
os.chmod(ab(f), 0o644)
with open(ab(f), "a") as fh:
fh.write("// %s %s\n" % (note, ver))
os.chmod(ab(f), mode)
e["base"] = ver
cmd, argv = sys.argv[1], sys.argv[2:]
v = load()
if cmd == "ls":
fl, vals, pos = parse(argv, {"-report"})
rep = vals.get("-report", "N")
for f in targets(v, pos):
e = v["files"][f]
if "-modified" in fl and not modified(v, f):
continue
print({"N": f, "V": e["base"], "L": e["locker"]}.get(rep, f))
elif cmd == "vhistory":
fl, vals, pos = parse(argv, {"-max", "-branch"})
for f in targets(v, pos):
e = v["files"][f]
print("%s %s 2026-09-22 17:04 %s" % (e["latest"], e.get("author", "bob"), "Trunk"))
elif cmd in ("co", "lock"):
fl, vals, pos = parse(argv, {"-version", "-comment"})
for f in targets(v, pos):
e = v["files"][f]
if e["locker"] and e["locker"] != ME:
die("%s is locked by %s" % (f, e["locker"]))
if cmd == "lock" or "-lock" in fl:
e["locker"] = ME
if cmd == "co":
if not modified(v, f) and e["base"] != e["latest"]:
fetch(v, f, e["latest"], "fetched")
e["hash"] = sha(f)
os.chmod(ab(f), 0o644)
print("%s : Success - %s" % (f, "locked" if e["locker"] == ME else "checked out"))
save(v)
elif cmd == "unlock":
fl, vals, pos = parse(argv, set())
for f in targets(v, pos):
e = v["files"][f]
if e["locker"] and e["locker"] != ME:
die("%s is locked by %s" % (f, e["locker"]))
e["locker"] = ""
print("%s : Success - unlocked" % f)
save(v)
elif cmd == "ci":
fl, vals, pos = parse(argv, {"-comment"})
if "-new" in fl:
for p in pos:
f = os.path.relpath(os.path.realpath(p), ROOT)
if f in v["files"]:
die("%s is already managed" % f)
v["files"][f] = dict(base="1.1", latest="1.1", hash=sha(f), locker="", tags={}, author=ME)
os.chmod(ab(f), 0o444)
print("%s : Success - new version 1.1" % f)
else:
for f in targets(v, pos):
e = v["files"][f]
if e["locker"] and e["locker"] != ME:
die("%s is locked by %s" % (f, e["locker"]))
if e["base"] != e["latest"]:
die("%s: not based on Latest (%s vs %s) - merge first" % (f, e["base"], e["latest"]))
if not modified(v, f):
print("%s : unchanged, skipped" % f)
continue
new = bump(e["latest"])
e.update(base=new, latest=new, hash=sha(f), locker="", author=ME)
os.chmod(ab(f), 0o444)
print("%s : Success - checked in %s" % (f, new))
save(v)
elif cmd == "tag":
fl, vals, pos = parse(argv, set())
tag = pos[0]
for f in targets(v, pos[1:]):
e = v["files"][f]
e["tags"][tag] = e["base"]
print("%s;%s : Success - tagged %s" % (f, e["base"], tag))
save(v)
elif cmd in ("pop", "populate"):
fl, vals, pos = parse(argv, {"-version"})
for f in targets(v, pos):
e = v["files"][f]
if e["base"] == e["latest"]:
continue
if "-merge" in fl:
fetch(v, f, e["latest"], "merged with")
print("%s : merged %s" % (f, e["latest"]))
elif not modified(v, f):
fetch(v, f, e["latest"], "fetched")
e["hash"] = sha(f)
print("%s : fetched %s" % (f, e["latest"]))
save(v)
else:
die("fake dssc: unsupported command '%s'" % cmd)
'''
DEMO_CONF = r'''# dsflow.conf for the dsflow_tui demo sandbox (fake dssc on PATH)
TRUNK_SEL="Trunk:Latest"
WORKING_TAG="working"
SANITY_CONFIGS="kibo_2x2 jaguar_1x1"
CI_EXTRA_CONFIGS=""
MAX_STAMP_AGE=$((4*3600))
HOT_FILES="${WS_ROOT:-.}/flow/hot_files.txt"
CHECKIN_LOG="@SHARE@/dsflow_checkins.log"
CI_STATE="@SHARE@/ci_state"
CI_NOTIFY="[email protected]"
DSFLOW_TAGS="wmac_working wmac_rx_drop"
# Fake regression: DEMO_FAIL="jaguar_1x1" makes that config fail.
run_sanity() {
local n=${DEMO_SANITY_TESTS:-12} i
echo "=== sanity $1 (demo) ==="
for ((i=1; i<=n; i++)); do
sleep "${DEMO_STEP_SECS:-1.5}"
echo "[$1] $(date +%T) test_$(printf %02d $i) ... PASS"
done
if [[ " ${DEMO_FAIL:-} " == *" $1 "* ]]; then
echo "[$1] ERROR: scoreboard mismatch in rx path"; return 1
fi
echo "[$1] all $n tests passed"
}
ds_list_modified() { dssc ls -rec -modified -report N . 2>/dev/null | awk 'NF'; }
ds_base_version() { dssc ls -report V "$1" 2>/dev/null | awk 'NF{v=$NF} END{print v}'; }
ds_latest_version() { dssc vhistory -max 1 -branch Trunk "$1" 2>/dev/null | awk '/^[0-9.]+/{print $1; exit}'; }
ds_lock_holder() { dssc ls -report L "$1" 2>/dev/null | awk 'NF{u=$NF} END{print u}'; }
ds_unlock() { dssc unlock "$@"; }
'''
def setup_demo(base, reset):
base = os.path.realpath(base) # macOS: /var -> /private/var would skew relative paths
ws, bindir, share = os.path.join(base, "ws"), os.path.join(base, "bin"), os.path.join(base, "share")
vault = os.path.join(ws, ".fakevault.json")
if reset and os.path.isdir(base):
for root, dirs, files in os.walk(base):
for n in dirs + files:
try:
os.chmod(os.path.join(root, n), 0o755)
except OSError:
pass
shutil.rmtree(base)
if not os.path.exists(vault):
for d in (ws, bindir, share, os.path.join(ws, "flow")):
if not os.path.isdir(d):
os.makedirs(d)
with open(os.path.join(bindir, "dssc"), "w") as fh:
fh.write(FAKE_DSSC)
os.chmod(os.path.join(bindir, "dssc"), 0o755)
with open(os.path.join(ws, "flow", "dsflow.conf"), "w") as fh:
fh.write(DEMO_CONF.replace("@SHARE@", share))
with open(os.path.join(ws, "flow", "hot_files.txt"), "w") as fh:
fh.write("# One workspace-relative path per line. Locked on edit.\n"
"rtl/top/wifi_mac_top.sv\nrtl/pkg/wifi_mac_pkg.sv\nrtl/regs/mac_regs.sv\n")
# path: (base, latest, locker, state) - state: ro | co (writable) | mod (edited)
layout = {
"rtl/top/wifi_mac_top.sv": ("1.12", "1.12", ME, "mod"),
"rtl/pkg/wifi_mac_pkg.sv": ("1.31", "1.31", "", "ro"),
"rtl/regs/mac_regs.sv": ("1.9", "1.9", "alice", "ro"),
"rtl/rx/rx_fsm.sv": ("1.4", "1.4", "", "mod"),
"rtl/rx/rx_buf.sv": ("1.6", "1.6", "", "ro"),
"rtl/tx/tx_ctrl.sv": ("1.7", "1.8", "", "mod"),
"rtl/tx/tx_crc.sv": ("1.3", "1.3", "", "co"),
"rtl/tx/tx_fifo.sv": ("1.2", "1.2", "", "mod"),
"sim/tb/tb_top.sv": ("1.20", "1.20", "", "ro"),
}
files = {}
for rel, (b, l, locker, state) in sorted(layout.items()):
p = os.path.join(ws, rel)
if not os.path.isdir(os.path.dirname(p)):
os.makedirs(os.path.dirname(p))
mod = os.path.splitext(os.path.basename(rel))[0]
with open(p, "w") as fh:
fh.write("// %s - version %s\nmodule %s;\nendmodule\n" % (rel, b, mod))
files[rel] = dict(base=b, latest=l, hash=sha1_file(p), locker=locker, tags={}, author="bob")
if state == "mod":
with open(p, "a") as fh:
fh.write("// local edit by %s\n" % ME)
os.chmod(p, 0o444 if state == "ro" else 0o644)
with open(vault, "w") as fh:
json.dump(dict(files=files), fh, indent=1)
newf = os.path.join(ws, "rtl/rx/rx_agg.sv")
with open(newf, "w") as fh:
fh.write("module rx_agg;\nendmodule\n")
if not os.path.isdir(os.path.join(ws, ".dsflow")):
os.makedirs(os.path.join(ws, ".dsflow"))
with open(os.path.join(ws, ".dsflow", "new_files"), "w") as fh:
fh.write("rtl/rx/rx_agg.sv\n")
os.environ["PATH"] = bindir + os.pathsep + os.environ.get("PATH", "")
os.environ["DSSC_FAKE_VAULT"] = vault
return ws, os.path.join(ws, "flow", "dsflow.conf")