klippy: Report repo version as "dirty" if there are untracked python files

Check for untracked files in the klippy/extras/ and klippy/kinematics/
directories and report those files in the log.  This helps identify
code modifications when inspecting a log.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-04-26 18:24:39 -04:00
parent 3b0729c949
commit 1a24e7c5b6
3 changed files with 37 additions and 9 deletions

View File

@ -343,12 +343,30 @@ def main():
else: else:
logging.getLogger().setLevel(debuglevel) logging.getLogger().setLevel(debuglevel)
logging.info("Starting Klippy...") 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() start_args['cpu_info'] = util.get_cpu_info()
if bglogger is not None: if bglogger is not None:
versions = "\n".join([ versions = "\n".join([
"Args: %s" % (sys.argv,), "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'],), "CPU: %s" % (start_args['cpu_info'],),
"Python: %s" % (repr(sys.version),)]) "Python: %s" % (repr(sys.version),)])
logging.info(versions) logging.info(versions)

View File

@ -138,20 +138,30 @@ def get_git_version(from_file=True):
# Obtain version info from "git" program # Obtain version info from "git" program
gitdir = os.path.join(klippy_src, '..') gitdir = os.path.join(klippy_src, '..')
prog = ('git', '-C', gitdir, 'describe', '--always', prog_desc = ('git', '-C', gitdir, 'describe', '--always',
'--tags', '--long', '--dirty') '--tags', '--long', '--dirty')
prog_status = ('git', '-C', gitdir, 'status', '--porcelain', '--ignored')
try: try:
process = subprocess.Popen(prog, stdout=subprocess.PIPE, process = subprocess.Popen(prog_desc, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
ver, err = process.communicate() ver, err = process.communicate()
retcode = process.wait() retcode = process.wait()
if retcode == 0: 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: else:
logging.debug("Error getting git version: %s", err) logging.debug("Error getting git version: %s", err)
except: except:
logging.debug("Exception on run: %s", traceback.format_exc()) logging.debug("Exception on run: %s", traceback.format_exc())
if from_file: if from_file:
return get_version_from_file(klippy_src) return (get_version_from_file(klippy_src), [])
return "?" return ("?", [])

View File

@ -23,7 +23,7 @@ def main(argv):
help='Name of distro this package is intended for' help='Name of distro this package is intended for'
) )
args = p.parse_args() 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='-') args.distroname.replace(' ', ''), sep='-')