firmware/bin/readprops.py

43 lines
1.3 KiB
Python
Raw Normal View History

2021-04-16 03:04:03 +00:00
import configparser
import subprocess
2021-04-16 03:04:03 +00:00
def readProps(prefsLoc):
"""Read the version of our project as a string"""
config = configparser.RawConfigParser()
config.read(prefsLoc)
version = dict(config.items("VERSION"))
verObj = dict(
short="{}.{}.{}".format(version["major"], version["minor"], version["build"]),
long="unset",
)
2021-04-16 03:04:03 +00:00
# Try to find current build SHA if if the workspace is clean. This could fail if git is not installed
try:
sha = (
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
.decode("utf-8")
.strip()
)
isDirty = (
subprocess.check_output(["git", "diff", "HEAD"]).decode("utf-8").strip()
)
2021-04-16 03:04:03 +00:00
suffix = sha
2023-01-28 20:50:07 +00:00
# if isDirty:
# # short for 'dirty', we want to keep our verstrings source for protobuf reasons
# suffix = sha + "-d"
verObj["long"] = "{}.{}.{}.{}".format(
version["major"], version["minor"], version["build"], suffix
)
2021-04-16 03:04:03 +00:00
except:
# print("Unexpected error:", sys.exc_info()[0])
# traceback.print_exc()
verObj["long"] = verObj["short"]
2021-04-16 03:04:03 +00:00
2022-07-29 22:58:42 +00:00
# print("firmware version " + verStr)
2021-05-03 01:50:06 +00:00
return verObj
2021-04-16 03:04:03 +00:00
# print("path is" + ','.join(sys.path))