mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-11 08:23:49 +00:00
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:
parent
a60341f0d8
commit
f8eb6c8cc6
@ -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.')
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user