diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-17 12:59:30 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-17 12:59:30 -0400 |
commit | 4c3c6bf163b1b26fa883e724463dafa8ccbbdd0d (patch) | |
tree | 64ae6d125a8d7c06fa6555201dcccfa436b354a2 | |
parent | 95d3a2ef4001473aa382eafea2ed00a066973c11 (diff) | |
download | python-termcast-server-4c3c6bf163b1b26fa883e724463dafa8ccbbdd0d.tar.gz python-termcast-server-4c3c6bf163b1b26fa883e724463dafa8ccbbdd0d.zip |
reformatting
-rw-r--r-- | server.py | 8 | ||||
-rw-r--r-- | ssh.py | 36 | ||||
-rw-r--r-- | termcast.py | 12 |
3 files changed, 41 insertions, 15 deletions
@@ -40,13 +40,17 @@ class Server(object): def handle_ssh_connection(self, client): self._handle_connection( client, - lambda client, connection_id: ssh.Connection(client, connection_id, self.publisher, self.keyfile) + lambda client, connection_id: ssh.Connection( + client, connection_id, self.publisher, self.keyfile + ) ) def handle_termcast_connection(self, client): self._handle_connection( client, - lambda client, connection_id: termcast.Connection(client, connection_id, self.publisher) + lambda client, connection_id: termcast.Connection( + client, connection_id, self.publisher + ) ) def _wait_for_connection(self, sock, cb): @@ -37,7 +37,11 @@ class Connection(object): break self.watching_id = streamer["id"] - print("new viewer watching %s (%s)" % (streamer["name"], streamer["id"])) + print( + "new viewer watching %s (%s)" % ( + streamer["name"], streamer["id"] + ) + ) self.chan.send( "\033[1;%d;1;%dr\033[m\033[H\033[2J" % ( streamer["rows"], streamer["cols"] @@ -48,8 +52,14 @@ class Connection(object): while True: c = self.chan.recv(1) if c == b'q': - print("viewer stopped watching %s (%s)" % (streamer["name"], streamer["id"])) - self.publisher.notify("viewer_disconnect", self.watching_id) + print( + "viewer stopped watching %s (%s)" % ( + streamer["name"], streamer["id"] + ) + ) + self.publisher.notify( + "viewer_disconnect", self.watching_id + ) self.chan.send( "\033[1;%d;1;%dr\033[m\033[H\033[2J" % ( self.server.rows, self.server.cols @@ -106,15 +116,17 @@ class Connection(object): for streamer in streamers: key = streamer["key"] name = streamer["name"].decode('utf-8') - size = "(%dx%d)" % (streamer["cols"], streamer["rows"]) + rows = streamer["rows"] + cols = streamer["cols"] + viewers = streamer["viewers"] + idle = streamer["idle_time"] + total = streamer["total_time"] + size = "(%dx%d)" % (cols, rows) size_pre = "" size_post = "" - if streamer["cols"] > self.server.cols or streamer["rows"] > self.server.rows: + if cols > self.server.cols or rows > self.server.rows: size_pre = "\033[31m" size_post = "\033[m" - viewers = streamer["viewers"] - idle = streamer["idle_time"] - total = streamer["total_time"] self.chan.send( "\033[%dH%s) %-20s %s%-15s%s %-10s %-15s %-15s" % ( row, key, name, size_pre, size, size_post, @@ -134,13 +146,17 @@ class Server(paramiko.ServerInterface): def check_channel_request(self, kind, chanid): return paramiko.OPEN_SUCCEEDED - def check_channel_pty_request(self, channel, term, width, height, pixelwidth, pixelheight, modes): + def check_channel_pty_request( + self, channel, term, width, height, pixelwidth, pixelheight, modes + ): self.cols = width self.rows = height self.pty_event.set() return True - def check_channel_window_change_request(self, channel, width, height, pixelwidth, pixelheight): + def check_channel_window_change_request( + self, channel, width, height, pixelwidth, pixelheight + ): self.cols = width self.rows = height return True diff --git a/termcast.py b/termcast.py index 3363365..a8b47b1 100644 --- a/termcast.py +++ b/termcast.py @@ -129,7 +129,9 @@ class Connection(object): buf = buf[len(m.group(0)):] if "geometry" in extra_data: - self.handler = Handler(extra_data["geometry"][1], extra_data["geometry"][0]) + self.handler = Handler( + extra_data["geometry"][1], extra_data["geometry"][0] + ) else: self.handler = Handler(24, 80) @@ -137,7 +139,9 @@ class Connection(object): while True: buf = self.client.recv(1024) if len(buf) > 0: - self.publisher.notify("new_data", self.connection_id, self.handler.buf, buf) + self.publisher.notify( + "new_data", self.connection_id, self.handler.buf, buf + ) self.handler.process(buf) else: return @@ -146,7 +150,9 @@ class Connection(object): if connection_id != self.connection_id: return self.viewers += 1 - self.publisher.notify("new_data", self.connection_id, self.handler.buf, b'') + self.publisher.notify( + "new_data", self.connection_id, self.handler.buf, b'' + ) self.client.send(b"msg watcher connected\n") def msg_viewer_disconnect(self, connection_id): |