fix typo
[enigma2.git] / lib / python / Plugins / SystemPlugins / DefaultServicesScanner / plugin.py
1 #from Components.ActionMap import ActionMap, NumberActionMap
2 #from Components.Input import Input
3 #from Components.Ipkg import IpkgComponent
4 #from Components.Label import Label
5 #from Components.MenuList import MenuList
6 #from Components.Slider import Slider
7 from Components.NimManager import nimmanager
8 from Plugins.Plugin import PluginDescriptor
9 from Screens.ScanSetup import ScanSetup
10 from Screens.ServiceScan import ServiceScan
11 from Screens.MessageBox import MessageBox
12 from Tools.Directories import resolveFilename, SCOPE_CONFIG, copyfile
13 #from Screens.Screen import Screen
14 from os import unlink
15 from enigma import eTimer, eDVBDB
16
17 class DefaultServiceScan(ServiceScan):
18         skin = """
19                 <screen position="150,115" size="420,390" title="Service Scan">
20                 <widget source="FrontendInfo" render="Pixmap" pixmap="skin_default/icons/scan-s.png" position="5,5" size="64,64" transparent="1" alphatest="on">
21                         <convert type="FrontendInfo">TYPE</convert>
22                         <convert type="ValueRange">0,0</convert>
23                         <convert type="ConditionalShowHide" />
24                 </widget>
25                 <widget source="FrontendInfo" render="Pixmap" pixmap="skin_default/icons/scan-c.png" position="5,5" size="64,64" transparent="1" alphatest="on">
26                         <convert type="FrontendInfo">TYPE</convert>
27                         <convert type="ValueRange">1,1</convert>
28                         <convert type="ConditionalShowHide" />
29                 </widget>
30                 <widget source="FrontendInfo" render="Pixmap" pixmap="skin_default/icons/scan-t.png" position="5,5" size="64,64" transparent="1" alphatest="on">
31                         <convert type="FrontendInfo">TYPE</convert>
32                         <convert type="ValueRange">2,2</convert>
33                         <convert type="ConditionalShowHide" />
34                 </widget>
35                 <widget name="network" position="80,15" size="330,20" font="Regular;20" />
36                 <widget name="transponder" position="80,40" size="330,20" font="Regular;20" />
37                 <widget name="scan_state" position="10,80" zPosition="2" size="400,20" font="Regular;18" />
38                 <widget name="pass" position="10,80" size="400,20" font="Regular;18" />
39                 <widget name="scan_progress" position="10,105" size="400,15" pixmap="skin_default/progress_big.png" borderWidth="2" borderColor="#cccccc" />
40                 <widget name="servicelist" position="10,135" size="400,265" selectionDisabled="1" />
41         </screen>"""
42
43         def __init__(self, session, scanList):
44                 try:
45                         unlink("rm " + resolveFilename(SCOPE_CONFIG) + "/lamedb");
46                 except OSError:
47                         pass
48                 db = eDVBDB.getInstance()
49                 db.reloadServicelist()
50                 ServiceScan.__init__(self, session, scanList)
51                 self.timer = eTimer()
52                 self.timer.callback.append(self.ok)
53                 self.timer.start(1000)
54
55 class DefaultServicesScannerPlugin(ScanSetup):
56         skin = """
57                 <screen position="100,115" size="520,390" title="Service scan">
58                         <widget name="config" position="10,10" size="500,350" scrollbarMode="showOnDemand" />
59                         <widget name="introduction" position="10,365" size="500,25" font="Regular;20" halign="center" />
60                 </screen>"""
61                 
62         def __init__(self, session, args = None):
63                 ScanSetup.__init__(self, session)
64                 # backup lamedb
65                 confdir = resolveFilename(SCOPE_CONFIG)
66                 copyfile(confdir + "/lamedb", confdir + "/lamedb.backup)
67                 self.scan_type.value = "multisat"
68                 self.createSetup()
69                 self.scanIndex = 0
70                 self.selectSat(0)
71                 self.onFirstExecBegin.append(self.runScan)
72                 
73         def selectSat(self, index):
74                 for satindex in range(len(self.multiscanlist)):
75                         if satindex != index:
76                                 self.multiscanlist[satindex][1].value = False
77                         else:
78                                 self.multiscanlist[satindex][1].value = True
79                                 
80         def runScan(self):
81                 print "runScan"
82                 self.keyGo()
83
84         def startScan(self, tlist, flags, feid):
85                 print "startScan"
86                 if len(tlist):
87                         # flags |= eComponentScan.scanSearchBAT
88                         self.session.openWithCallback(self.scanFinished, DefaultServiceScan, [{"transponders": tlist, "feid": feid, "flags": flags}])
89                 else:
90                         self.session.openWithCallback(self.scanFinished, MessageBox, _("Nothing to scan!\nPlease setup your tuner settings before you start a service scan."), MessageBox.TYPE_ERROR)
91
92         def scanFinished(self, value = None):
93                 print "finished"
94                 db = eDVBDB.getInstance()
95                 satint = self.multiscanlist[self.scanIndex][0]
96                 print "scanned sat:", satint
97                 db.saveServicelist("/tmp/lamedb." + str(satint))
98                 file = open("/tmp/sat" + str(satint) + ".info", "w")
99                 xml = """<default>
100         <prerequisites>
101                 <tag type="services" />
102                 <bcastsystem type="DVB-S" />
103                 <satellite type="%d" />
104         </prerequisites>
105         
106         <info>
107                 <author>%s</author>
108                 <name>%s</name>
109         </info>
110
111         <files type="directories">
112                 <file type="services" name="lamedb.%d">
113                 </file>
114         </files>
115 </default>""" % (satint, "Dream", nimmanager.getSatDescription(satint), satint)
116                 file.write(xml)
117                 file.close()
118                 
119                 self.scanIndex += 1
120                 if self.scanIndex + 1 >= len(self.multiscanlist):
121                         print "no more sats to scan"
122                         confdir = resolveFilename(SCOPE_CONFIG)
123                         copyfile(confdir + "/lamedb.backup", confdir + "/lamedb)
124                         db.reloadServicelist()
125                         self.close()
126                 else:
127                         self.selectSat(self.scanIndex)
128                         self.keyGo()
129
130 def DefaultServicesScannerMain(session, **kwargs):
131         session.open(DefaultServicesScannerPlugin)
132
133 def Plugins(**kwargs):
134         return PluginDescriptor(name="Default Services Scanner", description=_("Scans default lamedbs sorted by satellite with a connected dish positioner"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc=DefaultServicesScannerMain)