mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-08-29 04:49:57 +00:00
Compare commits
2 Commits
528d7ce398
...
f0930be238
Author | SHA1 | Date | |
---|---|---|---|
f0930be238 | |||
113a861f31 |
@ -91,9 +91,8 @@ class Pacman(LazyLogging):
|
|||||||
database = self.database_init(handle, repository, self.repository_id.architecture)
|
database = self.database_init(handle, repository, self.repository_id.architecture)
|
||||||
self.database_copy(handle, database, pacman_root, use_ahriman_cache=use_ahriman_cache)
|
self.database_copy(handle, database, pacman_root, use_ahriman_cache=use_ahriman_cache)
|
||||||
|
|
||||||
# install repository database too
|
# install repository database too (without copying)
|
||||||
local_database = self.database_init(handle, self.repository_id.name, self.repository_id.architecture)
|
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)
|
|
||||||
|
|
||||||
if use_ahriman_cache and refresh_database:
|
if use_ahriman_cache and refresh_database:
|
||||||
self.database_sync(handle, force=refresh_database == PacmanSynchronization.Force)
|
self.database_sync(handle, force=refresh_database == PacmanSynchronization.Force)
|
||||||
@ -115,6 +114,7 @@ class Pacman(LazyLogging):
|
|||||||
|
|
||||||
if not use_ahriman_cache:
|
if not use_ahriman_cache:
|
||||||
return
|
return
|
||||||
|
|
||||||
# copy root database if no local copy found
|
# copy root database if no local copy found
|
||||||
pacman_db_path = Path(handle.dbpath)
|
pacman_db_path = Path(handle.dbpath)
|
||||||
if not pacman_db_path.is_dir():
|
if not pacman_db_path.is_dir():
|
||||||
@ -123,11 +123,13 @@ class Pacman(LazyLogging):
|
|||||||
if dst.is_file():
|
if dst.is_file():
|
||||||
return # file already exists, do not copy
|
return # file already exists, do not copy
|
||||||
dst.parent.mkdir(mode=0o755, exist_ok=True) # create sync directory if it doesn't exist
|
dst.parent.mkdir(mode=0o755, exist_ok=True) # create sync directory if it doesn't exist
|
||||||
|
|
||||||
src = repository_database(pacman_root)
|
src = repository_database(pacman_root)
|
||||||
if not src.is_file():
|
if not src.is_file():
|
||||||
self.logger.warning("repository %s is set to be used, however, no working copy was found", database.name)
|
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
|
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)
|
shutil.copy(src, dst)
|
||||||
self.repository_paths.chown(dst)
|
self.repository_paths.chown(dst)
|
||||||
|
|
||||||
|
@ -23,9 +23,8 @@ from collections.abc import Callable
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, TypeVar
|
from typing import Any, TypeVar
|
||||||
|
|
||||||
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.log import LazyLogging
|
from ahriman.core.log import LazyLogging
|
||||||
from ahriman.models.repository_id import RepositoryId
|
|
||||||
from ahriman.models.repository_paths import RepositoryPaths
|
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
@ -39,16 +38,16 @@ class Operations(LazyLogging):
|
|||||||
path(Path): path to the database file
|
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:
|
Args:
|
||||||
path(Path): path to the database file
|
path(Path): path to the database file
|
||||||
repository_id(RepositoryId): repository unique identifier
|
configuration(Configuration): configuration instance
|
||||||
repository_paths(RepositoryPaths): repository paths
|
|
||||||
"""
|
"""
|
||||||
self.path = path
|
self.path = path
|
||||||
self._repository_id = repository_id
|
self._configuration = configuration
|
||||||
self._repository_paths = repository_paths
|
_, self._repository_id = configuration.check_loaded()
|
||||||
|
self._repository_paths = configuration.repository_paths
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logger_name(self) -> str:
|
def logger_name(self) -> str:
|
||||||
|
@ -66,10 +66,9 @@ class SQLite(
|
|||||||
Self: fully initialized instance of the database
|
Self: fully initialized instance of the database
|
||||||
"""
|
"""
|
||||||
path = cls.database_path(configuration)
|
path = cls.database_path(configuration)
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
|
|
||||||
database = cls(path, repository_id, configuration.repository_paths)
|
database = cls(path, configuration)
|
||||||
database.init(configuration)
|
database.init()
|
||||||
|
|
||||||
return database
|
return database
|
||||||
|
|
||||||
@ -86,23 +85,18 @@ class SQLite(
|
|||||||
"""
|
"""
|
||||||
return configuration.getpath("settings", "database")
|
return configuration.getpath("settings", "database")
|
||||||
|
|
||||||
def init(self, configuration: Configuration) -> None:
|
def init(self) -> None:
|
||||||
"""
|
"""
|
||||||
perform database migrations
|
perform database migrations
|
||||||
|
|
||||||
Args:
|
|
||||||
configuration(Configuration): configuration instance
|
|
||||||
"""
|
"""
|
||||||
# custom types support
|
# custom types support
|
||||||
sqlite3.register_adapter(dict, json.dumps)
|
sqlite3.register_adapter(dict, json.dumps)
|
||||||
sqlite3.register_adapter(list, json.dumps)
|
sqlite3.register_adapter(list, json.dumps)
|
||||||
sqlite3.register_converter("json", json.loads)
|
sqlite3.register_converter("json", json.loads)
|
||||||
|
|
||||||
paths = configuration.repository_paths
|
if self._configuration.getboolean("settings", "apply_migrations", fallback=True):
|
||||||
|
self.with_connection(lambda connection: Migrations.migrate(connection, self._configuration))
|
||||||
if configuration.getboolean("settings", "apply_migrations", fallback=True):
|
self._repository_paths.chown(self.path)
|
||||||
self.with_connection(lambda connection: Migrations.migrate(connection, configuration))
|
|
||||||
paths.chown(self.path)
|
|
||||||
|
|
||||||
def package_clear(self, package_base: str, repository_id: RepositoryId | None = None) -> None:
|
def package_clear(self, package_base: str, repository_id: RepositoryId | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -144,7 +144,8 @@ class UpdateHandler(PackageInfo, Cleaner):
|
|||||||
branch="master",
|
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)
|
remote = Package.from_build(cache_dir, self.architecture, None)
|
||||||
|
|
||||||
local = packages.get(remote.base)
|
local = packages.get(remote.base)
|
||||||
|
@ -13,7 +13,7 @@ def test_load(configuration: Configuration, mocker: MockerFixture) -> None:
|
|||||||
"""
|
"""
|
||||||
init_mock = mocker.patch("ahriman.core.database.SQLite.init")
|
init_mock = mocker.patch("ahriman.core.database.SQLite.init")
|
||||||
SQLite.load(configuration)
|
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:
|
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
|
must run migrations on init
|
||||||
"""
|
"""
|
||||||
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
|
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
|
||||||
database.init(configuration)
|
database.init()
|
||||||
migrate_schema_mock.assert_called_once_with(pytest.helpers.anyvar(int), configuration)
|
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
|
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")
|
migrate_schema_mock = mocker.patch("ahriman.core.database.migrations.Migrations.migrate")
|
||||||
|
|
||||||
database.init(configuration)
|
database.init()
|
||||||
migrate_schema_mock.assert_not_called()
|
migrate_schema_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user