aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'klippy/util.py')
-rw-r--r--klippy/util.py57
1 files changed, 55 insertions, 2 deletions
diff --git a/klippy/util.py b/klippy/util.py
index 948ac5ee..201ff528 100644
--- a/klippy/util.py
+++ b/klippy/util.py
@@ -1,11 +1,16 @@
# Low level unix utility functions
#
-# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
+# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import sys, os, pty, fcntl, termios, signal, logging
+import sys, os, pty, fcntl, termios, signal, logging, json, time
import subprocess, traceback, shlex
+
+######################################################################
+# Low-level Unix commands
+######################################################################
+
# Return the SIGINT interrupt handler back to the OS default
def fix_sigint():
signal.signal(signal.SIGINT, signal.SIG_DFL)
@@ -41,6 +46,54 @@ def create_pty(ptyname):
termios.tcsetattr(mfd, termios.TCSADRAIN, old)
return mfd
+
+######################################################################
+# Helper code for extracting mcu build info
+######################################################################
+
+def dump_file_stats(build_dir, filename):
+ fname = os.path.join(build_dir, filename)
+ try:
+ mtime = os.path.getmtime(fname)
+ fsize = os.path.getsize(fname)
+ timestr = time.asctime(time.localtime(mtime))
+ logging.info("Build file %s(%d): %s", fname, fsize, timestr)
+ except:
+ logging.info("No build file %s", fname)
+
+# Try to log information on the last mcu build
+def dump_mcu_build():
+ build_dir = os.path.join(os.path.dirname(__file__), '..')
+ # Try to log last mcu config
+ dump_file_stats(build_dir, '.config')
+ try:
+ f = open(os.path.join(build_dir, '.config'), 'rb')
+ data = f.read(32*1024)
+ f.close()
+ logging.info("========= Last MCU build config =========\n%s"
+ "=======================", data)
+ except:
+ pass
+ # Try to log last mcu build version
+ dump_file_stats(build_dir, 'out/klipper.dict')
+ try:
+ f = open(os.path.join(build_dir, 'out/klipper.dict'), 'rb')
+ data = f.read(32*1024)
+ f.close()
+ data = json.loads(data)
+ logging.info("Last MCU build version: %s", data.get('version', ''))
+ logging.info("Last MCU build tools: %s", data.get('build_versions', ''))
+ cparts = ["%s=%s" % (k, v) for k, v in data.get('config', {}).items()]
+ logging.info("Last MCU build config: %s", " ".join(cparts))
+ except:
+ pass
+ dump_file_stats(build_dir, 'out/klipper.elf')
+
+
+######################################################################
+# General system and software information
+######################################################################
+
def get_cpu_info():
try:
f = open('/proc/cpuinfo', 'rb')