summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Fahlgren2025-06-23 22:50:23 +0000
committerPaul Spooren2025-06-24 21:59:06 +0000
commit0c7d564b1dc2a1a237bc8ea125ec1b22f606cdbc (patch)
treece8eb16787767238e68b4fee1c112f1130c27960
parentd3324aa20841bc4bf93ed6ddd9890bc2a923f042 (diff)
downloadopenwrt-0c7d564b1dc2a1a237bc8ea125ec1b22f606cdbc.tar.gz
scripts: make-index-json: rework for old Python versions
The current code uses functions and features only found in newer versions of Python, so rework to allow use on systems only supporting older Python. Tested on Python 3.8 (released Oct 2019), but should work on 3.7 also. Suggested-by: Chen Minqiang <ptpt52@gmail.com> Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com>
-rwxr-xr-xscripts/make-index-json.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/scripts/make-index-json.py b/scripts/make-index-json.py
index af5c6cf073..4d71c3fca3 100755
--- a/scripts/make-index-json.py
+++ b/scripts/make-index-json.py
@@ -14,6 +14,12 @@ import email.parser
import json
+def removesuffix(src, suffix):
+ # For compatibility with Python < 3.9.
+ suffix_length = len(suffix)
+ return src[:-suffix_length] if suffix_length and src.endswith(suffix) else src
+
+
def parse_args():
from argparse import ArgumentParser
@@ -42,7 +48,7 @@ def parse_apk(text: str) -> dict:
for tag in package.get("tags", []):
if tag.startswith("openwrt:abiversion="):
package_abi: str = tag.split("=")[-1]
- package_name = package_name.removesuffix(package_abi)
+ package_name = removesuffix(package_name, package_abi)
break
packages[package_name] = package["version"]
@@ -58,8 +64,9 @@ def parse_opkg(text: str) -> dict:
for chunk in chunks:
package: dict = parser.parsestr(chunk, headersonly=True)
package_name: str = package["Package"]
- if package_abi := package.get("ABIVersion"):
- package_name = package_name.removesuffix(package_abi)
+ package_abi = package.get("ABIVersion")
+ if package_abi:
+ package_name = removesuffix(package_name, package_abi)
packages[package_name] = package["Version"]