update_manager: introduce anomalies field

This allows Moonraker to report anomalies detected in an updater
that won't prevent an update.  Front ends may decide to present
these to users in a more subtle fashion so they know the state of
the repo without being concerned of an issue.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-07-24 16:57:44 -04:00
parent 871c551134
commit 5a0dde2017
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
2 changed files with 31 additions and 19 deletions

View File

@ -275,6 +275,7 @@ class GitRepo:
"""
self.repo_warnings: List[str] = []
self.repo_anomalies: List[str] = []
self.managing_instances: List[str] = []
self.init_evt: Optional[asyncio.Event] = None
self.initialized: bool = False
@ -715,6 +716,9 @@ class GitRepo:
def _check_warnings(self) -> None:
self.repo_warnings.clear()
self.repo_anomalies.clear()
if self.repo_corrupt:
self.repo_warnings.append("Repo is corrupt")
if self.upstream_url == "?":
self.repo_warnings.append("Failed to detect repo url")
return
@ -722,16 +726,24 @@ class GitRepo:
if upstream_url[-4:] != ".git":
upstream_url += ".git"
if upstream_url != self.origin_url.lower():
self.repo_warnings.append(f"Unofficial remote url: {self.upstream_url}")
self.repo_anomalies.append(f"Unofficial remote url: {self.upstream_url}")
if self.git_branch != self.primary_branch or self.git_remote != "origin":
self.repo_warnings.append(
self.repo_anomalies.append(
"Repo not on offical remote/branch, expected: "
f"origin/{self.primary_branch}, detected: "
f"{self.git_remote}/{self.git_branch}")
if self.head_detached:
self.repo_warnings.append("Detached HEAD detected")
if self.untracked_files:
self.repo_anomalies.append(
f"Repo has untracked source files: {self.untracked_files}"
)
if self.diverged:
self.repo_warnings.append("Repo has diverged from remote")
self.repo_anomalies.append("Repo has diverged from remote")
if self.head_detached:
msg = "Detached HEAD detected"
if self.server.is_debug_enabled():
self.repo_anomalies.append(msg)
else:
self.repo_warnings.append(msg)
if self.is_dirty():
self.repo_warnings.append(
"Repo is dirty. Detected the following modifed files: "
@ -739,24 +751,19 @@ class GitRepo:
)
if len(self.managing_instances) > 1:
instances = "\n".join([f" {ins}" for ins in self.managing_instances])
self.repo_warnings.append(
self.repo_anomalies.append(
f"Multiple instances of Moonraker managing this repo:\n"
f"{instances}"
)
self._generate_warn_msg()
def _generate_warn_msg(self) -> str:
extra_warnings = []
if self.untracked_files:
extra_warnings.append(
f"Repo has untracked source files: {self.untracked_files}"
)
ro_msg = f"Git Repo {self.alias}: No warnings detected"
warn_msg = ""
if self.repo_warnings or extra_warnings:
if self.repo_warnings or self.repo_anomalies:
ro_msg = f"Git Repo {self.alias}: Warnings detected:\n"
warn_msg = "\n".join(
[f" {warn}" for warn in self.repo_warnings + extra_warnings]
[f" {warn}" for warn in self.repo_warnings + self.repo_anomalies]
)
ro_msg += warn_msg
self.server.add_log_rollover_item(f"umgr_{self.alias}_warn", ro_msg, log=False)
@ -1083,7 +1090,8 @@ class GitRepo:
'full_version_string': self.current_version.full_version,
'pristine': no_untrk_src and not self.current_version.dirty,
'corrupt': self.repo_corrupt,
'warnings': self.repo_warnings
'warnings': self.repo_warnings,
'anomalies': self.repo_anomalies
}
def get_version(self, upstream: bool = False) -> GitVersion:

View File

@ -55,6 +55,7 @@ class WebClientDeploy(BaseDeploy):
self.info_tags: List[str] = config.getlist("info_tags", [])
self.persistent_files: List[str] = []
self.warnings: List[str] = []
self.anomalies: List[str] = []
self.version: str = "?"
pfiles = config.getlist('persistent_files', None)
if pfiles is not None:
@ -103,7 +104,7 @@ class WebClientDeploy(BaseDeploy):
self._valid = True
detected_repo = f"{owner}/{project_name}"
if self.repo.lower() != detected_repo.lower():
self.warnings.append(
self.anomalies.append(
f"Value at option 'repo: {self.repo}' does not match "
f"detected repo '{detected_repo}', falling back to "
"detected version."
@ -142,7 +143,7 @@ class WebClientDeploy(BaseDeploy):
owner = fallback_defs[proj_name]
detected_repo = f"{owner}/{proj_name}"
if detected_repo != self.repo.lower():
self.warnings.append(
self.anomalies.append(
f"Value at option 'repo: {self.repo}' does not match "
f"detected repo '{detected_repo}', falling back to "
"detected version."
@ -180,9 +181,11 @@ class WebClientDeploy(BaseDeploy):
def _log_client_info(self) -> None:
warn_str = ""
if self.warnings:
if self.warnings or self.anomalies:
warn_str = "\nWarnings:\n"
warn_str += "\n".join([f" {item}" for item in self.warnings])
warn_str += "\n".join(
[f" {item}" for item in self.warnings + self.anomalies]
)
dl_url, content_type, size = self.dl_info
logging.info(
f"Web Client {self.name} Detected:\n"
@ -387,5 +390,6 @@ class WebClientDeploy(BaseDeploy):
'info_tags': self.info_tags,
'last_error': self.last_error,
'is_valid': self._valid,
'warnings': self.warnings
'warnings': self.warnings,
'anomalies': self.anomalies
}