mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-10-30 21:33:43 +00:00 
			
		
		
		
	more package propertieis
This commit is contained in:
		| @ -33,14 +33,18 @@ | |||||||
|                     <tr class="header"> |                     <tr class="header"> | ||||||
|                         <th>package</th> |                         <th>package</th> | ||||||
|                         <th>version</th> |                         <th>version</th> | ||||||
|  |                         <th>archive size</th> | ||||||
|                         <th>installed size</th> |                         <th>installed size</th> | ||||||
|  |                         <th>build date</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.archive_size|e }}</td> | ||||||
|                             <td>{{ package.installed_size|e }}</td> |                             <td>{{ package.installed_size|e }}</td> | ||||||
|  |                             <td>{{ package.build_date|e }}</td> | ||||||
|                         </tr> |                         </tr> | ||||||
|                     {% endfor %} |                     {% endfor %} | ||||||
|                 </table> |                 </table> | ||||||
|  | |||||||
| @ -17,13 +17,11 @@ | |||||||
| # You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||
| # | # | ||||||
| from __future__ import annotations |  | ||||||
|  |  | ||||||
| import logging | import logging | ||||||
| import os | import os | ||||||
| import shutil | import shutil | ||||||
|  |  | ||||||
| from typing import Callable, Iterable, List, Optional, Set, Type | from typing import Callable, Iterable, List, Optional, Set | ||||||
|  |  | ||||||
| from ahriman.core.build_tools.task import Task | from ahriman.core.build_tools.task import Task | ||||||
| from ahriman.core.configuration import Configuration | from ahriman.core.configuration import Configuration | ||||||
|  | |||||||
| @ -24,8 +24,8 @@ 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.core.util import pretty_size, pretty_datetime | ||||||
| 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 | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -39,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, installed_size, name, version. Required |         packages - sorted list of packages properties: archive_size, build_date, 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 | ||||||
|  |  | ||||||
| @ -85,8 +85,10 @@ class HTML(Report): | |||||||
|  |  | ||||||
|         content = [ |         content = [ | ||||||
|             { |             { | ||||||
|  |                 'archive_size': pretty_size(properties.archive_size), | ||||||
|  |                 'build_date': pretty_datetime(properties.build_date), | ||||||
|                 'filename': properties.filename, |                 'filename': properties.filename, | ||||||
|                 'installed_size': PackageDescription.size_to_str(properties.installed_size), |                 'installed_size': pretty_size(properties.installed_size), | ||||||
|                 'name': package, |                 'name': package, | ||||||
|                 'version': base.version |                 'version': base.version | ||||||
|             } for base in packages for package, properties in base.packages.items() |             } for base in packages for package, properties in base.packages.items() | ||||||
|  | |||||||
| @ -17,11 +17,14 @@ | |||||||
| # You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||
| # | # | ||||||
|  | import datetime | ||||||
| import subprocess | import subprocess | ||||||
|  |  | ||||||
| from logging import Logger | from logging import Logger | ||||||
| from typing import Optional | from typing import Optional | ||||||
|  |  | ||||||
|  | from ahriman.core.exceptions import InvalidOption | ||||||
|  |  | ||||||
|  |  | ||||||
| def check_output(*args: str, exception: Optional[Exception], | def check_output(*args: str, exception: Optional[Exception], | ||||||
|                  cwd: Optional[str] = None, stderr: int = subprocess.STDOUT, |                  cwd: Optional[str] = None, stderr: int = subprocess.STDOUT, | ||||||
| @ -55,3 +58,37 @@ def package_like(filename: str) -> bool: | |||||||
|     :return: True in case if name contains `.pkg.` and not signature, False otherwise |     :return: True in case if name contains `.pkg.` and not signature, False otherwise | ||||||
|     ''' |     ''' | ||||||
|     return '.pkg.' in filename and not filename.endswith('.sig') |     return '.pkg.' in filename and not filename.endswith('.sig') | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def pretty_datetime(timestamp: Optional[datetime.datetime]) -> str: | ||||||
|  |     ''' | ||||||
|  |     convert datetime object to string | ||||||
|  |     :param timestamp: datetime to convert | ||||||
|  |     :return: pretty printable datetime as string | ||||||
|  |     ''' | ||||||
|  |     return '' if timestamp is None else timestamp.strftime('%Y-%m-%d %H:%M:%S') | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def pretty_size(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)  # I hope it will not be more than 1024 GiB | ||||||
|  |  | ||||||
|  |     if size is None: | ||||||
|  |         return '' | ||||||
|  |     elif size < 1024: | ||||||
|  |         return f'{round(size, 2)} {str_level()}' | ||||||
|  |     return pretty_size(size / 1024, level + 1) | ||||||
|  | |||||||
| @ -70,11 +70,4 @@ class BuildStatus: | |||||||
|         :param timestamp: build status timestamp. Current timestamp will be used if not set |         :param timestamp: build status timestamp. Current timestamp will be used if not set | ||||||
|         ''' |         ''' | ||||||
|         self.status = BuildStatusEnum(status) if status else BuildStatusEnum.Unknown |         self.status = BuildStatusEnum(status) if status else BuildStatusEnum.Unknown | ||||||
|         self._timestamp = timestamp or datetime.datetime.utcnow() |         self.timestamp = timestamp or datetime.datetime.utcnow() | ||||||
|  |  | ||||||
|     @property |  | ||||||
|     def timestamp(self) -> str: |  | ||||||
|         ''' |  | ||||||
|         :return: string representation of build status timestamp |  | ||||||
|         ''' |  | ||||||
|         return self._timestamp.strftime('%Y-%m-%d %H:%M:%S') |  | ||||||
|  | |||||||
| @ -20,6 +20,7 @@ | |||||||
| from __future__ import annotations | from __future__ import annotations | ||||||
|  |  | ||||||
| import aur  # type: ignore | import aur  # type: ignore | ||||||
|  | import datetime | ||||||
| import os | import os | ||||||
|  |  | ||||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||||
| @ -108,7 +109,8 @@ class Package: | |||||||
|         :return: package properties |         :return: package properties | ||||||
|         ''' |         ''' | ||||||
|         package = pacman.handle.load_pkg(path) |         package = pacman.handle.load_pkg(path) | ||||||
|         properties = PackageDescription(os.path.basename(path), package.isize) |         build_date = datetime.datetime.fromtimestamp(package.builddate) | ||||||
|  |         properties = PackageDescription(package.size, build_date, os.path.basename(path), package.isize) | ||||||
|         return cls(package.base, package.version, aur_url, {package.name: properties}) |         return cls(package.base, package.version, aur_url, {package.name: properties}) | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|  | |||||||
| @ -17,41 +17,23 @@ | |||||||
| # You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||
| # | # | ||||||
|  | import datetime | ||||||
|  |  | ||||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||||
| from typing import Optional | from typing import Optional | ||||||
|  |  | ||||||
| from ahriman.core.exceptions import InvalidOption |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @dataclass | @dataclass | ||||||
| class PackageDescription: | class PackageDescription: | ||||||
|     ''' |     ''' | ||||||
|     package specific properties |     package specific properties | ||||||
|  |     :ivar archive_size: package archive size | ||||||
|  |     :ivar build_date: package build date | ||||||
|  |     :ivar filename: package archive name | ||||||
|  |     :ivar installed_size: package installed size | ||||||
|     ''' |     ''' | ||||||
|  |  | ||||||
|  |     archive_size: Optional[int] = None | ||||||
|  |     build_date: Optional[datetime.datetime] = None | ||||||
|     filename: Optional[str] = None |     filename: Optional[str] = None | ||||||
|     installed_size: Optional[int] = 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) |  | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ from ahriman.core.exceptions import InvalidOption | |||||||
| class ReportSettings(Enum): | class ReportSettings(Enum): | ||||||
|     ''' |     ''' | ||||||
|     report targets enumeration |     report targets enumeration | ||||||
|     :ivar HTML: html report generation |     :cvar HTML: html report generation | ||||||
|     ''' |     ''' | ||||||
|  |  | ||||||
|     HTML = auto() |     HTML = auto() | ||||||
|  | |||||||
| @ -27,8 +27,8 @@ from ahriman.core.exceptions import InvalidOption | |||||||
| class SignSettings(Enum): | class SignSettings(Enum): | ||||||
|     ''' |     ''' | ||||||
|     sign targets enumeration |     sign targets enumeration | ||||||
|     :ivar SignPackages: sign each package |     :cvar SignPackages: sign each package | ||||||
|     :ivar SignRepository: sign repository database file |     :cvar SignRepository: sign repository database file | ||||||
|     ''' |     ''' | ||||||
|  |  | ||||||
|     SignPackages = auto() |     SignPackages = auto() | ||||||
|  | |||||||
| @ -27,8 +27,8 @@ from ahriman.core.exceptions import InvalidOption | |||||||
| class UploadSettings(Enum): | class UploadSettings(Enum): | ||||||
|     ''' |     ''' | ||||||
|     remote synchronization targets enumeration |     remote synchronization targets enumeration | ||||||
|     :ivar Rsync: sync via rsync |     :cvar Rsync: sync via rsync | ||||||
|     :ivar S3: sync to Amazon S3 |     :cvar S3: sync to Amazon S3 | ||||||
|     ''' |     ''' | ||||||
|  |  | ||||||
|     Rsync = auto() |     Rsync = auto() | ||||||
|  | |||||||
| @ -23,6 +23,7 @@ from typing import Any, Dict | |||||||
|  |  | ||||||
| import ahriman.version as version | import ahriman.version as version | ||||||
|  |  | ||||||
|  | from ahriman.core.util import pretty_datetime | ||||||
| from ahriman.web.views.base import BaseView | from ahriman.web.views.base import BaseView | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -52,7 +53,7 @@ class IndexView(BaseView): | |||||||
|                 'base': package.base, |                 'base': package.base, | ||||||
|                 'packages': [p for p in sorted(package.packages)], |                 'packages': [p for p in sorted(package.packages)], | ||||||
|                 'status': status.status.value, |                 'status': status.status.value, | ||||||
|                 'timestamp': status.timestamp, |                 'timestamp': pretty_datetime(status.timestamp), | ||||||
|                 'version': package.version, |                 'version': package.version, | ||||||
|                 'web_url': package.web_url |                 'web_url': package.web_url | ||||||
|             } for package, status in sorted(self.service.packages, key=lambda item: item[0].base) |             } for package, status in sorted(self.service.packages, key=lambda item: item[0].base) | ||||||
| @ -60,7 +61,7 @@ class IndexView(BaseView): | |||||||
|         service = { |         service = { | ||||||
|             'status': self.service.status.status.value, |             'status': self.service.status.status.value, | ||||||
|             'status_color': self.service.status.status.badges_color(), |             'status_color': self.service.status.status.badges_color(), | ||||||
|             'timestamp': self.service.status.timestamp |             'timestamp': pretty_datetime(self.service.status.timestamp) | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return { |         return { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user