Add constant for /etc/pacman.conf (#4375)
This commit is contained in:
parent
41858db832
commit
56bec01979
|
|
@ -1,9 +1,9 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from archinstall.lib.locale.utils import list_timezones
|
from archinstall.lib.locale.utils import list_timezones
|
||||||
from archinstall.lib.menu.helpers import Confirmation, Input, Selection
|
from archinstall.lib.menu.helpers import Confirmation, Input, Selection
|
||||||
from archinstall.lib.output import warn
|
from archinstall.lib.output import warn
|
||||||
|
from archinstall.lib.pathnames import PACMAN_CONF
|
||||||
from archinstall.lib.translationhandler import Language, tr
|
from archinstall.lib.translationhandler import Language, tr
|
||||||
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
|
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
|
||||||
from archinstall.tui.ui.result import ResultType
|
from archinstall.tui.ui.result import ResultType
|
||||||
|
|
@ -162,11 +162,10 @@ async def add_number_of_parallel_downloads(preset: int = 1) -> int | None:
|
||||||
case ResultType.Selection:
|
case ResultType.Selection:
|
||||||
downloads = int(result.get_value())
|
downloads = int(result.get_value())
|
||||||
|
|
||||||
pacman_conf_path = Path('/etc/pacman.conf')
|
with PACMAN_CONF.open() as f:
|
||||||
with pacman_conf_path.open() as f: # noqa: ASYNC230
|
|
||||||
pacman_conf = f.read().split('\n')
|
pacman_conf = f.read().split('\n')
|
||||||
|
|
||||||
with pacman_conf_path.open('w') as fwrite: # noqa: ASYNC230
|
with PACMAN_CONF.open('w') as fwrite:
|
||||||
for line in pacman_conf:
|
for line in pacman_conf:
|
||||||
if 'ParallelDownloads' in line:
|
if 'ParallelDownloads' in line:
|
||||||
fwrite.write(f'ParallelDownloads = {downloads}\n')
|
fwrite.write(f'ParallelDownloads = {downloads}\n')
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ from archinstall.lib.output import debug, error, info, log, logger, warn
|
||||||
from archinstall.lib.packages.packages import installed_package
|
from archinstall.lib.packages.packages import installed_package
|
||||||
from archinstall.lib.pacman.config import PacmanConfig
|
from archinstall.lib.pacman.config import PacmanConfig
|
||||||
from archinstall.lib.pacman.pacman import Pacman
|
from archinstall.lib.pacman.pacman import Pacman
|
||||||
|
from archinstall.lib.pathnames import PACMAN_CONF
|
||||||
from archinstall.lib.plugins import plugins
|
from archinstall.lib.plugins import plugins
|
||||||
from archinstall.lib.translationhandler import tr
|
from archinstall.lib.translationhandler import tr
|
||||||
|
|
||||||
|
|
@ -570,7 +571,7 @@ class Installer:
|
||||||
|
|
||||||
root = self.target if on_target else Path('/')
|
root = self.target if on_target else Path('/')
|
||||||
mirrorlist_config = root / 'etc/pacman.d/mirrorlist'
|
mirrorlist_config = root / 'etc/pacman.d/mirrorlist'
|
||||||
pacman_config = root / 'etc/pacman.conf'
|
pacman_config = root / PACMAN_CONF.relative_to_root()
|
||||||
|
|
||||||
repositories_config = mirror_config.repositories_config()
|
repositories_config = mirror_config.repositories_config()
|
||||||
if repositories_config:
|
if repositories_config:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
|
|
||||||
|
class LPath(Path):
|
||||||
|
@classmethod
|
||||||
|
def fs_root(cls) -> Self:
|
||||||
|
return cls('/')
|
||||||
|
|
||||||
|
def relative_to_root(self) -> Self:
|
||||||
|
return self.relative_to(self.fs_root())
|
||||||
|
|
@ -3,15 +3,15 @@ from pathlib import Path
|
||||||
from shutil import copy2
|
from shutil import copy2
|
||||||
|
|
||||||
from archinstall.lib.models.packages import Repository
|
from archinstall.lib.models.packages import Repository
|
||||||
|
from archinstall.lib.pathnames import PACMAN_CONF
|
||||||
|
|
||||||
|
|
||||||
class PacmanConfig:
|
class PacmanConfig:
|
||||||
def __init__(self, target: Path | None):
|
def __init__(self, target: Path | None):
|
||||||
self._config_path = Path('/etc') / 'pacman.conf'
|
|
||||||
self._config_remote_path: Path | None = None
|
self._config_remote_path: Path | None = None
|
||||||
|
|
||||||
if target:
|
if target:
|
||||||
self._config_remote_path = target / 'etc' / 'pacman.conf'
|
self._config_remote_path = target / PACMAN_CONF.relative_to_root()
|
||||||
|
|
||||||
self._repositories: list[Repository] = []
|
self._repositories: list[Repository] = []
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ class PacmanConfig:
|
||||||
else:
|
else:
|
||||||
repos_to_enable.append(repo.value)
|
repos_to_enable.append(repo.value)
|
||||||
|
|
||||||
content = self._config_path.read_text().splitlines(keepends=True)
|
content = PACMAN_CONF.read_text().splitlines(keepends=True)
|
||||||
|
|
||||||
for row, line in enumerate(content):
|
for row, line in enumerate(content):
|
||||||
# Check if this is a commented repository section that needs to be enabled
|
# Check if this is a commented repository section that needs to be enabled
|
||||||
|
|
@ -47,9 +47,9 @@ class PacmanConfig:
|
||||||
content[row + 1] = re.sub(r'^#\s*', '', content[row + 1])
|
content[row + 1] = re.sub(r'^#\s*', '', content[row + 1])
|
||||||
|
|
||||||
# Write the modified content back to the file
|
# Write the modified content back to the file
|
||||||
with open(self._config_path, 'w') as f:
|
with PACMAN_CONF.open('w') as f:
|
||||||
f.writelines(content)
|
f.writelines(content)
|
||||||
|
|
||||||
def persist(self) -> None:
|
def persist(self) -> None:
|
||||||
if self._repositories and self._config_remote_path:
|
if self._repositories and self._config_remote_path:
|
||||||
copy2(self._config_path, self._config_remote_path)
|
copy2(PACMAN_CONF, self._config_remote_path)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from pathlib import Path
|
||||||
from archinstall.lib.command import SysCommand
|
from archinstall.lib.command import SysCommand
|
||||||
from archinstall.lib.exceptions import RequirementError
|
from archinstall.lib.exceptions import RequirementError
|
||||||
from archinstall.lib.output import error, info, warn
|
from archinstall.lib.output import error, info, warn
|
||||||
|
from archinstall.lib.pathnames import PACMAN_CONF
|
||||||
from archinstall.lib.plugins import plugins
|
from archinstall.lib.plugins import plugins
|
||||||
from archinstall.lib.translationhandler import tr
|
from archinstall.lib.translationhandler import tr
|
||||||
|
|
||||||
|
|
@ -77,6 +78,6 @@ class Pacman:
|
||||||
'Could not strap in packages',
|
'Could not strap in packages',
|
||||||
'Pacstrap failed. See /var/log/archinstall/install.log or above message for error details',
|
'Pacstrap failed. See /var/log/archinstall/install.log or above message for error details',
|
||||||
SysCommand,
|
SysCommand,
|
||||||
f'pacstrap -C /etc/pacman.conf -K {self.target} {" ".join(packages)} --noconfirm --needed',
|
f'pacstrap -C {PACMAN_CONF} -K {self.target} {" ".join(packages)} --noconfirm --needed',
|
||||||
peek_output=True,
|
peek_output=True,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
from typing import Final
|
||||||
|
|
||||||
|
from archinstall.lib.linux_path import LPath
|
||||||
|
|
||||||
|
PACMAN_CONF: Final = LPath('/etc/pacman.conf')
|
||||||
Loading…
Reference in New Issue