* add "web/getallservices" to get all bouquets and services for a serviceref
[enigma2-plugins.git] / 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 from pprint import pprint
5
6
7 class ServiceListRecursive( Source ):
8     FETCH = 0
9     
10     def __init__(self, session, func = FETCH):
11         Source.__init__(self)  
12         
13         self.session = session
14         self.func = func
15         self.servicelist = {}
16         self.xml = ""
17         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')
18     
19     def handleCommand(self,cmd):
20         self.command = cmd
21     
22     def do_func(self):
23         if self.func == self.FETCH:
24             func = self.buildList
25         else:
26             func = self.buildList
27         
28         return func(self.command)
29     
30     def buildList(self, ref):
31         self.servicelist = ServiceList(ref, command_func = self.getServiceList, validate_commands=False)
32         list = self.servicelist.getServicesAsList()       
33         for index in range(len(list)): 
34             item = list[index]
35             
36             self.servicelist.setRoot(eServiceReference(item[0]))
37             sub = self.servicelist.getServicesAsList()
38             
39             if len(sub) > 0:
40                 list[index] = ( item[0] , item[1], sub )
41                 self.xml += "\t<e2bouquet>\n"
42                 bouquet = True
43                 
44                 subxml = ""
45                 for (ref, name) in sub:
46                     subxml += "\t\t\t<e2service>\n"
47                     subxml += "\t\t\t\t<e2servicereference>%s</e2servicereference>\n<e2servicename>%s</e2servicename>\n" %(ref, name)
48                     subxml += "\t\t\t</e2service>"
49             
50             else:
51                 self.xml += "\t\t<e2service>\n"
52                 bouquet = False
53             
54             self.xml += "\t\t\t<e2servicereference>%s</e2servicereference>\n<e2servicename>%s</e2servicename>\n" %(item[0], item[1])
55             
56             if bouquet:
57                 self.xml += "\t\t<e2servicelist>\n"
58                 self.xml += subxml
59                 self.xml += "\t\t</e2servicelist>\n"
60                 self.xml += "\t</e2bouquet>\n"
61             else:
62                 self.xml += "\t</e2service>\n"
63         
64         #print "_XML is: \n%s" %(self.xml)
65         return self.getText()
66
67             
68     def getServiceList(self, ref):
69         self.servicelist.root = ref
70         
71     def getText(self):
72         return self.xml
73     
74     text = property(do_func)
75         
76 #    list = property(do_func)
77  #   lut = {"ServiceReference": 0, "ServiceName": 1 }