Skip to content

Commit

Permalink
[remote_control] add more detailed output, reuse old files
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkerrigan committed Jun 13, 2023
1 parent 3b3a181 commit bb0c8e6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions plugins/remote_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def handle(self):
self.request.sendall(str(result).encode('utf8'))
self.server.sheet.addRow(dict(command=data, exit_code=result, error=error))


class RemoteControlSheet(Sheet):
"""A sheet that provides rudimentary remote control features
Expand All @@ -74,8 +73,12 @@ class RemoteControlSheet(Sheet):
def __init__(self, name):
super().__init__(name)
Path("~/.visidata/run").expanduser().mkdir(parents=True, exist_ok=True)
socket_path = Path(f"~/.visidata/run/{name}").expanduser()
if socket_path.exists() and socket_path.is_socket():
vd.status(f"Replacing existing socket at {socket_path}")
socket_path.unlink()
self.server = socketserver.UnixStreamServer(
str(Path(f"~/.visidata/run/{name}").expanduser()),
str(socket_path),
VisiDataRemoteControlHandler,
)
self.server.sheet = self
Expand All @@ -84,19 +87,19 @@ def __init__(self, name):
@asyncthread
def serve(self):
self.server.serve_forever()
vd.status("server closed")
vd.status("Remote control socket closed")


@RemoteControlSheet.api
def confirmQuit(vs, verb="quit"):
"""Try to avoid leaving dangling socket nonsense"""

super(vs.__class__, vs).confirmQuit(verb)
vd.status("closing server")
vd.status("Closing remote control socket")
vs.server.shutdown()
with suppress(OSError, FileNotFoundError):
sockname = vs.server.socket.getsockname()
vd.status(f"removing file {sockname}")
vd.status(f"Removing {sockname}")
Path(sockname).expanduser().unlink()


Expand Down

0 comments on commit bb0c8e6

Please sign in to comment.