clean tests run: pi 1.5.0 model-list shim, panes checked by process, board r refreshes detail, office . accepted
This commit is contained in:
@@ -104,6 +104,10 @@ def main():
|
||||
result, ident, ws = tuios.open_pane(
|
||||
name, workspace, folder, command, session,
|
||||
adopt_existing=(name == "shell"),
|
||||
# The shell pane is a shell whether we started it or TUIOS restored
|
||||
# it, so it is always adopted. The other seven must be running the
|
||||
# harness, or they are a prompt pretending to be a page.
|
||||
expect=None if name == "shell" else "harness",
|
||||
)
|
||||
h.say(" %-9s %-8s workspace %s" % (name, result, ws))
|
||||
|
||||
|
||||
BIN
bin/harness
BIN
bin/harness
Binary file not shown.
Binary file not shown.
@@ -92,7 +92,25 @@ def claim(name, session=None):
|
||||
return free["workspace"]
|
||||
|
||||
|
||||
def open_pane(name, workspace_name, cwd, command, session=None, adopt_existing=False):
|
||||
def running(window):
|
||||
"""What the pane's own process is running, as one line.
|
||||
|
||||
TUIOS restores a session after a reboot with a fresh shell in every pane and
|
||||
keeps the pane's name, so the name says where a pane belongs, never what it is
|
||||
doing. Reading the process is the only honest check.
|
||||
"""
|
||||
pid = window.get("pid")
|
||||
if not pid:
|
||||
return ""
|
||||
try:
|
||||
with open("/proc/%s/cmdline" % int(pid), "rb") as fh:
|
||||
return fh.read().replace(b"\0", b" ").decode("utf-8", "replace").strip()
|
||||
except (OSError, ValueError):
|
||||
return ""
|
||||
|
||||
|
||||
def open_pane(name, workspace_name, cwd, command, session=None, adopt_existing=False,
|
||||
expect=None):
|
||||
"""Open a pane in a named workspace, or say it is already there.
|
||||
|
||||
With adopt_existing, a pane already in that workspace is adopted even if it
|
||||
@@ -116,8 +134,15 @@ def open_pane(name, workspace_name, cwd, command, session=None, adopt_existing=F
|
||||
)
|
||||
return "adopted", w["window_id"], ws
|
||||
for w in windows(session):
|
||||
if (w.get("custom_name") or "") == name:
|
||||
return "adopted", w["window_id"], ws
|
||||
if (w.get("custom_name") or "") != name:
|
||||
continue
|
||||
if expect and expect not in running(w):
|
||||
# The pane has the right name and nothing running in it: a pane
|
||||
# restored from a snapshot, or one whose program has exited. Close it
|
||||
# and open a fresh one, so the page is the page and not a bare prompt.
|
||||
close_pane(name, session)
|
||||
break
|
||||
return "adopted", w["window_id"], ws
|
||||
subprocess.run(
|
||||
[
|
||||
"tuios", "new-window", name,
|
||||
|
||||
14
bin/office
14
bin/office
@@ -42,8 +42,8 @@ def parse(argv):
|
||||
of --remote as the folder, which is exactly the kind of bug that only shows
|
||||
up when someone uses the flag.
|
||||
"""
|
||||
opts = {"folder": ".", "project": "", "session": "", "dry": False,
|
||||
"host": "", "no_switch": False, "new": "", "remote": ""}
|
||||
opts = {"folder": ".", "folder_given": False, "project": "", "session": "",
|
||||
"dry": False, "host": "", "no_switch": False, "new": "", "remote": ""}
|
||||
positional = []
|
||||
i = 0
|
||||
while i < len(argv):
|
||||
@@ -64,6 +64,7 @@ def parse(argv):
|
||||
i += 1
|
||||
if positional:
|
||||
opts["folder"] = positional[0]
|
||||
opts["folder_given"] = True
|
||||
return opts
|
||||
|
||||
|
||||
@@ -254,7 +255,9 @@ def main():
|
||||
h.say(USAGE.strip())
|
||||
return 0
|
||||
opts = parse(argv)
|
||||
if opts["folder"] in ("", "."):
|
||||
if not opts["folder_given"]:
|
||||
# "." is a real folder: `office . --project <name>` adopts the folder you
|
||||
# are standing in. Only a missing argument is an error.
|
||||
raise h.Refused(2, "give the folder: office <folder> --project \"<Name>\" (office --help)")
|
||||
folder = os.path.abspath(os.path.expanduser(opts["folder"]))
|
||||
if not os.path.isdir(folder):
|
||||
@@ -289,7 +292,10 @@ def main():
|
||||
return run_on_remote(opts["remote"], folder, opts)
|
||||
|
||||
if opts["dry"]:
|
||||
h.say("would create a Paperclip project %r for %s" % (opts["new"] or opts["project"], folder))
|
||||
if opts["new"]:
|
||||
h.say("would create a Paperclip project %r for %s" % (opts["new"], folder))
|
||||
else:
|
||||
h.say("would adopt the Paperclip project %r for %s" % (opts["project"] or "<from .harness/harness.toml>", folder))
|
||||
h.say("would write %s" % os.path.join(folder, ".harness", "harness.toml"))
|
||||
h.say("would create or reuse session %r and build eight panes there" % session)
|
||||
h.say("dry run: nothing was written")
|
||||
|
||||
Reference in New Issue
Block a user