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