Skip to content

Commit b699cc6

Browse files
authored
Add analysis field to the recording
1 parent 8916588 commit b699cc6

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/microlog/models.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def __init__(self) -> None:
5959
self.calls: list[Call] = []
6060
self.markers: list[Marker] = []
6161
self.statuses: list[Status] = []
62+
self.analysis: str = ""
63+
64+
def __setstate__(self, state: dict[str, Any]) -> None:
65+
"""Handle unpickling of old Recording objects for backward compatibility."""
66+
if not 'analysis' in state:
67+
state['analysis'] = ""
68+
self.__dict__.update(state)
6269

6370
def show_details(self, identifier: str) -> None:
6471
"""Print details about the recording, including a link to view it."""
@@ -104,15 +111,16 @@ def get_log_path(self, identifier: str) -> str:
104111
path = os.path.join(config.S3_ROOT, identifier.replace(" ", "_"))
105112
return f"{path}.zip"
106113

107-
def save(self) -> None:
114+
def save(self, name:str="") -> None:
108115
"""Save the recording to a compressed file and notify the server."""
109116
# local import because pyscript only supports pure python modules
110117
import zstd # pylint: disable=import-outside-toplevel
111118

112-
identifier = self.get_identifier()
119+
identifier = name or self.get_identifier()
113120
pickled_data = pickle.dumps(self)
114121
compressed_data = zstd.compress(pickled_data) # pylint: disable=c-extension-no-member
115122
path = self.get_log_path(identifier)
123+
logging.info("Saving recording %s to %s (%s KB)", identifier, path, len(compressed_data) / 1024)
116124

117125
config.fs.makedir(os.path.dirname(path), exist_ok=True)
118126
with config.fs.open(path, "wb") as file:
@@ -133,6 +141,7 @@ def load(self, pickled_data: bytes) -> None:
133141
self.calls = download.calls
134142
self.markers = download.markers
135143
self.statuses = download.statuses
144+
self.analysis = download.analysis
136145

137146
def add_status(
138147
self,

0 commit comments

Comments
 (0)