9 tuerSock = "/run/tuer.sock"
12 histfile = os.path.join(os.path.expanduser("~"), ".tyshellhist")
14 readline.read_history_file(histfile)
18 atexit.register(readline.write_history_file, histfile)
19 atexit.register(print, "Bye")
23 print("Available commands: %s" % ", ".join(sorted(longcommands.keys())))
27 ret = subprocess.call(cmd)
29 print("Command returned non-zero exit statis %d" % ret)
32 def sendcmd(addr, cmd):
34 print("Running %s..." % (cmd))
35 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
42 print("Received unexpected answer %s" % str(data))
51 'open': sendcmd(tuerSock, 'open'),
52 'close': sendcmd(tuerSock, 'close'),
53 'buzz': sendcmd(tuerSock, 'buzz'),
56 # command convenience shortcuts
57 def filterCommonPrefix (strings, length):
58 # ignores duplicates in the string list "strings"
63 if a[:length] == b[:length]:
66 ret = list(strings) # copy
74 def shortcutify (dic):
79 for i in range(maxlen):
80 shortable = filterCommonPrefix (dic.keys(), i)
83 return dic # only for convenience, as dic is passed by reference
85 longcommands = commands.copy()
86 shortcutify (commands)
90 print("Welcome to tyshell. Use help to see what you can do.")
97 command = shlex.split(command)
98 if not len(command): continue
100 if command[0] in commands:
102 commands[command[0]](command)
103 except Exception as e:
104 print("Error while executing %s: %s" % (command[0], str(e)))
106 print("Command %s not found. Use help." % command[0])