From b12d994760e552a1e4d7a8922f0792406c68e458 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 8 Sep 2020 15:27:48 -0700 Subject: [PATCH] upgrades: Separate concepts for backports enabled vs. requested It is confusing to combine the user's intent of wanting to have backports activated with whether they have actually been configured in the system. - Separate out checking for requested which is a key in the kvstore from enabled which is about checking system configuration for backports. - Implement convenience method for setting whether user requested backports. - Do not base the status display (in security and upgrades modules) on the configuration status and instead focus on user intent. - If user requested backports but they have not been enabled yet due to not being available, show as activated. System will keep trying the background and configure eventually. - If user requested backports but their configuration is outdated yet due to newer release, show as activated. System will keep trying in the background and configure latest settings eventually. - In all places where backports enabling is being checked, split the logic for 'can be activated' from 'already activated' and 'user requested activation' properly. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- .../modules/security/templates/security.html | 2 +- plinth/modules/security/views.py | 4 +-- plinth/modules/upgrades/__init__.py | 29 +++++++++++++------ plinth/modules/upgrades/forms.py | 2 +- .../templates/upgrades_configure.html | 8 ++--- plinth/modules/upgrades/views.py | 29 +++++-------------- 6 files changed, 35 insertions(+), 39 deletions(-) diff --git a/plinth/modules/security/templates/security.html b/plinth/modules/security/templates/security.html index 56bd907d1..80ecd8646 100644 --- a/plinth/modules/security/templates/security.html +++ b/plinth/modules/security/templates/security.html @@ -13,7 +13,7 @@ {% trans "Show security report" %} - {% if is_backports_enabled %} + {% if is_backports_requested %}

{% trans "Frequent Feature Updates" %}

{% blocktrans trimmed %} diff --git a/plinth/modules/security/views.py b/plinth/modules/security/views.py index 65bcee4de..2270fb746 100644 --- a/plinth/modules/security/views.py +++ b/plinth/modules/security/views.py @@ -9,7 +9,7 @@ from django.utils.translation import ugettext as _ from plinth import action_utils, actions from plinth.modules import security -from plinth.modules.upgrades import is_backports_enabled +from plinth.modules.upgrades import is_backports_requested from .forms import SecurityForm @@ -33,7 +33,7 @@ def index(request): request, 'security.html', { 'app_info': security.app.info, 'form': form, - 'is_backports_enabled': is_backports_enabled(), + 'is_backports_requested': is_backports_requested(), }) diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index f5808f162..4d733a361 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -3,6 +3,7 @@ FreedomBox app for upgrades. """ +import logging import os import subprocess @@ -42,10 +43,12 @@ _description = [ app = None -BACKPORTS_ENABLED_KEY = 'upgrades_backports_enabled' +BACKPORTS_REQUESTED_KEY = 'upgrades_backports_requested' SOURCES_LIST = '/etc/apt/sources.list.d/freedombox2.list' +logger = logging.getLogger(__name__) + class UpgradesApp(app_module.App): """FreedomBox app for software upgrades.""" @@ -139,7 +142,7 @@ def disable(): def setup_repositories(data): """Setup apt backport repositories.""" - if is_backports_enabled(): + if is_backports_requested(): command = ['setup-repositories'] if cfg.develop: command += ['--develop'] @@ -147,11 +150,22 @@ def setup_repositories(data): actions.superuser_run('upgrades', command) -def is_backports_enabled(): - """Return whether backports are enabled.""" +def is_backports_requested(): + """Return whether user has chosen to activate backports.""" from plinth import kvstore - return kvstore.get_default(BACKPORTS_ENABLED_KEY, - os.path.exists(SOURCES_LIST)) + return kvstore.get_default(BACKPORTS_REQUESTED_KEY, False) + + +def set_backports_requested(requested): + """Set whether user has chosen to activate backports.""" + from plinth import kvstore + kvstore.set(BACKPORTS_REQUESTED_KEY, requested) + logger.info('Backports requested - %s', requested) + + +def is_backports_enabled(): + """Return whether backports are enabled in the system configuration.""" + return os.path.exists(SOURCES_LIST) def get_current_release(): @@ -180,9 +194,6 @@ def is_backports_current(): def can_activate_backports(): """Return whether backports can be activated.""" - if is_backports_current(): - return False - release, _ = get_current_release() if release == 'unstable' or (release == 'testing' and not cfg.develop): return False diff --git a/plinth/modules/upgrades/forms.py b/plinth/modules/upgrades/forms.py index 5a92aa70c..db4263ef4 100644 --- a/plinth/modules/upgrades/forms.py +++ b/plinth/modules/upgrades/forms.py @@ -18,4 +18,4 @@ class BackportsFirstbootForm(forms.Form): """Form to configure backports during first boot wizard.""" backports_enabled = forms.BooleanField( label=_('Activate frequent feature updates (recommended)'), - required=False) + required=False, initial=True) diff --git a/plinth/modules/upgrades/templates/upgrades_configure.html b/plinth/modules/upgrades/templates/upgrades_configure.html index 94262751c..f8c7ecf3b 100644 --- a/plinth/modules/upgrades/templates/upgrades_configure.html +++ b/plinth/modules/upgrades/templates/upgrades_configure.html @@ -10,12 +10,12 @@ {% block extra_content %}

{% trans "Frequent Feature Updates" %}

- {% if can_activate_backports %} + {% if can_activate_backports and not is_backports_requested %} {% blocktrans trimmed %} Frequent feature updates can be activated. Activating them is recommended. {% endblocktrans %} - {% elif is_backports_enabled %} + {% elif can_activate_backports and is_backports_requested %} {% blocktrans trimmed %} Frequent feature updates are enabled. {% endblocktrans %} @@ -27,7 +27,7 @@ {% endif %}

- {% if can_activate_backports or is_backports_enabled %} + {% if can_activate_backports %} {% blocktrans trimmed %} Frequent feature updates allow a very limited set of software, including {{box_name}} service, to be updated to receive newer features regularly @@ -38,7 +38,7 @@ {% endblocktrans %} {% endif %}

- {% if can_activate_backports %} + {% if can_activate_backports and not is_backports_requested %}