644b00bb5f81a5454dc081807a44499239914d50
[vuplus_dvbapp-plugin] / webinterface / src / WebComponents / Sources / ServiceListRecursive.py
1 from Components.Sources.Source import Source
2 from Components.Sources.ServiceList import ServiceList
3 from enigma import eServiceReference
4
5 class ServiceListRecursive( Source ):
6     FETCH = 0
7     
8     def __init__(self, session, func = FETCH):
9         Source.__init__(self)  
10         
11         self.session = session
12         self.func = func
13         self.servicelist = {}
14         self.xml = ""
15         self.command = eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25) FROM BOUQUET "bouquets.tv" ORDER BY bouquet')
16     
17     def handleCommand(self,cmd):
18         self.command = eServiceReference(cmd)
19     
20     def do_func(self):
21         if self.func == self.FETCH:
22             func = self.buildList
23         else:
24             func = self.buildList
25         
26         return func(self.command)
27     
28     def buildList(self, ref):
29         self.servicelist = ServiceList(ref, command_func = self.getServiceList, validate_commands=False)
30         list = self.servicelist.getServicesAsList()       
31         for index in range(len(list)): 
32             item = list[index]
33             
34             self.servicelist.setRoot(eServiceReference(item[0]))
35             sub = self.servicelist.getServicesAsList()
36             
37             if len(sub) > 0:
38                 # list[index] = ( item[0] , item[1], sub )
39                 self.xml += "\t<e2bouquet>\n"
40                 bouquet = True
41                 
42                 subxml = ""
43                 for (ref, name) in sub:
44                     subxml += "\t\t\t<e2service>\n"
45                     subxml += "\t\t\t\t<e2servicereference>%s</e2servicereference>\n\t\t\t\t<e2servicename>%s</e2servicename>\n" %(self.filterXML(ref), self.filterXML(name))
46                     subxml += "\t\t\t</e2service>\n"
47             
48             else:
49                 self.xml += "\t\t<e2service>\n"
50                 bouquet = False
51             
52             self.xml += "\t\t<e2servicereference>%s</e2servicereference>\n\t\t<e2servicename>%s</e2servicename>\n" %(self.filterXML(item[0]), self.filterXML(item[1]))
53             
54             if bouquet:
55                 self.xml += "\t\t<e2servicelist>\n"
56                 self.xml += subxml
57                 self.xml += "\t\t</e2servicelist>\n"
58                 self.xml += "\t</e2bouquet>\n"
59             else:
60                 self.xml += "\t</e2service>\n"
61         
62         return self.xml
63     
64     def filterXML(self, item):
65         item = item.replace("&", "&amp;").replace("<", "&lt;").replace('"', '&quot;').replace(">", "&gt;")
66         return item
67     
68     def getServiceList(self, ref):
69         self.servicelist.root = ref
70             
71     text = property(do_func)
72         
73 #    list = property(do_func)
74  #   lut = {"ServiceReference": 0, "ServiceName": 1 }