Compare commits

...

2 Commits

Author SHA1 Message Date
f0930be238 fix: do not copy own database during pyalpm initialization
Previous implementation lead to warning in logs in case if the
repository itself wasn't configured on the host
2024-09-25 14:31:32 +03:00
113a861f31 fix: suppress info logging during version check 2024-09-25 14:23:53 +03:00
5 changed files with 26 additions and 30 deletions

View File

@ -91,9 +91,8 @@ class Pacman(LazyLogging):
database = self.database_init(handle, repository, self.repository_id.architecture)
self.database_copy(handle, database, pacman_root, use_ahriman_cache=use_ahriman_cache)
# install repository database too
local_database = self.database_init(handle, self.repository_id.name, self.repository_id.architecture)
self.database_copy(handle, local_database, pacman_root, use_ahriman_cache=use_ahriman_cache)
# install repository database too (without copying)
self.database_init(handle, self.repository_id.name, self.repository_id.architecture)
if use_ahriman_cache and refresh_database:
self.database_sync(handle, force=refresh_database == PacmanSynchronization.Force)
@ -115,6 +114,7 @@ class Pacman(LazyLogging):
if not use_ahriman_cache:
return
# copy root database if no local copy found
pacman_db_path = Path(handle.dbpath)
if not pacman_db_path.is_dir():
@ -123,11 +123,13 @@ class Pacman(LazyLogging):
if dst.is_file():
return # file already exists, do not copy
dst.parent.mkdir(mode=0o755, exist_ok=True) # create sync directory if it doesn't exist
src = repository_database(pacman_root)
if not src.is_file():
self.logger.warning("repository %s is set to be used, however, no working copy was found", database.name)
return # database for some reason deos not exist
self.logger.info("copy pacman database from operating system root to ahriman's home")
self.logger.info("copy pacman database %s from operating system root to ahriman's home %s", src, dst)
shutil.copy(src, dst)
self.repository_paths.chown(dst)

View File

@ -23,9 +23,8 @@ from collections.abc import Callable
from pathlib import Path
from typing import Any, TypeVar
from ahriman.core.configuration import Configuration
from ahriman.core.log import LazyLogging
from ahriman.models.repository_id import RepositoryId
from ahriman.models.repository_paths import RepositoryPaths
T = TypeVar("T")
@ -39,16 +38,16 @@ class Operations(LazyLogging):
path(Path): path to the database file
"""
def __init__(self, path: Path, repository_id: RepositoryId, repository_paths: RepositoryPaths) -> None:
def __init__(self, path: Path, configuration: Configuration) -> None:
"""
Args:
path(Path): path to the database file
repository_id(RepositoryId): repository unique identifier
repository_paths(RepositoryPaths): repository paths
configuration(Configuration): configuration instance
"""
self.path = path
self._repository_id = repository_id
self._repository_paths = repository_paths
self._configuration = configuration
_, self._repository_id = configuration.check_loaded()
self._repository_paths = configuration.repository_paths
@property
def logger_name(self) -> str:

View File

@ -66,10 +66,9 @@ class SQLite(
Self: fully initialized instance of the database
"""
path = cls.database_path(configuration)
_, repository_id = configuration.check_loaded()
database = cls(path, repository_id, configuration.repository_paths)
database.init(configuration)
database = cls(path, configuration)
database.init()
return database
@ -86,23 +85,18 @@ class SQLite(
"""
return configuration.getpath("settings", "database")
def init(self, configuration: Configuration) -> None:
def init(self) -> None:
"""
perform database migrations
Args:
configuration(Configuration): configuration instance
"""
# custom types support
sqlite3.register_adapter(dict, json.dumps)
sqlite3.register_adapter(list, json.dumps)
sqlite3.register_converter("json", json.loads)
paths = configuration.repository_paths
if configuration.getboolean("settings", "apply_migrations", fallback=True):
self.with_connection(lambda connection: Migrations.migrate(connection, configuration))
paths.chown(self.path)
if self._configuration.getboolean("settings", "apply_migrations", fallback=True):
self.with_connection(lambda connection: Migrations.migrate(connection, self._configuration))
self._repository_paths.chown(self.path)
def package_clear(self, package_base: str, repository_id: RepositoryId | None = None) -> None:
"""

View File

@ -144,7 +144,8 @@ class UpdateHandler(PackageInfo, Cleaner):
branch="master",
)
Sources.fetch(cache_dir, source)
with self.suppress_logging():
Sources.fetch(cache_dir, source)
remote = Package.from_build(cache_dir, self.architecture, None)
local = packages.get(remote.base)

View File

@ -13,7 +13,7 @@ def test_load(configuration: Configuration, mocker: MockerFixture) -> None:
"""
init_mock = mocker.patch("ahriman.core.database.SQLite.init")
SQLite.load(configuration)
init_mock.assert_called_once_with(configuration)
init_mock.assert_called_once_with()
def test_init(database: SQLite, configuration: Configuration, mocker: MockerFixture) -> None:
@ -21,18 +21,18 @@ def test_init(database: SQLite, configuration: Configuration, mocker: MockerFixt
must run migrations on init
"""
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
database.init(configuration)
migrate_schema_mock.assert_called_once_with(pytest.helpers.anyvar(int), configuration)
database.init()
migrate_schema_mock.assert_called_once_with(pytest.helpers.anyvar(int), database._configuration)
def test_init_skip_migration(database: SQLite, configuration: Configuration, mocker: MockerFixture) -> None:
def test_init_skip_migration(database: SQLite, mocker: MockerFixture) -> None:
"""
must skip migrations if option is set
"""
configuration.set_option("settings", "apply_migrations", "no")
database._configuration.set_option("settings", "apply_migrations", "no")
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
database.init(configuration)
database.init()
migrate_schema_mock.assert_not_called()