diff --git a/klippy/klippy.py b/klippy/klippy.py index 8f2caf3b..d94612cf 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -343,12 +343,30 @@ def main(): else: logging.getLogger().setLevel(debuglevel) logging.info("Starting Klippy...") - start_args['software_version'] = util.get_git_version() + git_vers, git_status = util.get_git_version() + extra_files = [fname for code, fname in git_status + if (code in ('??', '!!') and fname.endswith('.py') + and (fname.startswith('klippy/kinematics/') + or fname.startswith('klippy/extras/')))] + modified_files = [fname for code, fname in git_status if code == 'M'] + extra_git_desc = "" + if extra_files: + if not git_vers.endswith('-dirty'): + git_vers = git_vers + '-dirty' + if len(extra_files) > 10: + extra_files[10:] = ["(+%d files)" % (len(extra_files) - 10,)] + extra_git_desc += "\nUntracked files: %s" % (', '.join(extra_files),) + if modified_files: + if len(modified_files) > 10: + modified_files[10:] = ["(+%d files)" % (len(modified_files) - 10,)] + extra_git_desc += "\nModified files: %s" % (', '.join(modified_files),) + start_args['software_version'] = git_vers start_args['cpu_info'] = util.get_cpu_info() if bglogger is not None: versions = "\n".join([ "Args: %s" % (sys.argv,), - "Git version: %s" % (repr(start_args['software_version']),), + "Git version: %s%s" % (repr(start_args['software_version']), + extra_git_desc), "CPU: %s" % (start_args['cpu_info'],), "Python: %s" % (repr(sys.version),)]) logging.info(versions) diff --git a/klippy/util.py b/klippy/util.py index c21ace28..ffea918c 100644 --- a/klippy/util.py +++ b/klippy/util.py @@ -138,20 +138,30 @@ def get_git_version(from_file=True): # Obtain version info from "git" program gitdir = os.path.join(klippy_src, '..') - prog = ('git', '-C', gitdir, 'describe', '--always', - '--tags', '--long', '--dirty') + prog_desc = ('git', '-C', gitdir, 'describe', '--always', + '--tags', '--long', '--dirty') + prog_status = ('git', '-C', gitdir, 'status', '--porcelain', '--ignored') try: - process = subprocess.Popen(prog, stdout=subprocess.PIPE, + process = subprocess.Popen(prog_desc, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ver, err = process.communicate() retcode = process.wait() if retcode == 0: - return str(ver.strip().decode()) + process = subprocess.Popen(prog_status, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stat, err = process.communicate() + status = [l.split(None, 1) + for l in str(stat.strip().decode()).split('\n')] + retcode = process.wait() + if retcode == 0: + return (str(ver.strip().decode()), status) + else: + logging.debug("Error getting git status: %s", err) else: logging.debug("Error getting git version: %s", err) except: logging.debug("Exception on run: %s", traceback.format_exc()) if from_file: - return get_version_from_file(klippy_src) - return "?" + return (get_version_from_file(klippy_src), []) + return ("?", []) diff --git a/scripts/make_version.py b/scripts/make_version.py index 47422500..ea8b0546 100644 --- a/scripts/make_version.py +++ b/scripts/make_version.py @@ -23,7 +23,7 @@ def main(argv): help='Name of distro this package is intended for' ) args = p.parse_args() - print(util.get_git_version(from_file=False), + print(util.get_git_version(from_file=False)[0], args.distroname.replace(' ', ''), sep='-')