diff --git a/actions/packages b/actions/packages index 5350e5164..301d54875 100755 --- a/actions/packages +++ b/actions/packages @@ -28,6 +28,8 @@ import sys from plinth import cfg +LOCK_FILE = '/var/lib/dpkg/lock' + def parse_arguments(): """Return parsed command line arguments as dictionary.""" @@ -41,6 +43,8 @@ def parse_arguments(): 'module', help='name of module for which package is being installed') subparser.add_argument( 'packages', nargs='+', help='list of packages to install') + subparsers.add_parser('is-package-manager-busy', + help='Return whether package manager is busy') subparsers.required = True return parser.parse_args() @@ -94,6 +98,14 @@ def _assert_managed_packages(module, packages): assert package in module.managed_packages +def subcommand_is_package_manager_busy(_): + """Return whether package manager is busy.""" + try: + subprocess.check_output(['lsof', LOCK_FILE]) + except subprocess.CalledProcessError: + sys.exit(-1) + + def main(): """Parse arguments and perform all duties.""" arguments = parse_arguments() diff --git a/actions/upgrades b/actions/upgrades index 01c2683a3..1211c3993 100755 --- a/actions/upgrades +++ b/actions/upgrades @@ -28,7 +28,6 @@ import sys CONF_FILE = '/etc/apt/apt.conf.d/50unattended-upgrades' AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-upgrades' -LOCK_FILE = '/var/lib/dpkg/lock' LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log' @@ -42,8 +41,6 @@ def parse_arguments(): help='Check if automatic upgrades are enabled') subparsers.add_parser('enable-auto', help='Enable automatic upgrades') subparsers.add_parser('disable-auto', help='Disable automatic upgrades.') - subparsers.add_parser('is-package-manager-busy', - help='Return whether package manager is busy') subparsers.add_parser('get-log', help='Print the automatic upgrades log') subparsers.required = True @@ -129,14 +126,6 @@ def setup(): conffile.write(' "origin=Debian";\n') -def subcommand_is_package_manager_busy(_): - """Return whether package manager is busy.""" - try: - subprocess.check_output(['lsof', LOCK_FILE]) - except subprocess.CalledProcessError: - sys.exit(-1) - - def subcommand_get_log(_): """Print the automatic upgrades log.""" try: diff --git a/plinth/modules/upgrades/views.py b/plinth/modules/upgrades/views.py index c9b3781d7..73fa764f3 100644 --- a/plinth/modules/upgrades/views.py +++ b/plinth/modules/upgrades/views.py @@ -84,11 +84,10 @@ class UpgradesConfigurationView(FormView): return super().form_valid(form) - def is_package_manager_busy(): """Return whether a package manager is running.""" try: - actions.superuser_run('upgrades', ['is-package-manager-busy']) + actions.superuser_run('packages', ['is-package-manager-busy']) return True except actions.ActionError: return False diff --git a/plinth/templates/setup.html b/plinth/templates/setup.html index 4cd25ee0f..0a7a4a8f4 100644 --- a/plinth/templates/setup.html +++ b/plinth/templates/setup.html @@ -50,8 +50,19 @@
{% csrf_token %} - + {% if package_manager_is_busy %} + + + {% else %} + + {% endif %}
{% elif setup_helper.get_state == 'needs-update' %}

@@ -63,8 +74,19 @@

{% csrf_token %} - + {% if package_manager_is_busy %} + + + {% else %} + + {% endif %}
{% endif %} diff --git a/plinth/views.py b/plinth/views.py index 489550d81..72b35d314 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -30,6 +30,7 @@ import time from . import forms, frontpage import plinth +from plinth import actions @public @@ -208,8 +209,17 @@ class SetupView(TemplateView): """Return the context data rendering the template.""" context = super(SetupView, self).get_context_data(**kwargs) context['setup_helper'] = self.kwargs['setup_helper'] + context['package_manager_is_busy'] = self.is_package_manager_busy() return context + def is_package_manager_busy(self): + """Return whether a package manager is running.""" + try: + actions.superuser_run('packages', ['is-package-manager-busy']) + return True + except actions.ActionError: + return False + def post(self, *args, **kwargs): """Handle installing/upgrading applications.