Implement detailed state updates in updater process

Added multiple Params.put() calls throughout the updater process to provide detailed status updates. This includes stages like setting git options, copying update files, performing git cleanup, and checking current branches and commits. These changes improve transparency and tracking of the update process.
This commit is contained in:
DevTekVE
2024-08-03 13:05:38 +02:00
parent bdb733ddc9
commit 2ed5c92830
+21 -8
View File
@@ -33,6 +33,7 @@ OVERLAY_INIT = Path(os.path.join(BASEDIR, ".overlay_init"))
DAYS_NO_CONNECTIVITY_MAX = 14 # do not allow to engage after this many days
DAYS_NO_CONNECTIVITY_PROMPT = 10 # send an offroad prompt after this many days
params = Params()
class UserRequest:
NONE = 0
@@ -119,6 +120,7 @@ def setup_git_options(cwd: str) -> None:
]
for option, value in git_cfg:
run(["git", "config", option, value], cwd)
params.put("UpdaterState", "Setting git options...")
def dismount_overlay() -> None:
@@ -141,7 +143,6 @@ def init_overlay() -> None:
cloudlog.info("preparing new safe staging area")
params = Params()
params.put_bool("UpdateAvailable", False)
set_consistent_flag(False)
dismount_overlay()
@@ -186,6 +187,7 @@ def finalize_update() -> None:
set_consistent_flag(False)
# Copy the merged overlay view and set the update ready flag
params.put("UpdaterState", "Copying the update to the finalized location...")
if os.path.exists(FINALIZED):
shutil.rmtree(FINALIZED)
shutil.copytree(OVERLAY_MERGED, FINALIZED, symlinks=True)
@@ -193,9 +195,11 @@ def finalize_update() -> None:
run(["git", "reset", "--hard"], FINALIZED)
run(["git", "submodule", "foreach", "--recursive", "git", "reset", "--hard"], FINALIZED)
params.put("UpdaterState", "Ensuring submodules are up-to-date...")
cloudlog.info("Starting git cleanup in finalized update")
t = time.monotonic()
try:
params.put("UpdaterState", "Doing git cleanup...")
run(["git", "gc"], FINALIZED)
run(["git", "lfs", "prune"], FINALIZED)
cloudlog.event("Done git cleanup", duration=time.monotonic() - t)
@@ -204,6 +208,7 @@ def finalize_update() -> None:
set_consistent_flag(True)
cloudlog.info("done finalizing overlay")
params.put("UpdaterState", "Finalizing update...")
def handle_agnos_update() -> None:
@@ -266,9 +271,11 @@ class Updater:
return False
def get_branch(self, path: str) -> str:
params.put("UpdaterState", "Checking current branch...")
return run(["git", "rev-parse", "--abbrev-ref", "HEAD"], path).rstrip()
def get_commit_hash(self, path: str = OVERLAY_MERGED) -> str:
params.put("UpdaterState", "Checking current commit...")
return run(["git", "rev-parse", "HEAD"], path).rstrip()
def set_params(self, update_success: bool, failed_count: int, exception: str | None) -> None:
@@ -351,6 +358,7 @@ class Updater:
self._has_internet = False
setup_git_options(OVERLAY_MERGED)
params.put("UpdaterState", "Discovering branches...")
output = run(["git", "ls-remote", "--heads"], OVERLAY_MERGED)
self.branches = defaultdict(lambda: None)
@@ -365,14 +373,16 @@ class Updater:
new_branch = self.target_branch
new_commit = self.branches[new_branch]
if (cur_branch, cur_commit) != (new_branch, new_commit):
cloudlog.info(f"update available, {cur_branch} ({str(cur_commit)[:7]}) -> {new_branch} ({str(new_commit)[:7]})")
upd_msg = f"update available, {cur_branch} ({str(cur_commit)[:7]}) -> {new_branch} ({str(new_commit)[:7]})"
params.put("UpdaterState", upd_msg)
cloudlog.info(upd_msg)
else:
cloudlog.info(f"up to date on {cur_branch} ({str(cur_commit)[:7]})")
def fetch_update(self) -> None:
cloudlog.info("attempting git fetch inside staging overlay")
self.params.put("UpdaterState", "downloading...")
self.params.put("UpdaterState", "downloading... Please, wait.")
# TODO: cleanly interrupt this and invalidate old update
set_consistent_flag(False)
@@ -382,9 +392,13 @@ class Updater:
branch = self.target_branch
git_fetch_output = run(["git", "fetch", "origin", branch], OVERLAY_MERGED)
cloudlog.info("git fetch success: %s", git_fetch_output)
upd_msg = f"git fetch success: {git_fetch_output}"
self.params.put("UpdaterState", upd_msg)
cloudlog.info(upd_msg)
cloudlog.info("git reset in progress")
upd_msg = "git reset in progress"
self.params.put("UpdaterState", upd_msg)
cloudlog.info(upd_msg)
cmds = [
["git", "checkout", "--force", "--no-recurse-submodules", "-B", branch, "FETCH_HEAD"],
["git", "reset", "--hard"],
@@ -394,7 +408,8 @@ class Updater:
["git", "submodule", "foreach", "--recursive", "git", "reset", "--hard"],
]
r = [run(cmd, OVERLAY_MERGED) for cmd in cmds]
cloudlog.info("git reset success: %s", '\n'.join(r))
self.params.put("UpdaterState", "git reset success...")
cloudlog.info(f"git reset success: %s", '\n'.join(r))
# TODO: show agnos download progress
if AGNOS:
@@ -407,8 +422,6 @@ class Updater:
def main() -> None:
params = Params()
if params.get_bool("DisableUpdates"):
cloudlog.warning("updates are disabled by the DisableUpdates param")
exit(0)