From 7caed57cafecb2da0feb37025c4a4abbc48998a1 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 1 Jul 2020 19:58:51 -0400 Subject: [PATCH] upgrades: Add button to activate backports Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- plinth/modules/upgrades/__init__.py | 19 +++++++++-- .../templates/upgrades_configure.html | 34 +++++++++++++++++++ plinth/modules/upgrades/urls.py | 2 ++ plinth/modules/upgrades/views.py | 10 ++++++ 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index 8a3161b58..86942454f 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -58,7 +58,7 @@ class UpgradesApp(app_module.App): # Check every day for setting up apt backport sources, every 3 minutes # in debug mode. interval = 180 if cfg.develop else 24 * 3600 - glib.schedule(interval, _setup_repositories) + glib.schedule(interval, setup_repositories) def _show_new_release_notification(self): """When upgraded to new release, show a notification.""" @@ -111,7 +111,7 @@ def setup(helper, old_version=None): # Try to setup apt repositories, if needed, if possible, on first install # and on version increment. - helper.call('post', _setup_repositories, None) + helper.call('post', setup_repositories, None) def is_enabled(): @@ -130,7 +130,7 @@ def disable(): actions.superuser_run('upgrades', ['disable-auto']) -def _setup_repositories(data): +def setup_repositories(data): """Setup apt backport repositories.""" actions.superuser_run('upgrades', ['setup-repositories']) @@ -146,3 +146,16 @@ def get_backports_in_use(): return True return False + + +def can_activate_backports(): + """Return whether backports can be activated.""" + if get_backports_in_use(): + return False + + release = subprocess.check_output(['lsb_release', '--release', + '--short']).decode().strip() + if release in ['testing', 'unstable']: + return False + + return True diff --git a/plinth/modules/upgrades/templates/upgrades_configure.html b/plinth/modules/upgrades/templates/upgrades_configure.html index d8497e010..1e6a308b8 100644 --- a/plinth/modules/upgrades/templates/upgrades_configure.html +++ b/plinth/modules/upgrades/templates/upgrades_configure.html @@ -8,6 +8,40 @@ {% load static %} {% block extra_content %} + {% if can_activate_backports %} +

{% trans "Backports" %}

+

+ {% blocktrans trimmed %} + Backports can be activated. This will allow a limited set of software, + including FreedomBox service, to be upgraded to newer versions from + Debian backports repository. + {% endblocktrans %} +

+

+ {% blocktrans trimmed %} + Please note that backports packages do not have security support from + Debian. However, they are maintained on a best-effort basis by + contributors in Debian and FreedomBox community. + {% endblocktrans %} +

+ +

+

+ {% csrf_token %} + +
+

+ {% endif %} +

{% trans "Manual update" %}

{% if is_busy %}

diff --git a/plinth/modules/upgrades/urls.py b/plinth/modules/upgrades/urls.py index e9c2b260e..093bac122 100644 --- a/plinth/modules/upgrades/urls.py +++ b/plinth/modules/upgrades/urls.py @@ -10,5 +10,7 @@ from . import views urlpatterns = [ url(r'^sys/upgrades/$', views.UpgradesConfigurationView.as_view(), name='index'), + url(r'^sys/upgrades/activate-backports/$', views.activate_backports, + name='activate-backports'), url(r'^sys/upgrades/upgrade/$', views.upgrade, name='upgrade'), ] diff --git a/plinth/modules/upgrades/views.py b/plinth/modules/upgrades/views.py index 056d294b4..61ec6a661 100644 --- a/plinth/modules/upgrades/views.py +++ b/plinth/modules/upgrades/views.py @@ -28,6 +28,7 @@ class UpgradesConfigurationView(AppView): def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) + context['can_activate_backports'] = upgrades.can_activate_backports() context['is_busy'] = package.is_package_manager_busy() context['log'] = get_log() context['refresh_page_sec'] = 3 if context['is_busy'] else None @@ -77,3 +78,12 @@ def upgrade(request): messages.error(request, _('Starting upgrade failed.')) return redirect(reverse_lazy('upgrades:index')) + + +def activate_backports(request): + """Activate backports.""" + if request.method == 'POST': + upgrades.setup_repositories(None) + messages.success(request, _('Backports activated.')) + + return redirect(reverse_lazy('upgrades:index'))