From add528532e3c1a5604d512d8411d2b454d7c8da1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 12 Dec 2017 15:51:50 -0500 Subject: logextract: Rename extractconfig.py to logextract.py and add shutdown parsing Add initial support for extracting out shutdown information from a klippy.log file. The shutdown dump will be reordered into the sequence that they occurred, and timestamps/sequence numbers in the mcu message dump will be expanded. Signed-off-by: Kevin O'Connor --- scripts/logextract.py | 259 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100755 scripts/logextract.py (limited to 'scripts/logextract.py') diff --git a/scripts/logextract.py b/scripts/logextract.py new file mode 100755 index 00000000..0fb9dcca --- /dev/null +++ b/scripts/logextract.py @@ -0,0 +1,259 @@ +#!/usr/bin/env python2 +# Script to extract a config file from a log +# +# Copyright (C) 2017 Kevin O'Connor +# +# This file may be distributed under the terms of the GNU GPLv3 license. +import sys, re, collections + +def format_comment(line_num, line): + return "# %6d: %s" % (line_num, line) + + +###################################################################### +# Config file extraction +###################################################################### + +class GatherConfig: + def __init__(self, configs, line_num, recent_lines, logname): + self.configs = configs + self.line_num = line_num + self.config_num = len(configs) + 1 + self.filename = "%s.config%04d.cfg" % (logname, self.config_num) + self.config_lines = [] + self.comments = [] + def add_line(self, line_num, line): + if line != '=======================': + self.config_lines.append(line) + return True + self.finalize() + return False + def finalize(self): + lines = tuple(self.config_lines) + ch = self.configs.get(lines) + if ch is None: + self.configs[lines] = ch = self + else: + ch.comments.extend(self.comments) + ch.comments.append(format_comment(self.line_num, "config file")) + def add_comment(self, comment): + if comment is not None: + self.comments.append(comment) + def write_file(self): + f = open(self.filename, 'wb') + f.write('\n'.join(self.comments + self.config_lines)) + f.close() + + +###################################################################### +# Shutdown extraction +###################################################################### + +stats_seq_s = r" send_seq=(?P[0-9]+) receive_seq=(?P[0-9]+) " +count_s = r"(?P[0-9]+)" +time_s = r"(?P