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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-05-12 17:11:21 -07:00 committed by James Valleroy
parent dbf70b9fef
commit 355b2be90e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 6 additions and 24 deletions

View File

@ -8,7 +8,7 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.urls import reverse from django.urls import reverse
from plinth import actions from plinth import actions, package
from plinth.modules import power from plinth.modules import power
@ -18,7 +18,7 @@ def index(request):
request, 'power.html', { request, 'power.html', {
'title': power.app.info.name, 'title': power.app.info.name,
'app_info': power.app.info, '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, 'title': power.app.info.name,
'form': form, 'form': form,
'manual_page': power.app.info.manual_page, '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, 'title': power.app.info.name,
'form': form, 'form': form,
'manual_page': power.app.info.manual_page, '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

View File

@ -8,7 +8,7 @@ from django.template.response import TemplateResponse
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from plinth import actions from plinth import actions, package
from plinth.errors import ActionError from plinth.errors import ActionError
from plinth.modules import upgrades from plinth.modules import upgrades
from plinth.views import AppView from plinth.views import AppView
@ -55,15 +55,6 @@ class UpgradesConfigurationView(AppView):
return super().form_valid(form) 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(): def get_log():
"""Return the current log for unattended upgrades.""" """Return the current log for unattended upgrades."""
return actions.superuser_run('upgrades', ['get-log']) return actions.superuser_run('upgrades', ['get-log'])
@ -71,7 +62,7 @@ def get_log():
def upgrade(request): def upgrade(request):
"""Serve the upgrade page.""" """Serve the upgrade page."""
is_busy = is_package_manager_busy() is_busy = package.is_package_manager_busy()
if request.method == 'POST': if request.method == 'POST':
try: try: