-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepoManifest2kasYml.py
executable file
·102 lines (88 loc) · 3.37 KB
/
repoManifest2kasYml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import xml.dom.minidom
import yaml
import sys
import os
def parseManifestXML(xmlfile):
doc = xml.dom.minidom.parse(xmlfile)
projects = doc.getElementsByTagName("project")
remotes = doc.getElementsByTagName("remote")
default = doc.getElementsByTagName("default")
rems = {}
for rem in remotes:
rems[rem.getAttribute("name")] = rem.getAttribute("fetch")
defnode = default.pop()
defname = defnode.getAttribute("remote")
defrem = rems[defname]
defrev = defnode.getAttribute("revision")
data = {}
for proj in projects:
[ path, name, remote, revision] = [proj.getAttribute("path"),
proj.getAttribute("name"),
proj.getAttribute("remote"),
proj.getAttribute("upstream")]
#print([name.rsplit('/', 1), path, name, remote, revision])
if not remote:
remote = defrem+"/"
else:
remote = rems[remote]+"/"
if not revision:
revision = defrev
try:
pname = name.rsplit('/', 1)[1]
except IndexError:
pname = name
# FIXME
if pname != "meta-openembedded":
data[pname]= {"url":remote+name, "refspec":revision, "path":path}
else:
data[pname]= {"url":remote+name, "refspec":revision, "path":path, "layers":{"meta-filesystems":"", "meta-multimedia":"", "meta-networking":""}}
return data
def saveHeader(outf):
header = """header:\n version: 3\n\n"""
lfile="./auto.conf"
if os.path.exists(lfile):
print("Header file exists!")
with open(lfile, 'r') as lconf:
lines = lconf.readlines()
for line in lines:
if not (line.startswith('#')) and not line.isspace():
print(line)
if line.startswith("DISTRO"):
value = line.split()[2].replace("\"","")
header = "".join([header, "distro: ", value, "\n"])
if line.startswith("MACHINE"):
value = line.split()[2].replace("\"","")
header = "".join([header, "machine: ", value, "\n"])
header = "".join([header, "target: core-image-minimal\n"])
print(["Header: ", header])
outf.write(header)
def saveFooter(outf):
lfile="./local.conf"
if os.path.exists(lfile):
footer = '''\n\nlocal_conf_header:\n meta-custom: | \n'''
print("Footer file exists!")
with open(lfile, 'r') as lconf:
lines = lconf.readlines()
for line in lines:
if not (line.startswith('#')) and not line.isspace():
footer = " ".join([footer, line])
# print(["Footer: ", footer])
outf.write(footer)
def saveToYAML(data, outfile):
with open(outfile, 'w') as outf:
saveHeader(outf)
data = {"repos" : data}
yaml.dump(data, outf, default_flow_style=False)
saveFooter(outf)
if __name__ == "__main__":
if (len(sys.argv) != 2):
print("Usage: " + sys.argv[0] + " infile")
sys.exit(0)
infile = sys.argv[1]
outfile = infile.replace("xml", "yml")
if (infile == outfile):
print("Input file " + infile + " is not a manifest xml file")
sys.exit(0)
print("Saving YAML to " + outfile)
newsitems = parseManifestXML(infile)
saveToYAML(newsitems, outfile)