Compare commits

...

2 Commits

9 changed files with 44 additions and 13 deletions

View File

@ -1,5 +1,5 @@
[loggers] [loggers]
keys = root,http,stderr,boto3,botocore,nose,s3transfer keys = root,http,stderr,boto3,botocore,nose,s3transfer,sql
[handlers] [handlers]
keys = console_handler,journald_handler,syslog_handler keys = console_handler,journald_handler,syslog_handler
@ -64,3 +64,8 @@ propagate = 0
level = INFO level = INFO
qualname = s3transfer qualname = s3transfer
propagate = 0 propagate = 0
[logger_sql]
level = INFO
qualname = sql
propagate = 0

View File

@ -43,7 +43,7 @@ class Pacman(LazyLogging):
configuration(Configuration): configuration instance configuration(Configuration): configuration instance
refresh_database(PacmanSynchronization): synchronize local cache to remote refresh_database(PacmanSynchronization): synchronize local cache to remote
repository_id(RepositoryId): repository unique identifier repository_id(RepositoryId): repository unique identifier
repository_path(RepositoryPaths): repository paths instance repository_paths(RepositoryPaths): repository paths instance
""" """
def __init__(self, repository_id: RepositoryId, configuration: Configuration, *, def __init__(self, repository_id: RepositoryId, configuration: Configuration, *,
@ -188,8 +188,8 @@ class Pacman(LazyLogging):
Returns: Returns:
dict[str, set[str]]: map of package name to its list of files dict[str, set[str]]: map of package name to its list of files
""" """
def extract(tar: tarfile.TarFile, package_names: dict[str, str]) -> Generator[tuple[str, set[str]], None, None]: def extract(tar: tarfile.TarFile, versions: dict[str, str]) -> Generator[tuple[str, set[str]], None, None]:
for package_name, version in package_names.items(): for package_name, version in versions.items():
path = Path(f"{package_name}-{version}") / "files" path = Path(f"{package_name}-{version}") / "files"
try: try:
content = tar.extractfile(str(path)) content = tar.extractfile(str(path))

View File

@ -59,7 +59,8 @@ class PacmanDatabase(SyncHttpClient):
self.sync_files_database = configuration.getboolean("alpm", "sync_files_database") self.sync_files_database = configuration.getboolean("alpm", "sync_files_database")
def copy(self, remote_path: Path, local_path: Path) -> None: @staticmethod
def copy(remote_path: Path, local_path: Path) -> None:
""" """
copy local database file copy local database file

View File

@ -46,11 +46,22 @@ class Operations(LazyLogging):
Args: Args:
path(Path): path to the database file path(Path): path to the database file
repository_id(RepositoryId): repository unique identifier repository_id(RepositoryId): repository unique identifier
repository_paths(RepositoryPaths): repository paths
""" """
self.path = path self.path = path
self._repository_id = repository_id self._repository_id = repository_id
self._repository_paths = repository_paths self._repository_paths = repository_paths
@property
def logger_name(self) -> str:
"""
extract logger name for the class
Returns:
str: logger name override
"""
return "sql"
@staticmethod @staticmethod
def factory(cursor: sqlite3.Cursor, row: tuple[Any, ...]) -> dict[str, Any]: def factory(cursor: sqlite3.Cursor, row: tuple[Any, ...]) -> dict[str, Any]:
""" """
@ -80,6 +91,7 @@ class Operations(LazyLogging):
T: result of the ``query`` call T: result of the ``query`` call
""" """
with sqlite3.connect(self.path, detect_types=sqlite3.PARSE_DECLTYPES) as connection: with sqlite3.connect(self.path, detect_types=sqlite3.PARSE_DECLTYPES) as connection:
connection.set_trace_callback(self.logger.debug)
connection.row_factory = self.factory connection.row_factory = self.factory
result = query(connection) result = query(connection)
if commit: if commit:

View File

@ -342,7 +342,7 @@ class Client:
def set_unknown(self, package: Package) -> None: def set_unknown(self, package: Package) -> None:
""" """
set package status to unknown. Unlike other methods, this method also checks if package is known, set package status to unknown. Unlike other methods, this method also checks if package is known,
and - in case if it is - it silently skips updatd and - in case if it is - it silently skips update
Args: Args:
package(Package): current package properties package(Package): current package properties

View File

@ -113,7 +113,7 @@ class RepositoryPaths(LazyLogging):
Returns: Returns:
Path: full patch to devtools chroot directory Path: full patch to devtools chroot directory
""" """
# for the chroot directory devtools will create own tree, and we don"t have to specify architecture here # for the chroot directory devtools will create own tree, and we don't have to specify architecture here
return self.root / "chroot" / self.repository_id.name return self.root / "chroot" / self.repository_id.name
@property @property

View File

@ -8,12 +8,12 @@ from ahriman.core.alpm.pacman_database import PacmanDatabase
from ahriman.core.exceptions import PacmanError from ahriman.core.exceptions import PacmanError
def test_copy(pacman_database: PacmanDatabase, mocker: MockerFixture) -> None: def test_copy(mocker: MockerFixture) -> None:
""" """
must copy loca database file must copy loca database file
""" """
copy_mock = mocker.patch("shutil.copy") copy_mock = mocker.patch("shutil.copy")
pacman_database.copy(Path("remote"), Path("local")) PacmanDatabase.copy(Path("remote"), Path("local"))
copy_mock.assert_called_once_with(Path("remote"), Path("local")) copy_mock.assert_called_once_with(Path("remote"), Path("local"))

View File

@ -6,6 +6,13 @@ from unittest.mock import MagicMock
from ahriman.core.database import SQLite from ahriman.core.database import SQLite
def test_logger_name(database: SQLite) -> None:
"""
must return correct logger name
"""
assert database.logger_name == "sql"
def test_factory(database: SQLite) -> None: def test_factory(database: SQLite) -> None:
""" """
must convert response to dictionary must convert response to dictionary
@ -24,6 +31,7 @@ def test_with_connection(database: SQLite, mocker: MockerFixture) -> None:
database.with_connection(lambda conn: conn.execute("select 1")) database.with_connection(lambda conn: conn.execute("select 1"))
connect_mock.assert_called_once_with(database.path, detect_types=sqlite3.PARSE_DECLTYPES) connect_mock.assert_called_once_with(database.path, detect_types=sqlite3.PARSE_DECLTYPES)
connection_mock.__enter__().set_trace_callback.assert_called_once_with(database.logger.debug)
connection_mock.__enter__().commit.assert_not_called() connection_mock.__enter__().commit.assert_not_called()

View File

@ -4,17 +4,19 @@ import pytest
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
from ahriman.core.alpm.repo import Repo from ahriman.core.alpm.repo import Repo
from ahriman.core.build_tools.task import Task
from ahriman.core.database import SQLite from ahriman.core.database import SQLite
from ahriman.models.log_record_id import LogRecordId from ahriman.models.log_record_id import LogRecordId
from ahriman.models.package import Package from ahriman.models.package import Package
def test_logger_name(database: SQLite, repo: Repo) -> None: def test_logger_name(database: SQLite, repo: Repo, task_ahriman: Task) -> None:
""" """
must correctly generate logger name must correctly generate logger name
""" """
assert database.logger_name == "ahriman.core.database.sqlite.SQLite" assert database.logger_name == "sql"
assert repo.logger_name == "ahriman.core.alpm.repo.Repo" assert repo.logger_name == "ahriman.core.alpm.repo.Repo"
assert task_ahriman.logger_name == "ahriman.core.build_tools.task.Task"
def test_package_logger_set_reset(database: SQLite) -> None: def test_package_logger_set_reset(database: SQLite) -> None:
@ -75,9 +77,12 @@ def test_in_package_context_failed(database: SQLite, package_ahriman: Package, m
reset_mock.assert_called_once_with() reset_mock.assert_called_once_with()
def test_logger(database: SQLite) -> None: def test_logger(database: SQLite, repo: Repo) -> None:
""" """
must set logger attribute must set logger attribute
""" """
assert database.logger assert database.logger
assert database.logger.name == "ahriman.core.database.sqlite.SQLite" assert database.logger.name == "sql"
assert repo.logger
assert repo.logger.name == "ahriman.core.alpm.repo.Repo"