diff --git a/dap/accumulator.py b/dap/accumulator.py index 30ecc61..0edf1d4 100644 --- a/dap/accumulator.py +++ b/dap/accumulator.py @@ -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__": diff --git a/dap/utils/__init__.py b/dap/utils/__init__.py index c195111..85850fe 100644 --- a/dap/utils/__init__.py +++ b/dap/utils/__init__.py @@ -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 diff --git a/dap/utils/filehandler.py b/dap/utils/filehandler.py new file mode 100644 index 0000000..341ea01 --- /dev/null +++ b/dap/utils/filehandler.py @@ -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() + + +