Commit 2f9091de authored by Tommy Olofsson's avatar Tommy Olofsson
Browse files

Removed the tail process from the csv tool.

parent 9e5d3636
#!/usr/bin/env python
import time
import argparse
import labcomm
import subprocess
import sys
class Reader(object):
......@@ -20,16 +19,24 @@ class Reader(object):
class FollowingReader(object):
def __init__(self, file_):
self.tail_proc = subprocess.Popen(['tail', '-c', '+0', '-f', file_],
class FollowingReader(Reader):
def __init__(self, file_, interval, timeout):
super(FollowingReader, self).__init__(file_)
self._interval = interval
self._timeout = timeout
def read(self, count):
def mark(self, value, decl):
data = ''
t_start = time.time()
while len(data) < count:
tmp = - len(data))
if tmp:
data += tmp
if self._timeout and time.time() - t_start > self._timeout:
raise EOFError()
return data
def flatten(sample, _type):
......@@ -87,10 +94,17 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('elc', type=str, help="The log file.")
parser.add_argument('-f', '--follow', action='store_true',
help="Find all registrations that already "
help="find all registrations that already "
"exist, then watch the file for changes. All "
"future registrations are ignored (because "
"the header has already been written).")
parser.add_argument('-s', '--interval', action="store", type=float,
help="time to sleep between failed reads. Requires -f.")
parser.add_argument('-t', '--timeout', action="store", type=float,
help="timeout to terminate when no changes are detected. "
"Requires -f.")
args = parser.parse_args()
d = labcomm.Decoder(Reader(args.elc))
seen = {}
......@@ -112,7 +126,10 @@ def main():
# Do another pass to extract the data.
current = {}
reader = FollowingReader(args.elc) if args.follow else Reader(args.elc)
if args.follow:
reader = FollowingReader(args.elc, args.interval, args.timeout)
reader = Reader(args.elc)
d = labcomm.Decoder(reader)
while True:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment