util: report git version info as a dict
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
b89a049fdb
commit
a3eebab4f2
|
@ -343,12 +343,14 @@ def main():
|
||||||
else:
|
else:
|
||||||
logging.getLogger().setLevel(debuglevel)
|
logging.getLogger().setLevel(debuglevel)
|
||||||
logging.info("Starting Klippy...")
|
logging.info("Starting Klippy...")
|
||||||
git_vers, git_status, repo_info = util.get_git_version()
|
git_info = util.get_git_version()
|
||||||
extra_files = [fname for code, fname in git_status
|
git_vers = git_info["version"]
|
||||||
|
extra_files = [fname for code, fname in git_info["file_status"]
|
||||||
if (code in ('??', '!!') and fname.endswith('.py')
|
if (code in ('??', '!!') and fname.endswith('.py')
|
||||||
and (fname.startswith('klippy/kinematics/')
|
and (fname.startswith('klippy/kinematics/')
|
||||||
or fname.startswith('klippy/extras/')))]
|
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 = ""
|
extra_git_desc = ""
|
||||||
if extra_files:
|
if extra_files:
|
||||||
if not git_vers.endswith('-dirty'):
|
if not git_vers.endswith('-dirty'):
|
||||||
|
@ -360,10 +362,9 @@ def main():
|
||||||
if len(modified_files) > 10:
|
if len(modified_files) > 10:
|
||||||
modified_files[10:] = ["(+%d files)" % (len(modified_files) - 10,)]
|
modified_files[10:] = ["(+%d files)" % (len(modified_files) - 10,)]
|
||||||
extra_git_desc += "\nModified files: %s" % (', '.join(modified_files),)
|
extra_git_desc += "\nModified files: %s" % (', '.join(modified_files),)
|
||||||
if repo_info:
|
extra_git_desc += "\nBranch: %s" % (git_info["branch"])
|
||||||
extra_git_desc += "\nBranch: %s" % (repo_info["branch"])
|
extra_git_desc += "\nRemote: %s" % (git_info["remote"])
|
||||||
extra_git_desc += "\nRemote: %s" % (repo_info["remote"])
|
extra_git_desc += "\nTracked URL: %s" % (git_info["url"])
|
||||||
extra_git_desc += "\nTracked URL: %s" % (repo_info["url"])
|
|
||||||
start_args['software_version'] = git_vers
|
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:
|
||||||
|
|
|
@ -183,6 +183,13 @@ def _get_repo_info(gitdir):
|
||||||
return repo_info
|
return repo_info
|
||||||
|
|
||||||
def get_git_version(from_file=True):
|
def get_git_version(from_file=True):
|
||||||
|
git_info = {
|
||||||
|
"version": "?",
|
||||||
|
"file_status": [],
|
||||||
|
"branch": "?",
|
||||||
|
"remote": "?",
|
||||||
|
"url": "?"
|
||||||
|
}
|
||||||
klippy_src = os.path.dirname(__file__)
|
klippy_src = os.path.dirname(__file__)
|
||||||
|
|
||||||
# Obtain version info from "git" program
|
# Obtain version info from "git" program
|
||||||
|
@ -196,6 +203,7 @@ def get_git_version(from_file=True):
|
||||||
ver, err = process.communicate()
|
ver, err = process.communicate()
|
||||||
retcode = process.wait()
|
retcode = process.wait()
|
||||||
if retcode == 0:
|
if retcode == 0:
|
||||||
|
git_info["version"] = str(ver.strip().decode())
|
||||||
process = subprocess.Popen(prog_status, stdout=subprocess.PIPE,
|
process = subprocess.Popen(prog_status, stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
stat, err = process.communicate()
|
stat, err = process.communicate()
|
||||||
|
@ -203,15 +211,16 @@ def get_git_version(from_file=True):
|
||||||
for l in str(stat.strip().decode()).split('\n')]
|
for l in str(stat.strip().decode()).split('\n')]
|
||||||
retcode = process.wait()
|
retcode = process.wait()
|
||||||
if retcode == 0:
|
if retcode == 0:
|
||||||
repo_info = _get_repo_info(gitdir)
|
git_info["file_status"] = status
|
||||||
return (str(ver.strip().decode()), status, repo_info)
|
|
||||||
else:
|
else:
|
||||||
logging.debug("Error getting git status: %s", err)
|
logging.debug("Error getting git status: %s", err)
|
||||||
|
git_info.update(_get_repo_info(gitdir))
|
||||||
|
return git_info
|
||||||
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), [], {})
|
git_info["version"] = get_version_from_file(klippy_src)
|
||||||
return ("?", [], {})
|
return git_info
|
||||||
|
|
|
@ -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)[0],
|
print(util.get_git_version(from_file=False)["version"],
|
||||||
args.distroname.replace(' ', ''), sep='-')
|
args.distroname.replace(' ', ''), sep='-')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue