forked from oe-alliance/AutoBouquetsMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genmetaindex.py
54 lines (41 loc) · 1.17 KB
/
genmetaindex.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
# usage: genmetaindex.py <xml-files> > index.xml
import sys
import os
from xml.etree.ElementTree import ElementTree, Element
root = Element("index")
encoding = ("unicode" if sys.version_info[0] >= 3 else "utf-8")
for file in sys.argv[1:]:
p = ElementTree()
p.parse(file)
package = Element("package")
package.set("details", os.path.basename(file))
# we need all prerequisites
package.append(p.find("prerequisites"))
info = None
# we need some of the info, but not all
for i in p.findall("info"):
if not info:
info = i
assert info
for i in info[:]:
if i.tag not in ["name", "packagename", "packagetype", "shortdescription"]:
info.remove(i)
for i in info[:]:
package.set(i.tag, i.text)
root.append(package)
def indent(elem, level=0):
i = "\n" + level * "\t"
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + "\t"
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level + 1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i
indent(root)
ElementTree(root).write(sys.stdout, encoding=encoding)