diff --git a/actions/upgrades b/actions/upgrades index 5174c5657..49242c31e 100755 --- a/actions/upgrades +++ b/actions/upgrades @@ -13,7 +13,8 @@ import sys from plinth.action_utils import run_apt_command from plinth.modules.apache.components import check_url -from plinth.modules.upgrades import is_backports_current, SOURCES_LIST +from plinth.modules.upgrades import (get_current_release, is_backports_current, + SOURCES_LIST) AUTO_CONF_FILE = '/etc/apt/apt.conf.d/20auto-upgrades' LOG_FILE = '/var/log/unattended-upgrades/unattended-upgrades.log' @@ -218,8 +219,7 @@ def _check_and_backports_sources(develop=False): 'backports.') return - release = subprocess.check_output(['lsb_release', '--release', - '--short']).decode().strip() + release, dist = get_current_release() if release == 'unstable' or (release == 'testing' and not develop): print(f'System release is {release}. Skip enabling backports.') return @@ -228,8 +228,6 @@ def _check_and_backports_sources(develop=False): if protocol == 'tor+http': print('Package download over Tor is enabled.') - dist = subprocess.check_output(['lsb_release', '--codename', - '--short']).decode().strip() if not _is_release_file_available(protocol, dist): print(f'Release file for {dist}-backports is not available yet.') return @@ -251,8 +249,7 @@ def _add_apt_preferences(): # Don't try to remove 50freedombox3.pref as this file is shipped with the # Debian package and is removed using maintainer scripts. - dist = subprocess.check_output(['lsb_release', '--codename', - '--short']).decode().strip() + _, dist = get_current_release() if dist == 'sid': print(f'System distribution is {dist}. Skip setting apt preferences ' 'for backports.') diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index 4adcaace9..97aec4db9 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -148,13 +148,22 @@ def is_backports_enabled(): return os.path.exists(SOURCES_LIST) +def get_current_release(): + """Return current release and codename as a tuple.""" + output = subprocess.check_output( + ['lsb_release', '--release', '--codename', + '--short']).decode().strip() + lines = output.split('\n') + return lines[0], lines[1] + + def is_backports_current(): """Return whether backports are enabled for the current release.""" if not is_backports_enabled: return False - dist = subprocess.check_output(['lsb_release', '--codename', '--short' - ]).decode().strip() + '-backports' + _, dist = get_current_release() + dist += '-backports' sources = sourceslist.SourcesList() for source in sources: if source.dist == dist: @@ -168,8 +177,7 @@ def can_activate_backports(): if is_backports_current(): return False - release = subprocess.check_output(['lsb_release', '--release', - '--short']).decode().strip() + release, _ = get_current_release() if release == 'unstable' or (release == 'testing' and not cfg.develop): return False diff --git a/plinth/modules/upgrades/views.py b/plinth/modules/upgrades/views.py index 77e12c2fa..51ed0c141 100644 --- a/plinth/modules/upgrades/views.py +++ b/plinth/modules/upgrades/views.py @@ -3,8 +3,6 @@ FreedomBox app for upgrades. """ -import subprocess - from django.contrib import messages from django.shortcuts import redirect from django.urls import reverse_lazy @@ -31,8 +29,8 @@ 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['dist'] = subprocess.check_output( - ['lsb_release', '--codename', '--short']).decode().strip() + _, dist = upgrades.get_current_release() + context['dist'] = dist context['is_busy'] = package.is_package_manager_busy() context['log'] = get_log() context['refresh_page_sec'] = 3 if context['is_busy'] else None