[openwrt/openwrt] scripts: make-index-json: rework for old Python versions

LEDE Commits lede-commits at lists.infradead.org
Tue Jun 24 14:59:19 PDT 2025


aparcar pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/0c7d564b1dc2a1a237bc8ea125ec1b22f606cdbc

commit 0c7d564b1dc2a1a237bc8ea125ec1b22f606cdbc
Author: Eric Fahlgren <ericfahlgren at gmail.com>
AuthorDate: Mon Jun 23 15:50:23 2025 -0700

    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 at gmail.com>
    Signed-off-by: Eric Fahlgren <ericfahlgren at gmail.com>
---
 scripts/make-index-json.py | 13 ++++++++++---
 1 file 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"]
 




More information about the lede-commits mailing list