1 from Plugins.Plugin import PluginDescriptor
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Screens.ChoiceBox import ChoiceBox
6 from Components.ActionMap import ActionMap
7 from enigma import eTimer, eServiceCenter, iServiceInformation, eConsoleAppContainer, eEnv
8 from os import access, chmod, X_OK
10 recons_path = eEnv.resolve("${libdir}/enigma2/python/Plugins/Extensions/ReconstructApSc/bin/reconstruct_apsc")
12 def main(session, service, **kwargs):
13 # Hack to make sure it is executable
14 if not access(recons_path, X_OK):
15 chmod(recons_path, 493)
16 session.open(ReconstructApSc, service, **kwargs)
18 def Plugins(**kwargs):
19 return PluginDescriptor(name="ReconstructApSc", description=_("Reconstruct AP/SC ..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc=main)
22 class ReconstructApSc(ChoiceBox):
23 def __init__(self, session, service):
24 self.service = service
25 serviceHandler = eServiceCenter.getInstance()
26 path = self.service.getPath()
27 info = serviceHandler.info(self.service)
31 self.name = info.getName(self.service)
33 (_("Don't reconstruct"), "CALLFUNC", self.confirmed0),
34 (_("Reconstruct the .ap and .sc files of the selected movie"), "CALLFUNC", self.confirmed1),
35 (_("Reconstruct all missing .ap and .sc files in this directory"), "CALLFUNC", self.confirmed2),
36 (_("Check any running reconstruct process"), "CALLFUNC", self.confirmed3),
38 ChoiceBox.__init__(self, session, _("What would you like to reconstruct? (\"%s\")") % (self.name), list = tlist, selection = 0)
39 self.skinName = "ChoiceBox"
41 def confirmed0(self, arg):
44 def confirmed1(self, arg):
45 ReconstructApScSpawn(self.session, self, [recons_path, self.service.getPath()], self.name, _("movie"))
47 def confirmed2(self, arg):
48 dir = self.dirName(self.service.getPath())
49 ReconstructApScSpawn(self.session, self, [recons_path, "-d", dir], dir, _("directory"))
51 def confirmed3(self, arg):
52 output = global_recons_queue.checkOutput()
54 mess = "There is no running reconstruction process"
56 mess = "Current reconstruction process output:\n%s" % output
57 self.session.openWithCallback(self.close, MessageBox, mess, MessageBox.TYPE_INFO)
59 def dirName(self, str):
60 return '/'.join(str.split('/')[:-1]) + '/'
63 class ReconstructApScQueue:
65 self.container = eConsoleAppContainer()
66 self.appClosed_conn = self.container.appClosed.connect(self.runDone)
67 self.dataAvail_conn = self.container.dataAvail.connect(self.collOutput)
72 def enqueue(self, cb, cmd):
73 self.queue.append((cb, cmd))
80 def collOutput(self, data):
83 def checkOutput(self):
95 self.container.execute(*self.queue[0][1])
97 def runDone(self, retval):
99 self.queue = self.queue[1:]
100 cb(retval, self.output)
103 global_recons_errors = [_("The %s \"%s\" is successfully processed:\n%s"),
104 _("Processing failed for the %s \"%s\":\n%s")]
106 global_recons_queue = ReconstructApScQueue()
108 global_recons_block = False
110 class ReconstructApScSpawn:
111 def __init__(self, session, parent, clist, name, typename):
112 global global_recons_queue
113 global global_recons_block
114 self.session = session
117 self.typename = typename
118 self.clist = [clist[0]] + clist
121 self.waitTimer = eTimer()
122 self.waitTimer_conn = self.waitTimer.timeout.connect(self.doWaitAck)
123 if global_recons_queue.enqueue(self.doAck, self.clist):
124 mess = _("The %s \"%s\" is processed in the background.") % (self.typename, self.name)
126 mess = _("Another movie or directory is currently processed.\nThe %s \"%s\" will be processed in the background after it.") % (self.typename, self.name)
127 global_recons_block = True
128 self.dialog = self.session.openWithCallback(self.endc, MessageBox, mess, MessageBox.TYPE_INFO)
130 def doAck(self, retval, output):
131 global global_recons_errors
132 self.mess = global_recons_errors[retval] % (self.typename, self.name, output)
136 global global_recons_block
137 if Screens.Standby.inStandby or not self.session.in_exec or (global_recons_block and not self.dialog):
138 self.waitTimer.start(2000, True)
140 global_recons_block = True
141 self.session.openWithCallback(self.endw, MessageBox, self.mess, MessageBox.TYPE_INFO)
143 def endw(self, arg = 0):
144 global global_recons_block
145 global_recons_block = False
146 if self.session.current_dialog == self.dialog:
147 self.session.current_dialog.close(True)
150 def endc(self, arg = 0):
151 global global_recons_block
152 global_recons_block = False