From 4bd6929d69f6783fc1b9891499f0c2e2b71b5780 Mon Sep 17 00:00:00 2001
From: Johannes Keyser
Date: Mon, 10 Jul 2017 00:45:40 +0200
Subject: [PATCH] power: warn if a package manager is running before
shutdown/restart
- red colors for warning about running package manager
- red buttons to indicate danger if installation/upgrade runs
---
plinth/modules/power/templates/power.html | 9 +++++++++
.../power/templates/power_restart.html | 19 +++++++++++++++++--
.../power/templates/power_shutdown.html | 19 +++++++++++++++++--
plinth/modules/power/views.py | 18 +++++++++++++++---
4 files changed, 58 insertions(+), 7 deletions(-)
diff --git a/plinth/modules/power/templates/power.html b/plinth/modules/power/templates/power.html
index 9d17724c8..628f012d5 100644
--- a/plinth/modules/power/templates/power.html
+++ b/plinth/modules/power/templates/power.html
@@ -23,6 +23,15 @@
{% block configuration %}
+ {% if pkg_manager_is_busy %}
+
+ {% blocktrans trimmed %}
+ Currently an installation or upgrade is running.
+ Consider waiting until it's finished before shutting down or restarting.
+ {% endblocktrans %}
+
+ {% endif %}
+
{% trans "Restart »" %}
diff --git a/plinth/modules/power/templates/power_restart.html b/plinth/modules/power/templates/power_restart.html
index d4f001c26..0f7b66535 100644
--- a/plinth/modules/power/templates/power_restart.html
+++ b/plinth/modules/power/templates/power_restart.html
@@ -33,13 +33,28 @@
{% endblocktrans %}
+ {% if pkg_manager_is_busy %}
+
+ {% blocktrans trimmed %}
+ Currently an installation or upgrade is running.
+ Consider waiting until it's finished before restarting.
+ {% endblocktrans %}
+
+ {% endif %}
+
{% endblock %}
diff --git a/plinth/modules/power/templates/power_shutdown.html b/plinth/modules/power/templates/power_shutdown.html
index fea041ea3..72bc89593 100644
--- a/plinth/modules/power/templates/power_shutdown.html
+++ b/plinth/modules/power/templates/power_shutdown.html
@@ -32,13 +32,28 @@
{% endblocktrans %}
+ {% if pkg_manager_is_busy %}
+
+ {% blocktrans trimmed %}
+ Currently an installation or upgrade is running.
+ Consider waiting until it's finished before shutting down.
+ {% endblocktrans %}
+
+ {% endif %}
+
diff --git a/plinth/modules/power/views.py b/plinth/modules/power/views.py
index 7b1820084..e6518f8ee 100644
--- a/plinth/modules/power/views.py
+++ b/plinth/modules/power/views.py
@@ -33,7 +33,8 @@ def index(request):
"""Serve power controls page."""
return TemplateResponse(request, 'power.html',
{'title': power.title,
- 'description': power.description})
+ 'description': power.description,
+ 'pkg_manager_is_busy': _is_pkg_manager_busy()})
def restart(request):
@@ -48,7 +49,8 @@ def restart(request):
return TemplateResponse(request, 'power_restart.html',
{'title': _('Power'),
- 'form': form})
+ 'form': form,
+ 'pkg_manager_is_busy': _is_pkg_manager_busy()})
def shutdown(request):
@@ -63,4 +65,14 @@ def shutdown(request):
return TemplateResponse(request, 'power_shutdown.html',
{'title': _('Power'),
- 'form': form})
+ 'form': form,
+ 'pkg_manager_is_busy': _is_pkg_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