Merge branch 'bug_537_vobsub' into experimental
[enigma2.git] / tools / genmetaindex.py
1 # usage: genmetaindex.py <xml-files>  > index.xml
2 import sys, os
3 from xml.etree.ElementTree import ElementTree, Element
4
5 root = Element("index")
6
7 for file in sys.argv[1:]:
8         p = ElementTree()
9         p.parse(file)
10         
11         package = Element("package")
12         package.set("details", os.path.basename(file))
13         
14         # we need all prerequisites
15         package.append(p.find("prerequisites"))
16         
17         info = None
18         # we need some of the info, but not all
19         for i in p.findall("info"):
20                 if not info:
21                         info = i
22         assert info
23         
24         for i in info[:]:
25                 if i.tag not in ["name", "packagename", "packagetype", "shortdescription"]:
26                         info.remove(i)
27
28         for i in info[:]:
29                 package.set(i.tag, i.text)
30
31         root.append(package)
32
33 def indent(elem, level=0):
34         i = "\n" + level*"\t"
35         if len(elem):
36                 if not elem.text or not elem.text.strip():
37                         elem.text = i + "\t"
38                 if not elem.tail or not elem.tail.strip():
39                         elem.tail = i
40                 for elem in elem:
41                         indent(elem, level+1)
42                 if not elem.tail or not elem.tail.strip():
43                         elem.tail = i
44         else:
45                 if level and (not elem.tail or not elem.tail.strip()):
46                         elem.tail = i
47
48 indent(root)
49
50 ElementTree(root).write(sys.stdout)