mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
diagnostics: Add DiagnosticCheck dataclass
- Set unique check_id for each diagnostic check. - Result is a string-based enumeration. The default value (NOT_DONE) can be used for diagnostic checks that have not been completed yet. - Result is StrEnum so that the return value of check_url can still be used directly as a diagnostic result. Closes: #2375 Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
19 files changed
+284
-183
No files matched your search
+16
-10
@@ -202,30 +202,36 @@ class Packages(app_module.FollowerComponent):
|
||||
|
||||
def diagnose(self):
|
||||
"""Run diagnostics and return results."""
|
||||
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
|
||||
|
||||
results = super().diagnose()
|
||||
cache = apt.Cache()
|
||||
for package_expression in self.package_expressions:
|
||||
try:
|
||||
package_name = package_expression.actual()
|
||||
except MissingPackageError:
|
||||
message = _('Package {expression} is not available for '
|
||||
'install').format(expression=package_expression)
|
||||
results.append([message, 'failed'])
|
||||
check_id = f'package-{package_expression}'
|
||||
description = _(
|
||||
'Package {expression} is not available for '
|
||||
'install').format(expression=package_expression)
|
||||
results.append(
|
||||
DiagnosticCheck(check_id, description, Result.FAILED))
|
||||
continue
|
||||
|
||||
result = 'warning'
|
||||
result = Result.WARNING
|
||||
latest_version = '?'
|
||||
if package_name in cache:
|
||||
package = cache[package_name]
|
||||
latest_version = package.candidate.version
|
||||
if package.candidate.is_installed:
|
||||
result = 'passed'
|
||||
result = Result.PASSED
|
||||
|
||||
message = _('Package {package_name} is the latest version '
|
||||
'({latest_version})').format(
|
||||
package_name=package_name,
|
||||
latest_version=latest_version)
|
||||
results.append([message, result])
|
||||
check_id = f'package-{package_name}'
|
||||
description = _('Package {package_name} is the latest version '
|
||||
'({latest_version})').format(
|
||||
package_name=package_name,
|
||||
latest_version=latest_version)
|
||||
results.append(DiagnosticCheck(check_id, description, result))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
Reference in new issue
Block a user