Skip to content

Commit

Permalink
pkginfo: Fall back to html2text if the appstream library doesn't
Browse files Browse the repository at this point in the history
contain AppStream.markup_convert().
  • Loading branch information
mtwebster committed Jul 26, 2024
1 parent e979400 commit 0cf1313
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Depends: python3,
python3-aptdaemon,
python3-aptdaemon.gtk3widgets,
python3-gi,
python3-html2text,
gir1.2-gtk-3.0,
gir1.2-xapp-1.0,
gir1.2-appstream-1.0,
Expand Down
19 changes: 14 additions & 5 deletions usr/lib/python3/dist-packages/mintcommon/installer/pkgInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
if sys.version_info.major < 3:
raise "python3 required"
import os
import html2text

import gi
gi.require_version("AppStream", "1.0")
gi.require_version("Gtk", "3.0")
from gi.repository import AppStream, Gtk

from .misc import warn

# this should hopefully be supplied by remote info someday.
FLATHUB_MEDIA_BASE_URL = "https://dl.flathub.org/media/"

Expand Down Expand Up @@ -365,6 +368,16 @@ def get_summary(self, as_component=None):

return self.summary

def as_markup_convert(self, markup):
try:
return AppStream.markup_convert(markup, AppStream.MarkupKind.TEXT)
except:
try:
return html2text.html2text(markup)
except Exception as e:
warn("Could not convert description to text: %s" % str(e))
return markup

def get_description(self, as_component=None):
# fastest
if self.description:
Expand All @@ -374,11 +387,7 @@ def get_description(self, as_component=None):
description = as_component.get_description()

if description is not None:
try:
self.description = AppStream.markup_convert(description, AppStream.MarkupKind.TEXT)
except GLib.Error as e:
warn("Could not convert description to text: %s" % e.message)
self.description = description
self.description = self.as_markup_convert(description)

if self.description is None:
return ""
Expand Down

0 comments on commit 0cf1313

Please sign in to comment.