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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user