Drop code for the old wiki

This commit is contained in:
Jochen Sprickerhof 2021-11-16 14:28:38 +01:00
parent 6952a23c47
commit b6f1f4231a
9 changed files with 3 additions and 409 deletions

View file

@ -199,236 +199,6 @@ def status_update_json(apps, apks):
common.write_status_json(output, options.pretty)
def update_wiki(apps, apks):
"""Update the wiki.
Parameters
----------
apps
fully populated list of all applications
apks
all apks, except...
"""
logging.info("Updating wiki")
wikicat = 'Apps'
wikiredircat = 'App Redirects'
import mwclient
site = mwclient.Site((config['wiki_protocol'], config['wiki_server']),
path=config['wiki_path'])
site.login(config['wiki_user'], config['wiki_password'])
generated_pages = {}
generated_redirects = {}
for appid in apps:
app = metadata.App(apps[appid])
wikidata = ''
if app.Disabled:
wikidata += '{{Disabled|' + app.Disabled + '}}\n'
if app.AntiFeatures:
for af in sorted(app.AntiFeatures):
wikidata += '{{AntiFeature|' + af + '}}\n'
if app.RequiresRoot:
requiresroot = 'Yes'
else:
requiresroot = 'No'
apppagename = common.get_app_display_name(app)
wikidata += '{{App|id=%s|name=%s|added=%s|lastupdated=%s|source=%s|tracker=%s|web=%s|changelog=%s|donate=%s|flattr=%s|liberapay=%s|bitcoin=%s|litecoin=%s|license=%s|root=%s|author=%s|email=%s}}\n' % (
appid,
apppagename,
app.added.strftime('%Y-%m-%d') if app.added else '',
app.lastUpdated.strftime('%Y-%m-%d') if app.lastUpdated else '',
app.SourceCode,
app.IssueTracker,
app.WebSite,
app.Changelog,
app.Donate,
app.FlattrID,
app.LiberapayID,
app.Bitcoin,
app.Litecoin,
app.License,
requiresroot,
app.AuthorName,
app.AuthorEmail)
if app.Provides:
wikidata += "This app provides: %s" % ', '.join(app.Summary.split(','))
wikidata += app.Summary
wikidata += " - [https://f-droid.org/repository/browse/?fdid=" + appid + " view in repository]\n\n"
wikidata += "=Description=\n"
wikidata += app.Description + "\n"
wikidata += "=Maintainer Notes=\n"
if app.MaintainerNotes:
wikidata += app.MaintainerNotes + "\n"
wikidata += "\nMetadata: [https://gitlab.com/fdroid/fdroiddata/blob/master/metadata/{0}.yml current] [https://gitlab.com/fdroid/fdroiddata/commits/master/metadata/{0}.yml history]\n".format(appid)
# Get a list of all packages for this application...
apklist = []
gotcurrentver = False
cantupdate = False
buildfails = False
for apk in apks:
if apk['packageName'] == appid:
if str(apk['versionCode']) == app.get('CurrentVersionCode'):
gotcurrentver = True
apklist.append(apk)
# Include ones we can't build, as a special case...
for build in app.get('Builds', []):
if build.disable:
if build.versionCode == app.get('CurrentVersionCode'):
cantupdate = True
# TODO: Nasty: vercode is a string in the build, and an int elsewhere
apklist.append({'versionCode': int(build.versionCode),
'versionName': build.versionName,
'buildproblem': "The build for this version was manually disabled. Reason: {0}".format(build.disable),
})
else:
builtit = False
for apk in apklist:
if apk['versionCode'] == int(build.versionCode):
builtit = True
break
if not builtit:
buildfails = True
apklist.append({'versionCode': int(build.versionCode),
'versionName': build.versionName,
'buildproblem': "The build for this version appears to have failed. Check the [[{0}/lastbuild_{1}|build log]].".format(appid, build.versionCode),
})
if app.get('CurrentVersionCode') == '0':
cantupdate = True
# Sort with most recent first...
apklist = sorted(apklist, key=lambda apk: apk['versionCode'], reverse=True)
wikidata += "=Versions=\n"
if len(apklist) == 0:
wikidata += "We currently have no versions of this app available."
elif not gotcurrentver:
wikidata += "We don't have the current version of this app."
else:
wikidata += "We have the current version of this app."
wikidata += " (Check mode: " + app.UpdateCheckMode + ") "
wikidata += " (Auto-update mode: " + app.AutoUpdateMode + ")\n\n"
if len(app.NoSourceSince) > 0:
wikidata += "This application has partially or entirely been missing source code since version " + app.NoSourceSince + ".\n\n"
if len(app.CurrentVersion) > 0:
wikidata += "The current (recommended) version is " + app.CurrentVersion
wikidata += " (version code " + app.CurrentVersionCode + ").\n\n"
validapks = 0
for apk in apklist:
wikidata += "==" + apk['versionName'] + "==\n"
if 'buildproblem' in apk:
wikidata += "We can't build this version: " + apk['buildproblem'] + "\n\n"
else:
validapks += 1
wikidata += "This version is built and signed by "
if 'srcname' in apk:
wikidata += "F-Droid, and guaranteed to correspond to the source tarball published with it.\n\n"
else:
wikidata += "the original developer.\n\n"
wikidata += "Version code: " + str(apk['versionCode']) + '\n'
wikidata += '\n[[Category:' + wikicat + ']]\n'
if len(app.NoSourceSince) > 0:
wikidata += '\n[[Category:Apps missing source code]]\n'
if validapks == 0 and not app.Disabled:
wikidata += '\n[[Category:Apps with no packages]]\n'
if cantupdate and not app.Disabled:
wikidata += "\n[[Category:Apps we cannot update]]\n"
if buildfails and not app.Disabled:
wikidata += "\n[[Category:Apps with failing builds]]\n"
elif not gotcurrentver and not cantupdate and not app.Disabled and app.UpdateCheckMode != "Static":
wikidata += '\n[[Category:Apps to Update]]\n'
if app.Disabled:
wikidata += '\n[[Category:Apps that are disabled]]\n'
if app.UpdateCheckMode == 'None' and not app.Disabled:
wikidata += '\n[[Category:Apps with no update check]]\n'
for appcat in app.Categories:
wikidata += '\n[[Category:{0}]]\n'.format(appcat)
# We can't have underscores in the page name, even if they're in
# the package ID, because MediaWiki messes with them...
pagename = appid.replace('_', ' ')
# Drop a trailing newline, because mediawiki is going to drop it anyway
# and it we don't we'll think the page has changed when it hasn't...
if wikidata.endswith('\n'):
wikidata = wikidata[:-1]
generated_pages[pagename] = wikidata
# Make a redirect from the name to the ID too, unless there's
# already an existing page with the name and it isn't a redirect.
noclobber = False
for ch in '_{}:[]|':
apppagename = apppagename.replace(ch, ' ')
# Drop double spaces caused mostly by replacing ':' above
apppagename = apppagename.replace(' ', ' ')
for expagename in site.allpages(prefix=apppagename,
filterredir='nonredirects',
generator=False):
if expagename == apppagename:
noclobber = True
# Another reason not to make the redirect page is if the app name
# is the same as it's ID, because that will overwrite the real page
# with an redirect to itself! (Although it seems like an odd
# scenario this happens a lot, e.g. where there is metadata but no
# builds or binaries to extract a name from.
if apppagename == pagename:
noclobber = True
if not noclobber:
generated_redirects[apppagename] = "#REDIRECT [[" + pagename + "]]\n[[Category:" + wikiredircat + "]]"
for tcat, genp in [(wikicat, generated_pages),
(wikiredircat, generated_redirects)]:
catpages = site.Pages['Category:' + tcat]
existingpages = []
for page in catpages:
existingpages.append(page.name)
if page.name in genp:
pagetxt = page.text()
if pagetxt != genp[page.name]:
logging.debug("Updating modified page " + page.name)
page.save(genp[page.name], summary='Auto-updated')
else:
logging.debug("Page " + page.name + " is unchanged")
else:
logging.warning('Deleting page ' + page.name)
page.delete('No longer published')
for pagename, text in genp.items():
logging.debug("Checking " + pagename)
if pagename not in existingpages:
logging.debug("Creating page " + pagename)
try:
newpage = site.Pages[pagename]
newpage.save(text, summary='Auto-created')
except Exception as e:
logging.error("...FAILED to create page '{0}': {1}".format(pagename, e))
# Purge server cache to ensure counts are up to date
site.Pages['Repository Maintenance'].purge()
# Write a page with the last build log for this version code
wiki_page_path = 'update_' + time.strftime('%s', start_timestamp)
newpage = site.Pages[wiki_page_path]
txt = ''
txt += "* command line: <code>" + ' '.join(sys.argv) + "</code>\n"
txt += "* started at " + common.get_wiki_timestamp(start_timestamp) + '\n'
txt += "* completed at " + common.get_wiki_timestamp() + '\n'
txt += common.get_git_describe_link()
txt += "\n\n"
txt += common.get_android_tools_version_log()
newpage.save(txt, summary='Run log')
newpage = site.Pages['update']
newpage.save('#REDIRECT [[' + wiki_page_path + ']]', summary='Update redirect')
def delete_disabled_builds(apps, apkcache, repodirs):
"""Delete disabled build outputs.
@ -2503,10 +2273,6 @@ def main():
# Update known apks info...
knownapks.writeifchanged()
# Update the wiki...
if options.wiki:
logging.warning(_('wiki support is deprecated and will be removed in the next release!'))
update_wiki(apps, apks + archapks)
status_update_json(apps, apks + archapks)
logging.info(_("Finished"))