mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-24 14:22:07 +08:00
e84a0326da
* sunnypilot: MADS - Base + HKG * fix upstream conflicts * Don't miss this * Missed it * Don't initiate lane change when braking * HKG: better cluster state * HKG: only blink when disengaging lateral * HKG: Optima's icons * HKG: update vars and blink for CAN-FD * HKG: don't get stuck * obsolete * remove this for now * border color should sync * change border color * simplify things * HKG: update events * Honda: MADS * HKG: cleanup * Toyota: MADS * Revert "remove this for now" This reverts commit 76ddd435084e051ced9a343372900ced96180989. * Revert "HKG: cleanup" This reverts commit e1ab96c6f7634508b5f3820868d22f4694361622. * Toyota: use the working one * same colors * block resume press if no previous set speed * HKG: handle events better * Honda: handle events better * Toyota: handle events better * Volkswagen MQB & PQ: MADS * Subaru: MADS * FCA: MADS * add another argument for per port specifics * GM: MADS * Toyota: missed this * Mazda: MADS * Nissan: MADS * have to use this * pass events to the next * move it around * move some stuff around * cleanup * simplify and check if cruise is initialized with non PCM * don't think we need this anymore * Volkswagen: These 2 buttons don't get used * check resume available differently * check better * simplify * Mazda: missed one update check * HKG: Move carstate logic to interface * check from ret instead * cruise state enabled spam bug * check pcm * set it earlier * own cruise initialize check * fixup! own cruise initialize check * more inclusive * HKG: redundant * Honda: Move carstate logic to interface * only check cruise speed when not PCM * Toyota: Move carstate logic to interface * fixup! HKG: Move carstate logic to interface * fixup! Honda: Move carstate logic to interface * fixup! Honda: Move carstate logic to interface * Volkswagen: Move carstate logic to interface * check if cruise has ever been enabled in state machine * already exists * just one more * do not allow steering in certain situations * Subaru: Move carstate logic to interface * FCA: Move carstate logic to interface * GM: Move carstate logic to interface * Mazda: Move carstate logic to interface * Nissan: Move carstate logic to interface * HKG: move init * declare at once * cleanup variables * prevent stuck engaged * initialize for all cars * slimmer * no entry for brake press engage * Revert "no entry for brake press engage" This reverts commit 9e6e1ca5000c213017091765a0e50d2d794cebe9. * Toyota: Change the logic * Nissan: Cleanup carstate * HKG: only disengage when cruise intially not available * Revert "HKG: only disengage when cruise intially not available" This reverts commit 123cce1818ea7285cbd433524c4f0e80e7c99cb4. * allow press anytime * cancel cruise when control wants to cancel * remove some stuff * wrong one * can't do that * would this fix it?
144 lines
4.1 KiB
Python
144 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import subprocess
|
|
from typing import List, Optional
|
|
from functools import lru_cache
|
|
|
|
from common.basedir import BASEDIR
|
|
from system.swaglog import cloudlog
|
|
|
|
RELEASE_BRANCHES = ['release3-staging', 'dashcam3-staging', 'release3', 'dashcam3', 'prod-c3']
|
|
TESTED_BRANCHES = RELEASE_BRANCHES + ['devel', 'devel-staging', 'test-c3']
|
|
|
|
training_version: bytes = b"0.2.0"
|
|
terms_version: bytes = b"2"
|
|
|
|
|
|
def cache(user_function, /):
|
|
return lru_cache(maxsize=None)(user_function)
|
|
|
|
|
|
def run_cmd(cmd: List[str]) -> str:
|
|
return subprocess.check_output(cmd, encoding='utf8').strip()
|
|
|
|
|
|
def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[str]:
|
|
try:
|
|
return run_cmd(cmd)
|
|
except subprocess.CalledProcessError:
|
|
return default
|
|
|
|
|
|
@cache
|
|
def get_commit(branch: str = "HEAD", default: Optional[str] = None) -> Optional[str]:
|
|
return run_cmd_default(["git", "rev-parse", branch], default=default)
|
|
|
|
|
|
@cache
|
|
def get_short_branch(default: Optional[str] = None) -> Optional[str]:
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "HEAD"], default=default)
|
|
|
|
|
|
@cache
|
|
def get_branch(default: Optional[str] = None) -> Optional[str]:
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"], default=default)
|
|
|
|
|
|
@cache
|
|
def get_origin(default: Optional[str] = None) -> Optional[str]:
|
|
try:
|
|
local_branch = run_cmd(["git", "name-rev", "--name-only", "HEAD"])
|
|
tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"])
|
|
return run_cmd(["git", "config", "remote." + tracking_remote + ".url"])
|
|
except subprocess.CalledProcessError: # Not on a branch, fallback
|
|
return run_cmd_default(["git", "config", "--get", "remote.origin.url"], default=default)
|
|
|
|
|
|
@cache
|
|
def get_normalized_origin(default: Optional[str] = None) -> Optional[str]:
|
|
origin: Optional[str] = get_origin()
|
|
|
|
if origin is None:
|
|
return default
|
|
|
|
return origin.replace("git@", "", 1) \
|
|
.replace(".git", "", 1) \
|
|
.replace("https://", "", 1) \
|
|
.replace(":", "/", 1)
|
|
|
|
|
|
@cache
|
|
def get_version() -> str:
|
|
with open(os.path.join(BASEDIR, "common", "version.h")) as _versionf:
|
|
version = _versionf.read().split('"')[1]
|
|
return version
|
|
|
|
@cache
|
|
def get_short_version() -> str:
|
|
return get_version().split('-')[0] # type: ignore
|
|
|
|
@cache
|
|
def is_prebuilt() -> bool:
|
|
return os.path.exists(os.path.join(BASEDIR, 'prebuilt'))
|
|
|
|
|
|
@cache
|
|
def is_comma_remote() -> bool:
|
|
# note to fork maintainers, this is used for release metrics. please do not
|
|
# touch this to get rid of the orange startup alert. there's better ways to do that
|
|
origin: Optional[str] = get_origin()
|
|
if origin is None:
|
|
return False
|
|
|
|
return origin.startswith('git@github.com:sunnyhaibin') or origin.startswith('https://github.com/sunnyhaibin')
|
|
|
|
|
|
@cache
|
|
def is_tested_branch() -> bool:
|
|
return get_short_branch() in TESTED_BRANCHES
|
|
|
|
@cache
|
|
def is_release_branch() -> bool:
|
|
return get_short_branch() in RELEASE_BRANCHES
|
|
|
|
@cache
|
|
def is_dirty() -> bool:
|
|
origin = get_origin()
|
|
branch = get_branch()
|
|
if (origin is None) or (branch is None):
|
|
return True
|
|
|
|
dirty = False
|
|
try:
|
|
# Actually check dirty files
|
|
if not is_prebuilt():
|
|
# This is needed otherwise touched files might show up as modified
|
|
try:
|
|
subprocess.check_call(["git", "update-index", "--refresh"])
|
|
except subprocess.CalledProcessError:
|
|
pass
|
|
|
|
dirty = (subprocess.call(["git", "diff-index", "--quiet", branch, "--"]) != 0)
|
|
except subprocess.CalledProcessError:
|
|
cloudlog.exception("git subprocess failed while checking dirty")
|
|
dirty = True
|
|
|
|
return dirty
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from common.params import Params
|
|
|
|
params = Params()
|
|
params.put("TermsVersion", terms_version)
|
|
params.put("TrainingVersion", training_version)
|
|
|
|
print(f"Dirty: {is_dirty()}")
|
|
print(f"Version: {get_version()}")
|
|
print(f"Short version: {get_short_version()}")
|
|
print(f"Origin: {get_origin()}")
|
|
print(f"Normalized origin: {get_normalized_origin()}")
|
|
print(f"Branch: {get_branch()}")
|
|
print(f"Short branch: {get_short_branch()}")
|
|
print(f"Prebuilt: {is_prebuilt()}")
|