source: ipk/source.sh4/swapepg_crossepg/var/swap/extensions/CrossEPG/crossepg_loader.py@ 20692

Last change on this file since 20692 was 12090, checked in by madie, 14 years ago

[ipk] update crossepg

File size: 6.7 KB
Line 
1from enigma import getDesktop, eTimer
2
3from Components.config import config
4from Components.Label import Label
5from Components.Pixmap import Pixmap
6from Components.ProgressBar import ProgressBar
7from Components.ActionMap import NumberActionMap
8
9from Screens.Screen import Screen
10from Screens.MessageBox import MessageBox
11
12from crossepglib import *
13from crossepg_locale import _
14
15import _enigma
16import os
17import sys
18
19class CrossEPG_Loader(Screen):
20 def __init__(self, session, pcallback = None, noosd = False):
21 self.session = session
22 if (getDesktop(0).size().width() < 800):
23 skin = "%s/skins/downloader_sd.xml" % os.path.dirname(sys.modules[__name__].__file__)
24 self.isHD = 0
25 else:
26 skin = "%s/skins/downloader_hd.xml" % os.path.dirname(sys.modules[__name__].__file__)
27 self.isHD = 1
28 f = open(skin, "r")
29 self.skin = f.read()
30 f.close()
31 Screen.__init__(self, session)
32
33 self["background"] = Pixmap()
34 self["action"] = Label(_("Loading data"))
35 self["status"] = Label("")
36 self["progress"] = ProgressBar()
37 self["progress"].hide()
38
39 self.retValue = True
40 self.config = CrossEPG_Config()
41 self.config.load()
42 self.db_root = self.config.db_root
43 if not pathExists(self.db_root):
44 if not createDir(self.db_root):
45 self.db_root = "/hdd/crossepg"
46
47 self.pcallback = pcallback
48 self.wrapper = None
49
50 self.pcallbacktimer = eTimer()
51 self.pcallbacktimer.callback.append(self.doCallback)
52
53 if pathExists("/usr/crossepg"):
54 self.home_directory = "/usr/crossepg"
55 elif pathExists("/var/crossepg"):
56 self.home_directory = "/var/crossepg"
57 else:
58 print "[CrossEPG_Config] ERROR!! CrossEPG binaries non found"
59
60 # check for common patches
61 try:
62 self.xepgpatch = new.instancemethod(_enigma.eEPGCache_crossepgImportEPGv21,None,eEPGCache)
63 print "[CrossEPG_Loader] patch crossepg v2.1 found"
64 except Exception, e:
65 self.xepgpatch = None
66
67 try:
68 self.epgpatch = new.instancemethod(_enigma.eEPGCache_load,None,eEPGCache)
69 print "[CrossEPG_Loader] patch epgcache.load() found"
70 except Exception, e:
71 self.epgpatch = None
72
73 try:
74 self.edgpatch = new.instancemethod(_enigma.eEPGCache_reloadEpg,None,eEPGCache)
75 print "[CrossEPG_Loader] patch EDG NEMESIS found"
76 except Exception, e:
77 self.edgpatch = None
78
79 try:
80 self.oudeispatch = new.instancemethod(_enigma.eEPGCache_importEvent,None,eEPGCache)
81 print "[CrossEPG_Loader] patch Oudeis found"
82 except Exception, e:
83 self.oudeispatch = None
84
85 if self.xepgpatch:
86 self.timer = eTimer()
87 self.timer.callback.append(self.loadEPG2)
88 self.timer.start(200, 1)
89
90 elif self.epgpatch:
91 self.timer = eTimer()
92 self.timer.callback.append(self.loadEPG)
93 self.timer.start(200, 1)
94
95 elif self.edgpatch:
96 self.timer = eTimer()
97 self.timer.callback.append(self.loadEDG)
98 self.timer.start(200, 1)
99
100 elif self.oudeispatch:
101 self["actions"] = NumberActionMap(["WizardActions", "InputActions"],
102 {
103 "back": self.quit
104 }, -1)
105
106 self.wrapper = CrossEPG_Wrapper()
107 self.wrapper.addCallback(self.wrapperCallback)
108
109 self.timeout = eTimer()
110 self.timeout.callback.append(self.quit)
111
112 self.hideprogress = eTimer()
113 self.hideprogress.callback.append(self["progress"].hide)
114
115 self.epg_channel = None;
116 self.epg_tuple = ()
117 self.epg_starttime = 0
118 self.epg_length = 0
119 self.epg_name = ""
120
121 self.wrapper.init(CrossEPG_Wrapper.CMD_CONVERTER, self.db_root)
122 else:
123 print "No patch found... please reboot enigma2 manually"
124 self.closeAndCallback(True)
125
126 if not noosd:
127 self.onFirstExecBegin.append(self.firstExec)
128
129 def firstExec(self):
130 if self.isHD:
131 self["background"].instance.setPixmapFromFile("%s/images/background_hd.png" % (os.path.dirname(sys.modules[__name__].__file__)))
132 else:
133 self["background"].instance.setPixmapFromFile("%s/images/background.png" % (os.path.dirname(sys.modules[__name__].__file__)))
134
135 def loadEPG2(self):
136 print "[CrossEPG_Loader] loading data with crossepg patch v2"
137 self.xepgpatch(eEPGCache.getInstance(), self.db_root)
138 self.closeAndCallback(True)
139
140 def loadEPG(self):
141 try:
142 cmd = "%s/crossepg_epgcopy %s/ext.epg.dat %s" % (self.home_directory, self.db_root, config.misc.epgcache_filename.value)
143 except Exception, e:
144 cmd = "%s/crossepg_epgcopy %s/ext.epg.dat /hdd/epg.dat" % (self.home_directory, self.db_root)
145
146 print "[CrossEPG_Loader] %s" % (cmd)
147 os.system(cmd)
148 self.epgpatch(eEPGCache.getInstance())
149 self.closeAndCallback(True)
150
151 def loadEDG(self):
152 cmd = "%s/crossepg_epgcopy %s/ext.epg.dat %s/epg.dat" % (self.home_directory, self.db_root, config.nemepg.path.value)
153 print "[CrossEPG_Loader] %s" % (cmd)
154 os.system(cmd)
155 self.edgpatch(eEPGCache.getInstance())
156 self.closeAndCallback(True)
157
158 def wrapperCallback(self, event, param):
159 if event == CrossEPG_Wrapper.EVENT_READY:
160 self.wrapper.text()
161
162 elif event == CrossEPG_Wrapper.EVENT_END:
163 self.wrapper.quit()
164
165 elif event == CrossEPG_Wrapper.EVENT_ACTION:
166 self["action"].text = param
167
168 elif event == CrossEPG_Wrapper.EVENT_STATUS:
169 self["status"].text = param
170
171 elif event == CrossEPG_Wrapper.EVENT_PROGRESS:
172 self["progress"].setValue(param)
173
174 elif event == CrossEPG_Wrapper.EVENT_CHANNEL:
175 if self.epg_channel:
176 if len(self.epg_tuple) > 0:
177 self.oudeispatch(eEPGCache.getInstance(), self.epg_channel, self.epg_tuple)
178 self.epg_tuple = ()
179 self.epg_channel = param
180
181 elif event == CrossEPG_Wrapper.EVENT_STARTTIME:
182 self.epg_starttime = param
183
184 elif event == CrossEPG_Wrapper.EVENT_LENGTH:
185 self.epg_length = param
186
187 elif event == CrossEPG_Wrapper.EVENT_NAME:
188 self.epg_name = param
189
190 elif event == CrossEPG_Wrapper.EVENT_DESCRIPTION:
191 if self.epg_channel:
192 self.epg_tuple += ((self.epg_starttime, self.epg_length, self.epg_name, self.epg_name, param, 0),)
193
194 elif event == CrossEPG_Wrapper.EVENT_PROGRESSONOFF:
195 if param:
196 self.hideprogress.stop()
197 self["progress"].setValue(0)
198 self["progress"].show()
199 else:
200 self["progress"].setValue(100)
201 self.hideprogress.start(500, 1)
202 elif event == CrossEPG_Wrapper.EVENT_QUIT:
203 if self.epg_channel:
204 if len(self.epg_tuple) > 0:
205 self.oudeispatch(eEPGCache.getInstance(), self.epg_channel, self.epg_tuple)
206 self.closeAndCallback(self.retValue)
207
208 elif event == CrossEPG_Wrapper.EVENT_ERROR:
209 self.session.open(MessageBox, _("CrossEPG error: %s") % (param), type = MessageBox.TYPE_INFO, timeout = 20)
210 self.retValue = False
211 self.quit()
212
213 def quit(self):
214 if self.wrapper:
215 if self.wrapper.running():
216 self.retValue = False
217 self.wrapper.quit()
218 return
219
220 self.closeAndCallback(False)
221
222 def closeAndCallback(self, ret):
223 self.retValue = ret
224 self.close(ret)
225 self.pcallbacktimer.start(0, 1)
226
227 def doCallback(self):
228 if self.pcallback:
229 self.pcallback(self.retValue)
230
Note: See TracBrowser for help on using the repository browser.