updated: more common helpers (#31804)

update more helpers
old-commit-hash: 74bf9dcdc7
chrysler-long2
Justin Newberry 1 year ago committed by GitHub
parent 294e055d8b
commit 85a3c58c1f
  1. 15
      selfdrive/updated/common.py
  2. 17
      selfdrive/updated/git.py

@ -86,6 +86,11 @@ def set_consistent_flag(consistent: bool) -> None:
os.sync() 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: def parse_release_notes(releases_md: str) -> str:
try: try:
r = releases_md.split('\n\n', 1)[0] # Slice latest release notes 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: except Exception:
cloudlog.exception("failed to parse release notes") cloudlog.exception("failed to parse release notes")
return "" 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())

@ -12,7 +12,8 @@ from typing import List
from openpilot.common.basedir import BASEDIR from openpilot.common.basedir import BASEDIR
from openpilot.common.params import Params from openpilot.common.params import Params
from openpilot.common.swaglog import cloudlog 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") OVERLAY_UPPER = os.path.join(STAGING_ROOT, "upper")
@ -127,8 +128,7 @@ class GitUpdateStrategy(UpdateStrategy):
return list(self.branches.keys()) return list(self.branches.keys())
def update_ready(self) -> bool: def update_ready(self) -> bool:
consistent_file = Path(os.path.join(FINALIZED, ".overlay_consistent")) if get_consistent_flag():
if consistent_file.is_file():
hash_mismatch = self.get_commit_hash(BASEDIR) != self.branches[self.target_channel] hash_mismatch = self.get_commit_hash(BASEDIR) != self.branches[self.target_channel]
branch_mismatch = self.get_branch(BASEDIR) != self.target_channel branch_mismatch = self.get_branch(BASEDIR) != self.target_channel
on_target_channel = self.get_branch(FINALIZED) == self.target_channel on_target_channel = self.get_branch(FINALIZED) == self.target_channel
@ -165,8 +165,7 @@ class GitUpdateStrategy(UpdateStrategy):
try: try:
branch = self.get_branch(basedir) branch = self.get_branch(basedir)
commit = self.get_commit_hash(basedir)[:7] commit = self.get_commit_hash(basedir)[:7]
with open(os.path.join(basedir, "common", "version.h")) as f: version = get_version(basedir)
version = f.read().split('"')[1]
commit_unix_ts = run(["git", "show", "-s", "--format=%ct", "HEAD"], basedir).rstrip() commit_unix_ts = run(["git", "show", "-s", "--format=%ct", "HEAD"], basedir).rstrip()
dt = datetime.datetime.fromtimestamp(int(commit_unix_ts)) dt = datetime.datetime.fromtimestamp(int(commit_unix_ts))
@ -175,16 +174,12 @@ class GitUpdateStrategy(UpdateStrategy):
cloudlog.exception("updater.get_description") cloudlog.exception("updater.get_description")
return f"{version} / {branch} / {commit} / {commit_date}" 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]: 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]: def describe_ready_channel(self) -> tuple[str, str]:
if self.update_ready(): if self.update_ready():
return self.describe_branch(FINALIZED), self.release_notes_branch(FINALIZED) return self.describe_branch(FINALIZED), get_release_notes(FINALIZED)
return "", "" return "", ""

Loading…
Cancel
Save