wesnoth/utils/update_appdata
Steve Cotton c1e4178338 Disambiguate some python shebang lines to be "python3"
Loonycyborg already uses these tools with Python 3.

The python launcher tool for Windows has magic handling for some shebang lines,
however `#!/bin/env python` isn't recognised without the `/usr`. Had the `/usr`
been included with the old code then these scripts would likely have been run
with Python 2.
https://docs.python.org/dev/using/windows.html#shebang-lines
2020-07-29 22:10:02 +02:00

38 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import sys, requests, argparse
from xml.dom import minidom
def fetch_date(version):
tag_info = requests.get("https://api.github.com/repos/wesnoth/wesnoth/git/refs/tags/"+version)
tag_info.raise_for_status()
url = tag_info.json()["object"]["url"]
result = requests.get(url)
result.raise_for_status()
return result.json()["tagger"]["date"]
def update_appdata(version, appdata_path):
date = fetch_date(version)
doc = minidom.parse(appdata_path)
releases = doc.getElementsByTagName("releases")
if releases:
releases = releases[0]
else:
releases = doc.getElementsByTagName("component")[-1].appendChild(doc.createElement("releases"))
release = doc.createElement("release")
release.setAttribute("version", version)
release.setAttribute("date", date)
releases.insertBefore(release, releases.firstChild)
doc.writexml(open(appdata_path, "w"))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('version', metavar='VERSION')
parser.add_argument('appdata', metavar='APPDATA_FILE')
args = parser.parse_args()
update_appdata(args.version, args.appdata)