write .makepkg.conf to home dir instead of repository root (#72)

This commit is contained in:
Evgenii Alekseev 2022-11-08 16:44:48 +02:00
parent 2a07356d24
commit e58ccdc8ad
3 changed files with 27 additions and 4 deletions

View File

@ -20,6 +20,7 @@
import argparse import argparse
from pathlib import Path from pathlib import Path
from pwd import getpwuid
from typing import Type from typing import Type
from ahriman.application.application import Application from ahriman.application.application import Application
@ -173,7 +174,9 @@ class Setup(Handler):
packager(str): packager identifier (e.g. name, email) packager(str): packager identifier (e.g. name, email)
paths(RepositoryPaths): repository paths instance paths(RepositoryPaths): repository paths instance
""" """
(paths.root / ".makepkg.conf").write_text(f"PACKAGER='{packager}'\n", encoding="utf8") uid, _ = paths.root_owner
home_dir = Path(getpwuid(uid).pw_dir)
(home_dir / ".makepkg.conf").write_text(f"PACKAGER='{packager}'\n", encoding="utf8")
@staticmethod @staticmethod
def configuration_create_sudo(paths: RepositoryPaths, prefix: str, architecture: str) -> None: def configuration_create_sudo(paths: RepositoryPaths, prefix: str, architecture: str) -> None:

View File

@ -0,0 +1,17 @@
import pytest
from collections import namedtuple
_passwd = namedtuple("passwd", ["pw_dir"])
@pytest.fixture
def passwd() -> _passwd:
"""
get passwd structure for the user
Returns:
_passwd: passwd structure test instance
"""
return _passwd("home")

View File

@ -3,6 +3,7 @@ import pytest
from pathlib import Path from pathlib import Path
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
from typing import Any
from unittest import mock from unittest import mock
from ahriman.application.handlers import Setup from ahriman.application.handlers import Setup
@ -130,15 +131,17 @@ def test_configuration_create_devtools_no_multilib(args: argparse.Namespace, rep
def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths: RepositoryPaths, def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths: RepositoryPaths,
mocker: MockerFixture) -> None: passwd: Any, mocker: MockerFixture) -> None:
""" """
must create makepkg configuration must create makepkg configuration
""" """
args = _default_args(args) args = _default_args(args)
write_text_mock = mocker.patch("pathlib.Path.write_text") mocker.patch("ahriman.application.handlers.setup.getpwuid", return_value=passwd)
write_text_mock = mocker.patch("pathlib.Path.write_text", autospec=True)
Setup.configuration_create_makepkg(args.packager, repository_paths) Setup.configuration_create_makepkg(args.packager, repository_paths)
write_text_mock.assert_called_once_with(pytest.helpers.anyvar(str, True), encoding="utf8") write_text_mock.assert_called_once_with(
Path("home") / ".makepkg.conf", pytest.helpers.anyvar(str, True), encoding="utf8")
def test_configuration_create_sudo(args: argparse.Namespace, repository_paths: RepositoryPaths, def test_configuration_create_sudo(args: argparse.Namespace, repository_paths: RepositoryPaths,