2021-10-11 12:23:08 +02:00
|
|
|
|
# standard imports
|
|
|
|
|
import os
|
2021-10-11 17:39:01 +02:00
|
|
|
|
import sys
|
2021-10-15 12:48:14 +02:00
|
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
logg = logging.getLogger(__name__)
|
2021-10-11 12:23:08 +02:00
|
|
|
|
|
|
|
|
|
|
2021-10-11 17:39:01 +02:00
|
|
|
|
class OutputWriter:
|
|
|
|
|
|
2021-10-12 08:39:20 +02:00
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-10-11 17:39:01 +02:00
|
|
|
|
def write(self, k, v):
|
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
2021-10-12 08:39:20 +02:00
|
|
|
|
class StdoutWriter(OutputWriter):
|
2021-10-11 17:39:01 +02:00
|
|
|
|
|
|
|
|
|
def write(self, k, v):
|
|
|
|
|
sys.stdout.write('{}\t{}\n'.format(k, v))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class KVWriter(OutputWriter):
|
2021-10-11 12:23:08 +02:00
|
|
|
|
|
2021-10-12 08:39:20 +02:00
|
|
|
|
def __init__(self, path=None, *args, **kwargs):
|
2021-10-11 12:23:08 +02:00
|
|
|
|
os.stat(path)
|
|
|
|
|
self.path = path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write(self, k, v):
|
2021-10-11 15:28:09 +02:00
|
|
|
|
fp = os.path.join(self.path, str(k))
|
2021-10-15 12:48:14 +02:00
|
|
|
|
logg.debug('path write {} {}'.format(fp, str(v)))
|
2021-10-11 17:39:01 +02:00
|
|
|
|
f = open(fp, 'wb')
|
2021-10-11 12:23:08 +02:00
|
|
|
|
f.write(v)
|
|
|
|
|
f.close()
|