mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-11 17:50:29 +03:00
metadata: make linkresolver an actual object
Previously this was magically capturing the apps dict when passing it around as a function. This also moved the code to the metadata module. Add a test doing read_metadata where the linkresolver is used. This happens when the apps we read have a [[app.id]] link to another app.
This commit is contained in:
parent
a4177e5ec3
commit
03881154c6
6 changed files with 1240 additions and 18 deletions
|
|
@ -58,11 +58,6 @@ def make(apps, sortedids, apks, repodir, archive):
|
|||
"""
|
||||
from fdroidserver.update import METADATA_VERSION
|
||||
|
||||
def _resolve_description_link(appid):
|
||||
if appid in apps:
|
||||
return "fdroid.app:" + appid, apps[appid].Name
|
||||
raise MetaDataException("Cannot resolve app id " + appid)
|
||||
|
||||
if not common.options.nosign:
|
||||
common.assert_config_keystore(common.config)
|
||||
|
||||
|
|
@ -117,7 +112,7 @@ def make(apps, sortedids, apks, repodir, archive):
|
|||
if apk['packageName'] == packageName:
|
||||
newapp = copy.copy(app) # update wiki needs unmodified description
|
||||
newapp['Description'] = metadata.description_html(app['Description'],
|
||||
_resolve_description_link)
|
||||
metadata.DescriptionResolver(apps))
|
||||
appsWithPackages[packageName] = newapp
|
||||
break
|
||||
|
||||
|
|
@ -311,11 +306,6 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
|
|||
value = str(apk[key])
|
||||
addElement(name, value, doc, parent)
|
||||
|
||||
def addElementCDATA(name, value, doc, parent):
|
||||
el = doc.createElement(name)
|
||||
el.appendChild(doc.createCDATASection(value))
|
||||
parent.appendChild(el)
|
||||
|
||||
def addElementCheckLocalized(name, app, key, doc, parent, default=''):
|
||||
"""Fill in field from metadata or localized block
|
||||
|
||||
|
|
|
|||
|
|
@ -616,7 +616,7 @@ class DescriptionFormatter:
|
|||
warn_or_exception(_("Unterminated ]]"))
|
||||
url = txt[2:index]
|
||||
if self.linkResolver:
|
||||
url, urltext = self.linkResolver(url)
|
||||
url, urltext = self.linkResolver.resolve_description_link(url)
|
||||
else:
|
||||
urltext = url
|
||||
res_html += '<a href="' + url + '">' + html.escape(urltext, quote=False) + '</a>'
|
||||
|
|
@ -899,14 +899,9 @@ def read_metadata(xref=True, check_vcs=[], refresh=True, sort_by_time=False):
|
|||
if xref:
|
||||
# Parse all descriptions at load time, just to ensure cross-referencing
|
||||
# errors are caught early rather than when they hit the build server.
|
||||
def linkres(appid):
|
||||
if appid in apps:
|
||||
return ("fdroid.app:" + appid, "Dummy name - don't know yet")
|
||||
warn_or_exception(_("Cannot resolve app id {appid}").format(appid=appid))
|
||||
|
||||
for appid, app in apps.items():
|
||||
try:
|
||||
description_html(app.Description, linkres)
|
||||
description_html(app.Description, DummyDescriptionResolver(apps))
|
||||
except MetaDataException as e:
|
||||
warn_or_exception(_("Problem with description of {appid}: {error}")
|
||||
.format(appid=appid, error=str(e)))
|
||||
|
|
@ -1679,3 +1674,21 @@ def add_metadata_arguments(parser):
|
|||
'''add common command line flags related to metadata processing'''
|
||||
parser.add_argument("-W", choices=['error', 'warn', 'ignore'], default='error',
|
||||
help=_("force metadata errors (default) to be warnings, or to be ignored."))
|
||||
|
||||
|
||||
class DescriptionResolver:
|
||||
def __init__(self, apps):
|
||||
self.apps = apps
|
||||
|
||||
def resolve_description_link(self, appid):
|
||||
if appid in self.apps:
|
||||
if self.apps[appid].Name:
|
||||
return "fdroid.app:" + appid, self.apps[appid].Name
|
||||
raise MetaDataException("Cannot resolve app id " + appid)
|
||||
|
||||
|
||||
class DummyDescriptionResolver(DescriptionResolver):
|
||||
def resolve_description_link(self, appid):
|
||||
if appid in self.apps:
|
||||
return "fdroid.app:" + appid, "Dummy name - don't know yet"
|
||||
warn_or_exception(_("Cannot resolve app id {appid}").format(appid=appid))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue