Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
arcan1s committed May 20, 2024
1 parent 13c063c commit 2dd6c12
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/ahriman/core/log/http_log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import Self

from ahriman.core.configuration import Configuration
from ahriman.core.status import Client
from ahriman.models.repository_id import RepositoryId


Expand Down Expand Up @@ -49,8 +50,6 @@ def __init__(self, repository_id: RepositoryId, configuration: Configuration, *,
# we don't really care about those parameters because they will be handled by the reporter
logging.Handler.__init__(self)

# client has to be imported here because of circular imports
from ahriman.core.status import Client
self.reporter = Client.load(repository_id, configuration, report=report)
self.suppress_errors = suppress_errors

Expand Down
7 changes: 4 additions & 3 deletions src/ahriman/core/repository/package_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ def load_archives(self, packages: Iterable[Path]) -> list[Package]:
Returns:
list[Package]: list of read packages
"""
sources = {package.base: package.remote for package, _, in self.reporter.package_get(None)}

result: dict[str, Package] = {}
# we are iterating over bases, not single packages
for full_path in packages:
try:
local = Package.from_archive(full_path, self.pacman)
remote, _ = next(iter(self.reporter.package_get(local.base)), (None, None))
if remote is not None: # update source with remote
local.remote = remote.remote
if (source := sources.get(local.base)) is not None: # update source with remote
local.remote = source

current = result.setdefault(local.base, local)
if current.version != local.version:
Expand Down
3 changes: 3 additions & 0 deletions src/ahriman/web/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ahriman.core.auth import Auth
from ahriman.core.configuration import Configuration
from ahriman.core.distributed import WorkersCache
from ahriman.core.exceptions import UnknownPackageError
from ahriman.core.sign.gpg import GPG
from ahriman.core.spawn import Spawn
from ahriman.core.status.watcher import Watcher
Expand Down Expand Up @@ -238,6 +239,8 @@ def service(self, repository_id: RepositoryId | None = None, package_base: str |
return self.services[repository_id](package_base)
except KeyError:
raise HTTPNotFound(reason=f"Repository {repository_id.id} is unknown")
except UnknownPackageError:
raise HTTPNotFound(reason=f"Package {package_base} is unknown")

async def username(self) -> str | None:
"""
Expand Down
8 changes: 2 additions & 6 deletions src/ahriman/web/views/v1/packages/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
#
import aiohttp_apispec # type: ignore[import-untyped]

from aiohttp.web import HTTPBadRequest, HTTPNoContent, HTTPNotFound, Response, json_response
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response

from ahriman.core.exceptions import UnknownPackageError
from ahriman.models.changes import Changes
from ahriman.models.user_access import UserAccess
from ahriman.web.schemas import AuthSchema, ChangesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
Expand Down Expand Up @@ -70,10 +69,7 @@ async def get(self) -> Response:
"""
package_base = self.request.match_info["package"]

try:
changes = self.service(package_base=package_base).package_changes_get(package_base)
except UnknownPackageError:
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
changes = self.service(package_base=package_base).package_changes_get(package_base)

return json_response(changes.view())

Expand Down
13 changes: 3 additions & 10 deletions src/ahriman/web/views/v1/packages/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
#
import aiohttp_apispec # type: ignore[import-untyped]

from aiohttp.web import HTTPBadRequest, HTTPNoContent, HTTPNotFound, Response, json_response
from aiohttp.web import HTTPBadRequest, HTTPNoContent, Response, json_response

from ahriman.core.exceptions import UnknownPackageError
from ahriman.models.dependencies import Dependencies
from ahriman.models.user_access import UserAccess
from ahriman.web.schemas import AuthSchema, DependenciesSchema, ErrorSchema, PackageNameSchema, RepositoryIdSchema
Expand Down Expand Up @@ -70,10 +69,7 @@ async def get(self) -> Response:
"""
package_base = self.request.match_info["package"]

try:
dependencies = self.service(package_base=package_base).package_dependencies_get(package_base)
except UnknownPackageError:
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
dependencies = self.service(package_base=package_base).package_dependencies_get(package_base)

return json_response(dependencies.view())

Expand Down Expand Up @@ -112,9 +108,6 @@ async def post(self) -> None:
except Exception as ex:
raise HTTPBadRequest(reason=str(ex))

try:
self.service(package_base=package_base).package_dependencies_update(package_base, dependencies)
except UnknownPackageError:
raise HTTPNotFound(reason=f"Package {package_base} is unknown")
self.service(package_base=package_base).package_dependencies_update(package_base, dependencies)

raise HTTPNoContent
1 change: 1 addition & 0 deletions src/ahriman/web/views/v1/packages/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def delete(self) -> None:
"""
package_base = self.request.match_info["package"]
variable = self.request.match_info["patch"]

self.service().package_patches_remove(package_base, variable)

raise HTTPNoContent
Expand Down
9 changes: 3 additions & 6 deletions src/ahriman/web/views/v2/packages/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
#
import aiohttp_apispec # type: ignore[import-untyped]

from aiohttp.web import HTTPNotFound, Response, json_response
from aiohttp.web import Response, json_response

from ahriman.core.exceptions import UnknownPackageError
from ahriman.models.user_access import UserAccess
from ahriman.web.schemas import AuthSchema, ErrorSchema, LogSchema, PackageNameSchema, PaginationSchema
from ahriman.web.views.base import BaseView
Expand Down Expand Up @@ -68,10 +67,8 @@ async def get(self) -> Response:
"""
package_base = self.request.match_info["package"]
limit, offset = self.page()
try:
logs = self.service(package_base=package_base).package_logs_get(package_base, limit, offset)
except UnknownPackageError:
raise HTTPNotFound(reason=f"Package {package_base} is unknown")

logs = self.service(package_base=package_base).package_logs_get(package_base, limit, offset)

response = [
{
Expand Down
3 changes: 1 addition & 2 deletions tests/ahriman/web/views/test_view_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from unittest.mock import AsyncMock

from ahriman.core.configuration import Configuration
from ahriman.core.exceptions import UnknownPackageError
from ahriman.models.repository_id import RepositoryId
from ahriman.models.user_access import UserAccess
from ahriman.web.keys import WatcherKey
Expand Down Expand Up @@ -210,7 +209,7 @@ def test_service_package(base: BaseView, repository_id: RepositoryId, mocker: Mo
must validate that package exists
"""
mocker.patch("ahriman.web.views.base.BaseView.repository_id", return_value=repository_id)
with pytest.raises(UnknownPackageError):
with pytest.raises(HTTPNotFound):
base.service(package_base="base")


Expand Down

0 comments on commit 2dd6c12

Please sign in to comment.