From 6daca3ea179a09e36699f5c7ebef91bf24a207b6 Mon Sep 17 00:00:00 2001 From: Evan Maddock Date: Tue, 2 Apr 2024 15:29:55 -0400 Subject: [PATCH] common: Convert yconvert.py to Python 3 Signed-off-by: Evan Maddock --- common/Scripts/yconvert.py | 57 +++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/common/Scripts/yconvert.py b/common/Scripts/yconvert.py index f4e9ab335e..0b1a7be146 100755 --- a/common/Scripts/yconvert.py +++ b/common/Scripts/yconvert.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # yconvert.py - convert existing package into YML format # @@ -13,18 +13,17 @@ import xml.etree.ElementTree as ET import sys import os -import xml.dom.minidom as minidom -import commands +import subprocess if __name__ == "__main__": if len(sys.argv) != 2: - print "Provide pspec.xml" + print("Provide pspec.xml") sys.exit(1) if not sys.argv[1].endswith("pspec.xml"): - print "This doesn\'t look like a pspec.xml. Aborting" + print("This doesn't look like a pspec.xml. Aborting") sys.exit(1) if not os.path.exists(sys.argv[1]): - print "pspec.xml doesn\'t exist - aborting" + print("pspec.xml doesn't exist - aborting") sys.exit(1) tree = ET.parse(sys.argv[1]) @@ -40,33 +39,45 @@ if __name__ == "__main__": lic = root.findall("Source/License") licenses = [x.text for x in lic] - hist = root.findall("History") last_update = hist[0].findall("Update")[0] - rel = int(last_update.attrib['release']) + 1 + rel = int(last_update.attrib["release"]) + 1 version = str(last_update.findall("Version")[0].text) description = root.findall("Source/Description")[0].text summary = root.findall("Source/Summary")[0].text depsi = root.findall("Source/BuildDependencies/Dependency") - pcdeps = ["pkgconfig(%s)" % (x.text) for x in depsi if "type" in x.attrib and x.attrib['type'] == "pkgconfig"] - pcdep32 = ["pkgconfig32(%s)" % (x.text) for x in depsi if "type" in x.attrib and x.attrib['type'] == "pkgconfig32"] - deps = [x.text for x in depsi if "pkgconfig(%s)" % x.text not in pcdeps and "pkgconfig32(%s)" % x.text not in pcdep32] + pcdeps = [ + "pkgconfig(%s)" % x.text + for x in depsi + if "type" in x.attrib and x.attrib["type"] == "pkgconfig" + ] + pcdep32 = [ + "pkgconfig32(%s)" % x.text + for x in depsi + if "type" in x.attrib and x.attrib["type"] == "pkgconfig32" + ] + deps = [ + x.text + for x in depsi + if "pkgconfig(%s)" % x.text not in pcdeps + and "pkgconfig32(%s)" % x.text not in pcdep32 + ] url = archive.text file = url.split("/")[-1] r = 0 try: - r = os.system("wget \"%s\"" % url) - except: - print "Failed to download file" - sys.exit(1) - if r != 0: - print "Failed to download file" + r = subprocess.call("wget {}".format(url), shell=True) + if r != 0: + print("Failed to download file") + sys.exit(1) + except OSError as e: + print("Failed to download file", e) sys.exit(1) - sha256 = commands.getoutput("sha256sum %s" % file).split()[0].strip() + sha256 = subprocess.getoutput("sha256sum {}".format(file)).split()[0].strip() os.unlink(file) d = """ @@ -75,7 +86,13 @@ version : %(version)s release : %(release)s source : - %(tarball)s : %(sha256)s -""" % { "name": name, "version": version, "release": rel, "tarball": url, "sha256": sha256} +""" % { + "name": name, + "version": version, + "release": rel, + "tarball": url, + "sha256": sha256, + } if homepage: d += "homepage : %s\n" % homepage d += "license :\n" @@ -103,5 +120,5 @@ install : | %make_install """ - with open ("package.yml", "w") as output: + with open("package.yml", "w") as output: output.writelines(d.strip() + "\n")