mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
action_utils: Separate function to hold freedombox package
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
3c975660f8
commit
eccc355203
@ -18,7 +18,7 @@ import apt.cache
|
|||||||
import apt_inst
|
import apt_inst
|
||||||
import apt_pkg
|
import apt_pkg
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth.action_utils import apt_hold, run_apt_command
|
from plinth.action_utils import apt_hold_freedombox, run_apt_command
|
||||||
|
|
||||||
LOCK_FILE = '/var/lib/dpkg/lock'
|
LOCK_FILE = '/var/lib/dpkg/lock'
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ def subcommand_install(arguments):
|
|||||||
extra_arguments += ['-o', 'Dpkg::Options::=--force-confmiss']
|
extra_arguments += ['-o', 'Dpkg::Options::=--force-confmiss']
|
||||||
|
|
||||||
subprocess.run(['dpkg', '--configure', '-a'])
|
subprocess.run(['dpkg', '--configure', '-a'])
|
||||||
with apt_hold():
|
with apt_hold_freedombox():
|
||||||
run_apt_command(['--fix-broken', 'install'])
|
run_apt_command(['--fix-broken', 'install'])
|
||||||
returncode = run_apt_command(['install'] + extra_arguments +
|
returncode = run_apt_command(['install'] + extra_arguments +
|
||||||
arguments.packages)
|
arguments.packages)
|
||||||
|
|||||||
@ -14,9 +14,9 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from plinth.action_utils import (apt_hold, debconf_set_selections,
|
from plinth.action_utils import (apt_hold, apt_hold_freedombox,
|
||||||
run_apt_command, service_daemon_reload,
|
debconf_set_selections, run_apt_command,
|
||||||
service_restart)
|
service_daemon_reload, service_restart)
|
||||||
from plinth.modules.apache.components import check_url
|
from plinth.modules.apache.components import check_url
|
||||||
from plinth.modules.snapshot import (is_apt_snapshots_enabled, is_supported as
|
from plinth.modules.snapshot import (is_apt_snapshots_enabled, is_supported as
|
||||||
snapshot_is_supported, load_augeas as
|
snapshot_is_supported, load_augeas as
|
||||||
@ -432,7 +432,7 @@ def _perform_dist_upgrade():
|
|||||||
|
|
||||||
# Hold freedombox package during entire dist upgrade.
|
# Hold freedombox package during entire dist upgrade.
|
||||||
print('Holding freedombox package...', flush=True)
|
print('Holding freedombox package...', flush=True)
|
||||||
with apt_hold():
|
with apt_hold_freedombox():
|
||||||
print('Updating Apt cache...', flush=True)
|
print('Updating Apt cache...', flush=True)
|
||||||
run_apt_command(['update'])
|
run_apt_command(['update'])
|
||||||
|
|
||||||
|
|||||||
@ -413,11 +413,8 @@ def run_apt_command(arguments):
|
|||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def apt_hold(packages=None, ignore_errors=False):
|
def apt_hold(packages, ignore_errors=False):
|
||||||
"""Prevent packages from being removed during apt operations."""
|
"""Prevent packages from being removed during apt operations."""
|
||||||
if not packages:
|
|
||||||
packages = ['freedombox']
|
|
||||||
|
|
||||||
current_hold = subprocess.check_output(['apt-mark', 'showhold'] + packages)
|
current_hold = subprocess.check_output(['apt-mark', 'showhold'] + packages)
|
||||||
try:
|
try:
|
||||||
yield current_hold or subprocess.run(['apt-mark', 'hold'] + packages,
|
yield current_hold or subprocess.run(['apt-mark', 'hold'] + packages,
|
||||||
@ -426,3 +423,16 @@ def apt_hold(packages=None, ignore_errors=False):
|
|||||||
if not current_hold:
|
if not current_hold:
|
||||||
subprocess.run(['apt-mark', 'unhold'] + packages,
|
subprocess.run(['apt-mark', 'unhold'] + packages,
|
||||||
check=not ignore_errors)
|
check=not ignore_errors)
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def apt_hold_freedombox():
|
||||||
|
"""Prevent freedombox package from being removed during apt operations."""
|
||||||
|
current_hold = subprocess.check_output(
|
||||||
|
['apt-mark', 'showhold', 'freedombox'])
|
||||||
|
try:
|
||||||
|
yield current_hold or subprocess.check_call(
|
||||||
|
['apt-mark', 'hold', 'freedombox'])
|
||||||
|
finally:
|
||||||
|
if not current_hold:
|
||||||
|
subprocess.check_call(['apt-mark', 'unhold', 'freedombox'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user