From 355b2be90e12faf2b3a5bd290fefedb76b12f411 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 12 May 2020 17:11:21 -0700 Subject: [PATCH] package: Fix error log when checking if package manager is busy Reuse the method in package.py that checks is package manager is busy without printing and error log. Tests performed: - Try to install a package and wait at the apt confirmation prompt. - Go to power index page /sys/power/ . It shows a warning that package manager is busy. No error log is printed. - Go to system restart page. It shows a warning that package manager is busy. No error log is printed. - Go to system poweroff page. It shows a warning that package manager is busy. No error log is printed. - Without package manager being busy, above warnings are not shown. - Go to manual update package. It shows as updating if apt is busy, otherwise shows the manual update button. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/power/views.py | 17 ++++------------- plinth/modules/upgrades/views.py | 13 ++----------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/plinth/modules/power/views.py b/plinth/modules/power/views.py index 54f6eaaca..f104a0c96 100644 --- a/plinth/modules/power/views.py +++ b/plinth/modules/power/views.py @@ -8,7 +8,7 @@ from django.shortcuts import redirect from django.template.response import TemplateResponse from django.urls import reverse -from plinth import actions +from plinth import actions, package from plinth.modules import power @@ -18,7 +18,7 @@ def index(request): request, 'power.html', { 'title': power.app.info.name, 'app_info': power.app.info, - 'pkg_manager_is_busy': _is_pkg_manager_busy() + 'pkg_manager_is_busy': package.is_package_manager_busy() }) @@ -37,7 +37,7 @@ def restart(request): 'title': power.app.info.name, 'form': form, 'manual_page': power.app.info.manual_page, - 'pkg_manager_is_busy': _is_pkg_manager_busy() + 'pkg_manager_is_busy': package.is_package_manager_busy() }) @@ -56,14 +56,5 @@ def shutdown(request): 'title': power.app.info.name, 'form': form, 'manual_page': power.app.info.manual_page, - 'pkg_manager_is_busy': _is_pkg_manager_busy() + 'pkg_manager_is_busy': package.is_package_manager_busy() }) - - -def _is_pkg_manager_busy(): - """Return whether a package manager is running.""" - try: - actions.superuser_run('packages', ['is-package-manager-busy']) - return True - except actions.ActionError: - return False diff --git a/plinth/modules/upgrades/views.py b/plinth/modules/upgrades/views.py index 1da6c734d..4e0549f2c 100644 --- a/plinth/modules/upgrades/views.py +++ b/plinth/modules/upgrades/views.py @@ -8,7 +8,7 @@ from django.template.response import TemplateResponse from django.urls import reverse_lazy from django.utils.translation import ugettext as _ -from plinth import actions +from plinth import actions, package from plinth.errors import ActionError from plinth.modules import upgrades from plinth.views import AppView @@ -55,15 +55,6 @@ class UpgradesConfigurationView(AppView): return super().form_valid(form) -def is_package_manager_busy(): - """Return whether a package manager is running.""" - try: - actions.superuser_run('packages', ['is-package-manager-busy']) - return True - except actions.ActionError: - return False - - def get_log(): """Return the current log for unattended upgrades.""" return actions.superuser_run('upgrades', ['get-log']) @@ -71,7 +62,7 @@ def get_log(): def upgrade(request): """Serve the upgrade page.""" - is_busy = is_package_manager_busy() + is_busy = package.is_package_manager_busy() if request.method == 'POST': try: