upgrades: Refactor use of lsb_release

Tests:
- On unstable and testing:
  - Ran functional tests for upgrades.
  - Ran actions "upgrades setup" and "upgrades setup-repositories".
- On testing:
  - In develop mode, activated backports.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy authored and Sunil Mohan Adapa committed 2020-07-13 14:44:32 -07:00
1 parent a60341f0d8
commit f8eb6c8cc6
3 files changed
+18 -15

No files matched your search

+12 -4
View File
@@ -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
+2 -4
View File
@@ -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