Commit 1e905c5f by Oleksandr Barabash

no file update

parent 3b16ace6
......@@ -7,7 +7,7 @@ import signal
import sys
from asyncio import AbstractEventLoop
from concurrent.futures import ThreadPoolExecutor
from typing import Any
from typing import Any, Optional
from absl import app, flags
from marshmallow import EXCLUDE
......@@ -44,16 +44,20 @@ class CSVLogger(PacketLogger):
BREAK_LINE = "\r\n"
def __init__(self, file_path: str):
def __init__(self, file_path: Optional[str] = None):
self.file_path = file_path
is_file_exists = os.path.exists(self.file_path)
self.file = open(self.file_path, "a+")
if not is_file_exists:
self.write("; ".join(["Station ID", "Timestamp", "Frequency",
"DoA", "Confidence", "Power", "Serial",
"Radio Bearing",
"Compass Offset"]) + self.BREAK_LINE)
self.save()
self.file = None
if file_path is not None:
self.file_path = file_path
is_file_exists = os.path.exists(self.file_path)
self.file = open(self.file_path, "a+")
if not is_file_exists:
self.write("; ".join(["Station ID", "Timestamp", "Frequency",
"DoA", "Confidence", "Power", "Serial",
"Radio Bearing",
"Compass Offset"]) + self.BREAK_LINE)
self.save()
@staticmethod
def serialize_data(data: Any) -> str:
......@@ -65,6 +69,9 @@ class CSVLogger(PacketLogger):
# noinspection PyBroadException
def write(self, data: str) -> None:
""" Try write """
if self.file is None:
return
while True:
try:
self.file.write(data)
......@@ -88,8 +95,9 @@ class CSVLogger(PacketLogger):
def save(self) -> None:
""" Save data """
self.file.flush()
self.file.close()
if self.file is not None:
self.file.flush()
self.file.close()
def init_logging(filename: str = None, level: int = None) -> None:
......
Markdown is supported
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