add information about installed size

This commit is contained in:
Evgenii Alekseev 2021-03-15 03:54:52 +03:00
parent 374b3febc8
commit 0fcb46afca
4 changed files with 71 additions and 8 deletions

View File

@ -33,12 +33,14 @@
<tr class="header"> <tr class="header">
<th>package</th> <th>package</th>
<th>version</th> <th>version</th>
<th>installed size</th>
</tr> </tr>
{% for package in packages %} {% for package in packages %}
<tr class="package"> <tr class="package">
<td class="include-search"><a href="{{ link_path|e }}/{{ package.filename|e }}" title="{{ package.name|e }}">{{ package.name|e }}</a></td> <td class="include-search"><a href="{{ link_path|e }}/{{ package.filename|e }}" title="{{ package.name|e }}">{{ package.name|e }}</a></td>
<td>{{ package.version|e }}</td> <td>{{ package.version|e }}</td>
<td>{{ package.installed_size|e }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -25,6 +25,7 @@ from typing import Callable, Dict, Iterable
from ahriman.core.configuration import Configuration from ahriman.core.configuration import Configuration
from ahriman.core.report.report import Report from ahriman.core.report.report import Report
from ahriman.models.package import Package from ahriman.models.package import Package
from ahriman.models.package_desciption import PackageDescription
from ahriman.models.sign_settings import SignSettings from ahriman.models.sign_settings import SignSettings
@ -38,7 +39,7 @@ class HTML(Report):
link_path - prefix fo packages to download, string, required link_path - prefix fo packages to download, string, required
has_package_signed - True in case if package sign enabled, False otherwise, required has_package_signed - True in case if package sign enabled, False otherwise, required
has_repo_signed - True in case if repository database sign enabled, False otherwise, required has_repo_signed - True in case if repository database sign enabled, False otherwise, required
packages - sorted list of packages properties: filename, name, version. Required packages - sorted list of packages properties: filename, installed_size, name, version. Required
pgp_key - default PGP key ID, string, optional pgp_key - default PGP key ID, string, optional
repository - repository name, string, required repository - repository name, string, required
@ -84,10 +85,11 @@ class HTML(Report):
content = [ content = [
{ {
'filename': filename, 'filename': properties.filename,
'installed_size': PackageDescription.size_to_str(properties.installed_size),
'name': package, 'name': package,
'version': base.version 'version': base.version
} for base in packages for package, filename in base.packages.items() } for base in packages for package, properties in base.packages.items()
] ]
comparator: Callable[[Dict[str, str]], str] = lambda item: item['filename'] comparator: Callable[[Dict[str, str]], str] = lambda item: item['filename']

View File

@ -32,6 +32,7 @@ from typing import Dict, List, Optional, Set, Type
from ahriman.core.alpm.pacman import Pacman from ahriman.core.alpm.pacman import Pacman
from ahriman.core.exceptions import InvalidPackageInfo from ahriman.core.exceptions import InvalidPackageInfo
from ahriman.core.util import check_output from ahriman.core.util import check_output
from ahriman.models.package_desciption import PackageDescription
@dataclass @dataclass
@ -40,14 +41,14 @@ class Package:
package properties representation package properties representation
:ivar aurl_url: AUR root url :ivar aurl_url: AUR root url
:ivar base: package base name :ivar base: package base name
:ivar packages: map of package names to archive name :ivar packages: map of package names to their properties. Filled only on load from archive
:ivar version: package full version :ivar version: package full version
''' '''
base: str base: str
version: str version: str
aur_url: str aur_url: str
packages: Dict[str, str] packages: Dict[str, PackageDescription]
@property @property
def git_url(self) -> str: def git_url(self) -> str:
@ -110,7 +111,8 @@ class Package:
:return: package properties :return: package properties
''' '''
package = pacman.handle.load_pkg(path) package = pacman.handle.load_pkg(path)
return cls(package.base, package.version, aur_url, {package.name: os.path.basename(path)}) properties = PackageDescription(os.path.basename(path), package.isize)
return cls(package.base, package.version, aur_url, {package.name: properties})
@classmethod @classmethod
def from_aur(cls: Type[Package], name: str, aur_url: str) -> Package: def from_aur(cls: Type[Package], name: str, aur_url: str) -> Package:
@ -121,7 +123,7 @@ class Package:
:return: package properties :return: package properties
''' '''
package = aur.info(name) package = aur.info(name)
return cls(package.package_base, package.version, aur_url, {package.name: ''}) return cls(package.package_base, package.version, aur_url, {package.name: PackageDescription()})
@classmethod @classmethod
def from_build(cls: Type[Package], path: str, aur_url: str) -> Package: def from_build(cls: Type[Package], path: str, aur_url: str) -> Package:
@ -135,7 +137,7 @@ class Package:
src_info, errors = parse_srcinfo(fn.read()) src_info, errors = parse_srcinfo(fn.read())
if errors: if errors:
raise InvalidPackageInfo(errors) raise InvalidPackageInfo(errors)
packages = {key: '' for key in src_info['packages'].keys()} packages = {key: PackageDescription() for key in src_info['packages'].keys()}
version = cls.full_version(src_info.get('epoch'), src_info['pkgver'], src_info['pkgrel']) version = cls.full_version(src_info.get('epoch'), src_info['pkgver'], src_info['pkgrel'])
return cls(src_info['pkgbase'], version, aur_url, packages) return cls(src_info['pkgbase'], version, aur_url, packages)

View File

@ -0,0 +1,57 @@
#
# Copyright (c) 2021 Evgenii Alekseev.
#
# 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
from typing import Optional
from ahriman.core.exceptions import InvalidOption
@dataclass
class PackageDescription:
'''
package specific properties
'''
filename: Optional[str] = None
installed_size: Optional[int] = None
@staticmethod
def size_to_str(size: Optional[float], level: int = 0) -> str:
'''
convert size to string
:param size: size to convert
:param level: represents current units, 0 is B, 1 is KiB etc
:return: pretty printable size as string
'''
def str_level() -> str:
if level == 0:
return 'B'
elif level == 1:
return 'KiB'
elif level == 2:
return 'MiB'
elif level == 3:
return 'GiB'
raise InvalidOption(level)
if size is None:
return ''
elif size < 1024:
return f'{round(size, 2)} {str_level()}'
return PackageDescription.size_to_str(size / 1024, level + 1)