Move stuff off of top level
This commit is contained in:
parent
94c4e0fa0c
commit
a534cacd0e
57
ethermess.py
57
ethermess.py
|
@ -61,33 +61,19 @@ def handle_user_command(backend, command):
|
||||||
else:
|
else:
|
||||||
print('s - request status, i - request msgid, m - send message, ^D - quit')
|
print('s - request status, i - request msgid, m - send message, ^D - quit')
|
||||||
|
|
||||||
# Create unbuffered version of stdin
|
def eventloop(proc):
|
||||||
unbuf_stdin = open(sys.stdin.buffer.fileno(), 'rb', buffering = 0)
|
# Create unbuffered version of stdin
|
||||||
|
unbuf_stdin = open(sys.stdin.buffer.fileno(), 'rb', buffering = 0)
|
||||||
|
|
||||||
_, interface, nick = sys.argv
|
# Set up a poll for inputs (but do output blockingly)
|
||||||
|
poll = select.poll()
|
||||||
|
poll.register(proc.stdout, select.POLLIN)
|
||||||
|
poll.register(unbuf_stdin, select.POLLIN)
|
||||||
|
|
||||||
proc = subprocess.Popen(['sudo', libexec_dir + '/ethermess-backend', interface], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = sys.stderr, bufsize = 0)
|
input_buffer = bytearray()
|
||||||
|
|
||||||
# Tell the backend the status and nick
|
running = True
|
||||||
status = 0
|
while running:
|
||||||
nick = nick.encode('utf-8')
|
|
||||||
writeall(proc.stdin, bytes([status, len(nick)]) + nick)
|
|
||||||
|
|
||||||
# Read our MAC
|
|
||||||
mac = readall(proc.stdout, 6)
|
|
||||||
|
|
||||||
print('Own mac: %s' % format_mac(mac))
|
|
||||||
|
|
||||||
print('s - request status, i - request msgid, m - send message, ^D - quit')
|
|
||||||
|
|
||||||
poll = select.poll()
|
|
||||||
poll.register(proc.stdout, select.POLLIN)
|
|
||||||
poll.register(unbuf_stdin, select.POLLIN)
|
|
||||||
|
|
||||||
input_buffer = bytearray()
|
|
||||||
|
|
||||||
running = True
|
|
||||||
while running:
|
|
||||||
for fd, event in poll.poll():
|
for fd, event in poll.poll():
|
||||||
if fd == proc.stdout.fileno() and event & select.POLLIN:
|
if fd == proc.stdout.fileno() and event & select.POLLIN:
|
||||||
event_type = readall(proc.stdout, 1)
|
event_type = readall(proc.stdout, 1)
|
||||||
|
@ -133,5 +119,26 @@ while running:
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception('Unreachable')
|
raise Exception('Unreachable')
|
||||||
|
def main():
|
||||||
|
_, interface, nick = sys.argv
|
||||||
|
|
||||||
proc.wait()
|
proc = subprocess.Popen(['sudo', libexec_dir + '/ethermess-backend', interface], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = sys.stderr, bufsize = 0)
|
||||||
|
|
||||||
|
# Tell the backend the status and nick
|
||||||
|
status = 0
|
||||||
|
nick = nick.encode('utf-8')
|
||||||
|
writeall(proc.stdin, bytes([status, len(nick)]) + nick)
|
||||||
|
|
||||||
|
# Read our MAC
|
||||||
|
mac = readall(proc.stdout, 6)
|
||||||
|
|
||||||
|
print('Own mac: %s' % format_mac(mac))
|
||||||
|
|
||||||
|
print('s - request status, i - request msgid, m - send message, ^D - quit')
|
||||||
|
|
||||||
|
eventloop(proc)
|
||||||
|
|
||||||
|
proc.wait()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in New Issue