aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-12-06 21:23:24 -0500
committerKevin O'Connor <kevin@koconnor.net>2017-12-06 21:23:24 -0500
commitef09ac5a7fdc1de4529aefca21498fcf0d144c9d (patch)
treebf93bb4f45b157a4b4e9998560e3d2bc73200dde /scripts
parentf6d4284d5ccc7e3041ab3d89a0a9244edcd157b9 (diff)
downloadkutter-ef09ac5a7fdc1de4529aefca21498fcf0d144c9d.tar.gz
kutter-ef09ac5a7fdc1de4529aefca21498fcf0d144c9d.tar.xz
kutter-ef09ac5a7fdc1de4529aefca21498fcf0d144c9d.zip
extractconfig: Add helper script that extracts config files from a log
Add a helper script that can read a klippy.log file and extract the printer.cfg files from it. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/extractconfig.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/extractconfig.py b/scripts/extractconfig.py
new file mode 100755
index 00000000..b50afc51
--- /dev/null
+++ b/scripts/extractconfig.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python2
+# Script to extract a config file from a log
+#
+# Copyright (C) 2017 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+import sys
+
+def format_comment(line_num, line):
+ return "# %6d: %s" % (line_num, line)
+
+def main():
+ logname = sys.argv[1]
+ f = open(logname, 'rb')
+ last_git = last_start = ''
+ config_count = config_line_num = 0
+ configs = {}
+ config_lines = []
+ info = None
+ # Parse log file
+ for line_num, line in enumerate(f):
+ line = line.strip()
+ line_num += 1
+ if config_line_num:
+ if line == '=======================':
+ lines = tuple(config_lines)
+ info = configs.get(lines)
+ if info is None:
+ config_count += 1
+ configs[lines] = info = (config_count, [])
+ info[1].append(format_comment(config_line_num, "config file"))
+ if last_git:
+ info[1].append(last_git)
+ if last_start:
+ info[1].append(last_start)
+ config_line_num = 0
+ config_lines = []
+ else:
+ config_lines.append(line)
+ elif line.startswith('Git version'):
+ last_git = format_comment(line_num, line)
+ elif line.startswith('Start printer at'):
+ last_start = format_comment(line_num, line)
+ elif line == '===== Config file =====':
+ config_line_num = line_num
+ elif info is not None and (
+ ' shutdown: ' in line or line.startswith('Dumping ')):
+ info[1].append(format_comment(line_num, line))
+ # Write found config files
+ for lines, (count, comments) in configs.items():
+ f = open("%s.config%04d.cfg" % (logname, count), 'wb')
+ f.write('\n'.join(tuple(comments) + lines))
+ f.close()
+
+if __name__ == '__main__':
+ main()