From 451ffd567d3a2b4871229681ec0449b87cc519f5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 24 Dec 2016 10:07:02 -0500 Subject: [PATCH] klippy: Log the host software git version at startup Signed-off-by: Kevin O'Connor --- klippy/klippy.py | 2 ++ klippy/util.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/klippy/klippy.py b/klippy/klippy.py index e7e9fed6..7c1b7618 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -250,6 +250,8 @@ def main(): else: logging.basicConfig(level=debuglevel) logging.info("Starting Klippy...") + if debugoutput is None: + util.report_git_version() # Start firmware while 1: diff --git a/klippy/util.py b/klippy/util.py index 6bbfd9af..9daf75cd 100644 --- a/klippy/util.py +++ b/klippy/util.py @@ -3,8 +3,7 @@ # Copyright (C) 2016 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. - -import os, pty, fcntl, termios, signal +import os, pty, fcntl, termios, signal, logging, subprocess, traceback, shlex # Return the SIGINT interrupt handler back to the OS default def fix_sigint(): @@ -36,3 +35,19 @@ def create_pty(ptyname): old[3] = old[3] & ~termios.ECHO termios.tcsetattr(mfd, termios.TCSADRAIN, old) return mfd + +def report_git_version(): + # Obtain version info from "git" program + if not os.path.exists('.git'): + logging.debug("No '.git' file/directory found") + return + prog = "git describe --tags --long --dirty" + try: + process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE) + output = process.communicate()[0] + retcode = process.poll() + except OSError: + logging.debug("Exception on run: %s" % (traceback.format_exc(),)) + return + ver = output.strip() + logging.info("Git version: %s" % (repr(ver),))