Compare commits
No commits in common. "lash/mux-input" and "master" have entirely different histories.
lash/mux-i
...
master
97
parse.py
97
parse.py
@ -4,8 +4,6 @@ import enum
|
||||
import uuid
|
||||
import os
|
||||
import logging
|
||||
import sys
|
||||
import select
|
||||
from multiprocessing import Process
|
||||
from multiprocessing import Value
|
||||
from multiprocessing import Pipe
|
||||
@ -273,7 +271,6 @@ class Router:
|
||||
|
||||
|
||||
def exec(self, cmd):
|
||||
logg.debug("router exec {}".format(cmd))
|
||||
if cmd.c & 0xa0 > 0:
|
||||
return self.sync(cmd.i)
|
||||
fn = self.__routes[cmd.c]
|
||||
@ -283,17 +280,10 @@ class Router:
|
||||
po.start()
|
||||
|
||||
|
||||
def finish(self):
|
||||
print("syncing")
|
||||
for k, v in self.__r.items():
|
||||
print("syncing key " + k)
|
||||
r = self.sync(k)
|
||||
logg.debug("synced " + k + ": " + r)
|
||||
print("synced " + k + ": " + r)
|
||||
|
||||
|
||||
def __del__(self):
|
||||
self.finish()
|
||||
for k, v in self.__r.items():
|
||||
r = self.sync(k)
|
||||
logging.debug("synced " + k + ": " + r)
|
||||
|
||||
|
||||
def noop_handler(cmd):
|
||||
@ -306,76 +296,21 @@ def foo_handler(cmd):
|
||||
|
||||
parser = yacc.yacc()
|
||||
|
||||
running = True
|
||||
|
||||
|
||||
class FileGet:
|
||||
def __init__(self, o, fp):
|
||||
self.__running = True
|
||||
self.__o = o
|
||||
self.__f = open(fp, 'r')
|
||||
|
||||
def run(self):
|
||||
while self.__running:
|
||||
v = ifc.get()
|
||||
if v == None:
|
||||
break
|
||||
v = v.strip('\n')
|
||||
if len(v) == 0:
|
||||
break
|
||||
r = parser.parse(v)
|
||||
self.__o.exec(r)
|
||||
|
||||
def get(self):
|
||||
return self.__f.readline()
|
||||
|
||||
|
||||
class WaitGet:
|
||||
def __init__(self, o, *r):
|
||||
self.__running = True
|
||||
self.__o = o
|
||||
self.__f = r
|
||||
|
||||
# TODO: router copy results in missing keys to sync when closing down
|
||||
def __process(self, f):
|
||||
while self.__running:
|
||||
r = select.select([f], [], [])
|
||||
v = r[0][0].recv()
|
||||
if v == None:
|
||||
break
|
||||
v = v.strip('\n')
|
||||
if len(v) == 0:
|
||||
break
|
||||
r = parser.parse(v)
|
||||
self.__o.exec(r)
|
||||
|
||||
|
||||
def run(self):
|
||||
(fo, fi,) = Pipe()
|
||||
p = Process(target=self.__process, args=(fo,))
|
||||
p.start()
|
||||
while self.__running:
|
||||
v = input("> ")
|
||||
if v == "":
|
||||
fi.send(None)
|
||||
break
|
||||
fi.send(v)
|
||||
p.join()
|
||||
logg.debug('waitget run end')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ifc = None
|
||||
cmds = [
|
||||
"KEY_CREATE foo-bar Foo BAr",
|
||||
"KEY_CREATE bar-baz Foo BAr 0xabcdef0",
|
||||
"VOUCHER_MINT - 0xdeadbeef 13 0xfdaf",
|
||||
"VOUCHER_MINT baz-baz 0xdeadbeef 13 0xfdaf",
|
||||
"VOUCHER_MINT bar-bar 0xdeadbeef 42",
|
||||
"VOUCHER_CREATE foo-foo Foo Bar 42",
|
||||
"VOUCHER_CREATE inky-pinky-blinky Foo Bar 42 44 233",
|
||||
"VOUCHER_TRANSFER clyde-sue 0xbeeffeed0123 666 foo 0x0fdc",
|
||||
]
|
||||
for v in cmds:
|
||||
o = Router()
|
||||
o.register(CmdId.KEY_CREATE, noop_handler)
|
||||
o.register(CmdId.VOUCHER_MINT, noop_handler)
|
||||
o.register(CmdId.VOUCHER_CREATE, noop_handler)
|
||||
o.register(CmdId.VOUCHER_TRANSFER, foo_handler)
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
ifc = FileGet(o, sys.argv[1])
|
||||
else:
|
||||
ifc = WaitGet(o, sys.stdin)
|
||||
|
||||
ifc.run()
|
||||
o.finish()
|
||||
r = parser.parse(v)
|
||||
o.exec(r)
|
||||
|
Loading…
Reference in New Issue
Block a user