Skip to content

Instantly share code, notes, and snippets.

@traverseda
Last active June 22, 2019 01:35
Show Gist options
  • Save traverseda/52b87330141aaed7300408e80d06512e to your computer and use it in GitHub Desktop.
Save traverseda/52b87330141aaed7300408e80d06512e to your computer and use it in GitHub Desktop.
#Run using `python catcher.py python asyncServer.py /home/traverseda`
import rpyc, sys, pathlib, os, math
class FileListingService(rpyc.Service,pathlib.PosixPath):
def on_connect(self, conn):
self._conn = conn
sys.stdout = conn.root.stdout
pass
def on_disconnect(self, conn):
pass
def __repr__(self):
out = []
width, height = self._conn.root.get_terminal_size()
maxWidth = max([len(i.name) for i in self.iterdir()])+2
columns = math.floor(width/maxWidth)
padding = math.floor(width/columns)
noHidden = (i for i in self.iterdir() if not i.name.startswith("."))
for i, f in enumerate(noHidden):
print(i,(i+1)%columns)
out.append(f.name.ljust(padding))
if (i+1)%columns == 0:
out.append("\n")
return "".join(out)
if __name__ == "__main__":
p="."
if len(sys.argv) == 2:
p=sys.argv[1]
server = rpyc.utils.factory.connect_pipes(sys.stdin,sys.stdout,FileListingService(p))
server.serve_all()
import sys, subprocess, rpyc, os
#We need to provide an rpyc object to the remote object, so it
#can find out things like how wide the terminal is.
class XonshService(rpyc.Service):
exposed_get_terminal_size = os.get_terminal_size
exposed_stdout = rpyc.utils.helpers.restricted(sys.stdout,("write",))
p = subprocess.Popen(sys.argv[1:],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
remoteConnection = rpyc.utils.factory.connect_pipes(p.stdout,p.stdin, service=XonshService)
remote = remoteConnection.root
print("\033[92mTo get started, try typing 'remote'\033[0m")
import code; code.interact(local=locals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment