mirror of
https://github.com/getsolus/packages.git
synced 2025-04-29 14:20:25 +03:00
common: Convert yconvert.py to Python 3
Signed-off-by: Evan Maddock <maddock.evan@vivaldi.net>
This commit is contained in:
parent
16d20bf4c8
commit
6daca3ea17
1 changed files with 37 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# yconvert.py - convert existing package into YML format
|
# yconvert.py - convert existing package into YML format
|
||||||
#
|
#
|
||||||
|
@ -13,18 +13,17 @@
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import xml.dom.minidom as minidom
|
import subprocess
|
||||||
import commands
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print "Provide pspec.xml"
|
print("Provide pspec.xml")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not sys.argv[1].endswith("pspec.xml"):
|
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)
|
sys.exit(1)
|
||||||
if not os.path.exists(sys.argv[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)
|
sys.exit(1)
|
||||||
|
|
||||||
tree = ET.parse(sys.argv[1])
|
tree = ET.parse(sys.argv[1])
|
||||||
|
@ -40,33 +39,45 @@ if __name__ == "__main__":
|
||||||
lic = root.findall("Source/License")
|
lic = root.findall("Source/License")
|
||||||
licenses = [x.text for x in lic]
|
licenses = [x.text for x in lic]
|
||||||
|
|
||||||
|
|
||||||
hist = root.findall("History")
|
hist = root.findall("History")
|
||||||
last_update = hist[0].findall("Update")[0]
|
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)
|
version = str(last_update.findall("Version")[0].text)
|
||||||
|
|
||||||
description = root.findall("Source/Description")[0].text
|
description = root.findall("Source/Description")[0].text
|
||||||
summary = root.findall("Source/Summary")[0].text
|
summary = root.findall("Source/Summary")[0].text
|
||||||
|
|
||||||
depsi = root.findall("Source/BuildDependencies/Dependency")
|
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"]
|
pcdeps = [
|
||||||
pcdep32 = ["pkgconfig32(%s)" % (x.text) for x in depsi if "type" in x.attrib and x.attrib['type'] == "pkgconfig32"]
|
"pkgconfig(%s)" % x.text
|
||||||
deps = [x.text for x in depsi if "pkgconfig(%s)" % x.text not in pcdeps and "pkgconfig32(%s)" % x.text not in pcdep32]
|
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
|
url = archive.text
|
||||||
file = url.split("/")[-1]
|
file = url.split("/")[-1]
|
||||||
r = 0
|
r = 0
|
||||||
try:
|
try:
|
||||||
r = os.system("wget \"%s\"" % url)
|
r = subprocess.call("wget {}".format(url), shell=True)
|
||||||
except:
|
|
||||||
print "Failed to download file"
|
|
||||||
sys.exit(1)
|
|
||||||
if r != 0:
|
if r != 0:
|
||||||
print "Failed to download file"
|
print("Failed to download file")
|
||||||
|
sys.exit(1)
|
||||||
|
except OSError as e:
|
||||||
|
print("Failed to download file", e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
sha256 = commands.getoutput("sha256sum %s" % file).split()[0].strip()
|
sha256 = subprocess.getoutput("sha256sum {}".format(file)).split()[0].strip()
|
||||||
os.unlink(file)
|
os.unlink(file)
|
||||||
|
|
||||||
d = """
|
d = """
|
||||||
|
@ -75,7 +86,13 @@ version : %(version)s
|
||||||
release : %(release)s
|
release : %(release)s
|
||||||
source :
|
source :
|
||||||
- %(tarball)s : %(sha256)s
|
- %(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:
|
if homepage:
|
||||||
d += "homepage : %s\n" % homepage
|
d += "homepage : %s\n" % homepage
|
||||||
d += "license :\n"
|
d += "license :\n"
|
||||||
|
@ -103,5 +120,5 @@ install : |
|
||||||
%make_install
|
%make_install
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open ("package.yml", "w") as output:
|
with open("package.yml", "w") as output:
|
||||||
output.writelines(d.strip() + "\n")
|
output.writelines(d.strip() + "\n")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue