moved FileHandler into utils
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import zmq
|
||||
|
||||
from utils import FileHandler
|
||||
|
||||
|
||||
FLAGS = 0
|
||||
OUTPUT_DIR_NAME = "/gpfs/photonics/swissfel/buffer/dap/data"
|
||||
@@ -64,30 +65,6 @@ def accumulate(_accumulator_host, accumulator_port): #TODO: accumulator_host is
|
||||
|
||||
|
||||
|
||||
class FileHandler:
|
||||
|
||||
def __init__(self):
|
||||
self.file = None
|
||||
|
||||
def switch(self, fname):
|
||||
self.close()
|
||||
self.open(fname)
|
||||
|
||||
def open(self, fname):
|
||||
dname = os.path.dirname(fname)
|
||||
os.makedirs(dname, exist_ok=True)
|
||||
self.file = open(fname, "a")
|
||||
|
||||
def close(self):
|
||||
if self.file:
|
||||
self.file.close()
|
||||
|
||||
def flush(self):
|
||||
if self.file:
|
||||
self.file.flush()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
from .aggregator import Aggregator
|
||||
from .bits import read_bit
|
||||
from .bufjson import BufferedJSON
|
||||
from .filehandler import FileHandler
|
||||
from .randskip import randskip
|
||||
|
||||
|
||||
|
||||
27
dap/utils/filehandler.py
Normal file
27
dap/utils/filehandler.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
|
||||
|
||||
class FileHandler:
|
||||
|
||||
def __init__(self):
|
||||
self.file = None
|
||||
|
||||
def switch(self, fname):
|
||||
self.close()
|
||||
self.open(fname)
|
||||
|
||||
def open(self, fname):
|
||||
dname = os.path.dirname(fname)
|
||||
os.makedirs(dname, exist_ok=True)
|
||||
self.file = open(fname, "a")
|
||||
|
||||
def close(self):
|
||||
if self.file:
|
||||
self.file.close()
|
||||
|
||||
def flush(self):
|
||||
if self.file:
|
||||
self.file.flush()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user