Skip to content

Commit

Permalink
add report file decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Helveg committed Oct 6, 2023
1 parent 1290701 commit c1831ef
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bsb/reporting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from os import PathLike

from .services import MPI
from . import exceptions as _exc
import functools
Expand Down Expand Up @@ -59,6 +61,12 @@ def get_report_file():
return _report_file


def read_report_file(file: PathLike):
with open(file, "r") as f:
print(f)
return _decode(f.read())


def report(*message, level=2, ongoing=False, token=None, nodes=None, all_nodes=False):
"""
Send a message to the appropriate output channel.
Expand Down Expand Up @@ -108,6 +116,24 @@ def _encode(header, message):
return _preamble + header + _preamble_bar + message + _preamble


def _decode(payload: str):
pos = -1
plen = len(_preamble)
reading = False
log = []
while (npos := payload.find(_preamble, pos + 1)) != -1:
if reading:
header, message = payload[pos + plen : npos].split(_preamble_bar)
header = base64.b64decode(header).decode("UTF-8")
message = base64.b64decode(message).decode("UTF-8")
if header:
message = f"[header: {header}] {message}"
log.append(message)
reading = not reading
pos = npos
return "\n".join(log)


def setup_reporting():
warnings.formatwarning = warning_on_one_line
# Don't touch stdout if we're in IPython
Expand Down

0 comments on commit c1831ef

Please sign in to comment.