logger: Simplify history loading, fixes mypy errors.

This commit is contained in:
Emmanuel Gil Peyrot 2018-08-15 13:50:18 +02:00
parent b6e23355f1
commit cccb1d9759

View file

@ -56,7 +56,7 @@ class LogMessage(LogItem):
self.nick = nick self.nick = nick
def parse_log_line(msg): def parse_log_line(msg: str) -> Optional[LogItem]:
match = re.match(MESSAGE_LOG_RE, msg) match = re.match(MESSAGE_LOG_RE, msg)
if match: if match:
return LogMessage(*match.groups()) return LogMessage(*match.groups())
@ -328,23 +328,22 @@ def parse_log_lines(lines: List[str]) -> List[Dict[str, Any]]:
if not isinstance(log_item, LogItem): if not isinstance(log_item, LogItem):
log.debug('wrong log format? %s', log_item) log.debug('wrong log format? %s', log_item)
continue continue
message_lines = []
message = { message = {
'lines': [],
'history': True, 'history': True,
'time': common.get_local_time(log_item.time) 'time': common.get_local_time(log_item.time)
} }
size = log_item.nb_lines size = log_item.nb_lines
if isinstance(log_item, LogInfo): if isinstance(log_item, LogInfo):
message['lines'].append(color + log_item.text) message_lines.append(color + log_item.text)
elif isinstance(log_item, LogMessage): elif isinstance(log_item, LogMessage):
message['nickname'] = log_item.nick message['nickname'] = log_item.nick
message['lines'].append(color + log_item.text) message_lines.append(color + log_item.text)
while size != 0 and idx < len(lines): while size != 0 and idx < len(lines):
message['lines'].append(lines[idx][1:]) message_lines.append(lines[idx][1:])
size -= 1 size -= 1
idx += 1 idx += 1
message['txt'] = '\n'.join(message['lines']) message['txt'] = '\n'.join(message_lines)
del message['lines']
messages.append(message) messages.append(message)
return messages return messages