package module: add install button

parent 73d33c09
......@@ -76,12 +76,10 @@ class PackageInfo:
context = etree.iterparse(path, events=("end",), recover=True)
for _, elem in context:
if elem.tag == "component":
if elem.tag == "component" and elem.get("type") != "addon":
if elem.findtext("pkgname") == pkgname:
return elem.findtext("id")
elem.clear()
while elem.getprevious() is not None:
del elem.getparent()[0]
elem.clear()
return None
......
......@@ -30,7 +30,7 @@ DEFAUIL_BRANCHES = [
BUGS_URL = "https://bugzilla.altlinux.org/"
PACKAGES_URL = "https://packages.altlinux.org/ru/{repo}/"
CYBERTALK_URL = "https://lists.altlinux.org/pipermail/sisyphus-cybertalk/{}/"
INSTALL_APP_URL = "https://appstream.k8s.eterfund.ru/app/{app_id}/"
# ====== BOT
......
......@@ -2,6 +2,7 @@ from . import admin as admin_keyboards
from . import start as start_keyboards
from . import menu as menu_keyboards
from . import news as news_keyboards
from . import package as package_keyboards
from . import profile as profile_keyboards
from . import watch as watch_keyboards
from . import bugs as bugs_keyboards
from typing import List
from telegrinder import InlineKeyboard, InlineButton
from config import INSTALL_APP_URL
def appstream_install_app_kb(ids: List[str], names: List[str]):
kb = InlineKeyboard()
for app_id, name in zip(ids, names):
kb.add(InlineButton(
text=f"Установить {name}",
url=INSTALL_APP_URL.format(app_id=app_id)
))
kb.row()
return kb.get_markup()
......@@ -6,6 +6,7 @@ from datetime import datetime
from altrepo import altrepo
from altrepo.api.errors import DataNotFoundError, RequestValidationError
from data.keyboards import package_keyboards
from database.models import User
from database.func import DB
from services.utils import _bold
......@@ -59,6 +60,14 @@ async def package_info_handler(
if arch:
source_package = package.package_archs[0].name
appstream_id = altrepo.appstream.package.id_by_pkgname(
package.name, branch
)
if appstream_id:
appstream_ids = [appstream_id]
else:
appstream_ids = []
appstream_names = [package.name]
new_version = None
if not arch:
......@@ -70,6 +79,8 @@ async def package_info_handler(
f" Новая версия: {new_version[0].version}-{new_version[0].release}"
)
appstream_ids = []
appstream_names = []
binary_packages_message = _bold("\n\nБинарные пакеты:\n")
for i, binary_package in enumerate(package.package_archs):
if i == 15:
......@@ -77,6 +88,13 @@ async def package_info_handler(
break
binary_packages_message += f" {binary_package.name}"
binary_packages_message += f" ({", ".join(binary_package.archs)})\n"
app_id = altrepo.appstream.package.id_by_pkgname(
binary_package.name, branch
)
if app_id:
appstream_ids.append(app_id)
appstream_names.append(binary_package.name)
_package = DB.package.get(package.name)
summary = (
......@@ -99,4 +117,9 @@ async def package_info_handler(
f"{f"{binary_packages_message}" if not arch else ""}"
)
await m.answer(message)
await m.answer(
message,
reply_markup=package_keyboards.appstream_install_app_kb(
appstream_ids, appstream_names
) if appstream_ids else None
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment