From 85a3c58c1fe05796e2608c924c856e6e4cb6fd54 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Fri, 8 Mar 2024 16:46:16 -0500 Subject: [PATCH] updated: more common helpers (#31804) update more helpers old-commit-hash: 74bf9dcdc7835f427eff132be8d32a86543a0cd4 --- selfdrive/updated/common.py | 15 +++++++++++++++ selfdrive/updated/git.py | 17 ++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/selfdrive/updated/common.py b/selfdrive/updated/common.py index c522e075d5..6847147995 100644 --- a/selfdrive/updated/common.py +++ b/selfdrive/updated/common.py @@ -86,6 +86,11 @@ def set_consistent_flag(consistent: bool) -> None: os.sync() +def get_consistent_flag() -> bool: + consistent_file = Path(os.path.join(FINALIZED, ".overlay_consistent")) + return consistent_file.is_file() + + def parse_release_notes(releases_md: str) -> str: try: r = releases_md.split('\n\n', 1)[0] # Slice latest release notes @@ -98,3 +103,13 @@ def parse_release_notes(releases_md: str) -> str: except Exception: cloudlog.exception("failed to parse release notes") return "" + + +def get_version(path) -> str: + with open(os.path.join(path, "common", "version.h")) as f: + return f.read().split('"')[1] + + +def get_release_notes(path) -> str: + with open(os.path.join(path, "RELEASES.md"), "r") as f: + return parse_release_notes(f.read()) diff --git a/selfdrive/updated/git.py b/selfdrive/updated/git.py index 29f95eeeff..921b32ede2 100644 --- a/selfdrive/updated/git.py +++ b/selfdrive/updated/git.py @@ -12,7 +12,8 @@ from typing import List from openpilot.common.basedir import BASEDIR from openpilot.common.params import Params from openpilot.common.swaglog import cloudlog -from openpilot.selfdrive.updated.common import FINALIZED, STAGING_ROOT, UpdateStrategy, parse_release_notes, set_consistent_flag, run +from openpilot.selfdrive.updated.common import FINALIZED, STAGING_ROOT, UpdateStrategy, \ + get_consistent_flag, get_release_notes, get_version, set_consistent_flag, run OVERLAY_UPPER = os.path.join(STAGING_ROOT, "upper") @@ -127,8 +128,7 @@ class GitUpdateStrategy(UpdateStrategy): return list(self.branches.keys()) def update_ready(self) -> bool: - consistent_file = Path(os.path.join(FINALIZED, ".overlay_consistent")) - if consistent_file.is_file(): + if get_consistent_flag(): hash_mismatch = self.get_commit_hash(BASEDIR) != self.branches[self.target_channel] branch_mismatch = self.get_branch(BASEDIR) != self.target_channel on_target_channel = self.get_branch(FINALIZED) == self.target_channel @@ -165,8 +165,7 @@ class GitUpdateStrategy(UpdateStrategy): try: branch = self.get_branch(basedir) commit = self.get_commit_hash(basedir)[:7] - with open(os.path.join(basedir, "common", "version.h")) as f: - version = f.read().split('"')[1] + version = get_version(basedir) commit_unix_ts = run(["git", "show", "-s", "--format=%ct", "HEAD"], basedir).rstrip() dt = datetime.datetime.fromtimestamp(int(commit_unix_ts)) @@ -175,16 +174,12 @@ class GitUpdateStrategy(UpdateStrategy): cloudlog.exception("updater.get_description") return f"{version} / {branch} / {commit} / {commit_date}" - def release_notes_branch(self, basedir) -> str: - with open(os.path.join(basedir, "RELEASES.md"), "r") as f: - return parse_release_notes(f.read()) - def describe_current_channel(self) -> tuple[str, str]: - return self.describe_branch(BASEDIR), self.release_notes_branch(BASEDIR) + return self.describe_branch(BASEDIR), get_release_notes(BASEDIR) def describe_ready_channel(self) -> tuple[str, str]: if self.update_ready(): - return self.describe_branch(FINALIZED), self.release_notes_branch(FINALIZED) + return self.describe_branch(FINALIZED), get_release_notes(FINALIZED) return "", ""