-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add counters to repository stats overview
- Loading branch information
Showing
26 changed files
with
519 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# | ||
# Copyright (c) 2021-2025 ahriman team. | ||
# | ||
# This file is part of ahriman | ||
# (see https://github.com/arcan1s/ahriman). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
from ahriman.core.formatters.string_printer import StringPrinter | ||
from ahriman.core.utils import pretty_size | ||
from ahriman.models.property import Property | ||
from ahriman.models.repository_id import RepositoryId | ||
from ahriman.models.repository_stats import RepositoryStats | ||
|
||
|
||
class RepositoryStatsPrinter(StringPrinter): | ||
""" | ||
print repository statistics | ||
Attributes: | ||
statistics(RepositoryStats): repository statistics | ||
""" | ||
|
||
def __init__(self, repository_id: RepositoryId, statistics: RepositoryStats) -> None: | ||
""" | ||
Args: | ||
statistics(RepositoryStats): repository statistics | ||
""" | ||
StringPrinter.__init__(self, str(repository_id)) | ||
self.statistics = statistics | ||
|
||
def properties(self) -> list[Property]: | ||
""" | ||
convert content into printable data | ||
Returns: | ||
list[Property]: list of content properties | ||
""" | ||
return [ | ||
Property("Packages", self.statistics.bases), | ||
Property("Repository size", pretty_size(self.statistics.archive_size)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# | ||
# Copyright (c) 2021-2025 ahriman team. | ||
# | ||
# This file is part of ahriman | ||
# (see https://github.com/arcan1s/ahriman). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
from dataclasses import dataclass, fields | ||
from typing import Any, Self | ||
|
||
from ahriman.core.utils import filter_json | ||
from ahriman.models.package import Package | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class RepositoryStats: | ||
""" | ||
repository stats representation | ||
""" | ||
|
||
bases: int | ||
packages: int | ||
archive_size: int | ||
installed_size: int | ||
|
||
@classmethod | ||
def from_json(cls, dump: dict[str, Any]) -> Self: | ||
""" | ||
construct counters from json dump | ||
Args: | ||
dump(dict[str, Any]): json dump body | ||
Returns: | ||
Self: status counters | ||
""" | ||
# filter to only known fields | ||
known_fields = [pair.name for pair in fields(cls)] | ||
return cls(**filter_json(dump, known_fields)) | ||
|
||
@classmethod | ||
def from_packages(cls, packages: list[Package]) -> Self: | ||
""" | ||
construct statistics from list of repository packages | ||
Args: | ||
packages(list[Packages]): list of repository packages | ||
Returns: | ||
Self: constructed statistics object | ||
""" | ||
return cls( | ||
bases=len(packages), | ||
packages=sum(len(package.packages) for package in packages), | ||
archive_size=sum( | ||
archive.archive_size or 0 | ||
for package in packages | ||
for archive in package.packages.values() | ||
), | ||
installed_size=sum( | ||
archive.installed_size or 0 | ||
for package in packages | ||
for archive in package.packages.values() | ||
), | ||
) |
Oops, something went wrong.