9 tuerSock = "/run/tuer.sock"
12 histfile = os.path.join(os.path.expanduser("~"), ".pyshellhist")
14 readline.read_history_file(histfile)
18 atexit.register(readline.write_history_file, histfile)
22 print("Available commands: %s" % ", ".join(sorted(commands.keys())))
26 ret = subprocess.call(cmd)
28 print("Command returned non-zero exit statis %d" % ret)
31 def sendcmd(addr, cmd):
33 print("Running %s..." % (cmd))
34 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
41 print("Received unexpected answer %s" % str(data))
45 'exit': None, # catched below, quits the loop
47 'open': sendcmd(tuerSock, 'open'),
48 'close': sendcmd(tuerSock, 'close'),
49 'buzz': sendcmd(tuerSock, 'buzz'),
53 print("Welcome to tyshell. Use help to see what you can do.")
60 command = shlex.split(command)
61 if not len(command): continue
63 if command[0] == "exit":
65 elif command[0] in commands:
67 commands[command[0]](command)
68 except Exception as e:
69 print("Error while executing %s: %s" % (command[0], str(e)))
71 print("Command %s not found. Use help." % command[0])