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