Add send cli tool, make token resolver pluggable
This commit is contained in:
29
chaind/eth/cli/csv.py
Normal file
29
chaind/eth/cli/csv.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CSVProcessor:
|
||||
|
||||
def load(self, s):
|
||||
contents = []
|
||||
f = None
|
||||
try:
|
||||
f = open(s, 'r')
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
import csv # only import if needed
|
||||
fr = csv.reader(f)
|
||||
|
||||
for r in fr:
|
||||
contents.append(r)
|
||||
f.close()
|
||||
l = len(contents)
|
||||
logg.info('successfully parsed source as csv, found {} records'.format(l))
|
||||
return contents
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return 'csv processor'
|
||||
34
chaind/eth/cli/output.py
Normal file
34
chaind/eth/cli/output.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import socket
|
||||
import enum
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class OpMode(enum.Enum):
|
||||
STDOUT = 'standard_output'
|
||||
UNIX = 'unix_socket'
|
||||
|
||||
class Outputter:
|
||||
|
||||
def __init__(self, mode):
|
||||
self.out = getattr(self, 'do_' + mode.value)
|
||||
|
||||
|
||||
def do(self, hx, *args, **kwargs):
|
||||
return self.out(hx, *args, **kwargs)
|
||||
|
||||
|
||||
def do_standard_output(self, hx, *args, **kwargs):
|
||||
return hx
|
||||
|
||||
|
||||
def do_unix_socket(self, hx, *args, **kwargs):
|
||||
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
s.connect(kwargs['socket'])
|
||||
s.send(hx.encode('utf-8'))
|
||||
r = s.recv(64+4)
|
||||
logg.debug('r {}'.format(r))
|
||||
s.close()
|
||||
return r[4:].decode('utf-8')
|
||||
Reference in New Issue
Block a user