util: report git version info as a dict

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-05-03 06:05:37 -04:00 committed by KevinOConnor
parent b89a049fdb
commit a3eebab4f2
3 changed files with 22 additions and 12 deletions

View File

@ -343,12 +343,14 @@ def main():
else:
logging.getLogger().setLevel(debuglevel)
logging.info("Starting Klippy...")
git_vers, git_status, repo_info = util.get_git_version()
extra_files = [fname for code, fname in git_status
git_info = util.get_git_version()
git_vers = git_info["version"]
extra_files = [fname for code, fname in git_info["file_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']
modified_files = [fname for code, fname in git_info["file_status"]
if code == 'M']
extra_git_desc = ""
if extra_files:
if not git_vers.endswith('-dirty'):
@ -360,10 +362,9 @@ def main():
if len(modified_files) > 10:
modified_files[10:] = ["(+%d files)" % (len(modified_files) - 10,)]
extra_git_desc += "\nModified files: %s" % (', '.join(modified_files),)
if repo_info:
extra_git_desc += "\nBranch: %s" % (repo_info["branch"])
extra_git_desc += "\nRemote: %s" % (repo_info["remote"])
extra_git_desc += "\nTracked URL: %s" % (repo_info["url"])
extra_git_desc += "\nBranch: %s" % (git_info["branch"])
extra_git_desc += "\nRemote: %s" % (git_info["remote"])
extra_git_desc += "\nTracked URL: %s" % (git_info["url"])
start_args['software_version'] = git_vers
start_args['cpu_info'] = util.get_cpu_info()
if bglogger is not None:

View File

@ -183,6 +183,13 @@ def _get_repo_info(gitdir):
return repo_info
def get_git_version(from_file=True):
git_info = {
"version": "?",
"file_status": [],
"branch": "?",
"remote": "?",
"url": "?"
}
klippy_src = os.path.dirname(__file__)
# Obtain version info from "git" program
@ -196,6 +203,7 @@ def get_git_version(from_file=True):
ver, err = process.communicate()
retcode = process.wait()
if retcode == 0:
git_info["version"] = str(ver.strip().decode())
process = subprocess.Popen(prog_status, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stat, err = process.communicate()
@ -203,15 +211,16 @@ def get_git_version(from_file=True):
for l in str(stat.strip().decode()).split('\n')]
retcode = process.wait()
if retcode == 0:
repo_info = _get_repo_info(gitdir)
return (str(ver.strip().decode()), status, repo_info)
git_info["file_status"] = status
else:
logging.debug("Error getting git status: %s", err)
git_info.update(_get_repo_info(gitdir))
return git_info
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 ("?", [], {})
git_info["version"] = get_version_from_file(klippy_src)
return git_info

View File

@ -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)[0],
print(util.get_git_version(from_file=False)["version"],
args.distroname.replace(' ', ''), sep='-')