def GrabPost(self): #notify if self.__notify_status == True: common.notifyOSD(__LS__(30000), __LS__(30004), common.IconInfo) #del ProgressBar if self.__ProgressBar != None: self.__ProgressBar.Close() del self.__ProgressBar self.__ProgressBar = None if self.__GrabFailed == False: # backup to fallback backup if not failed if self.__backup_xml == True: if os.path.exists("%s.bak" % (self.__wg_xmlfile)): shutil.copy2("%s.bak" % (self.__wg_xmlfile), "%s.fallback" % (self.__wg_xmlfile)) else: common.writeLog( "xml-backup-file not found, no fallback file generated", xbmc.LOGWARNING) common.notifyOSD(__LS__(30006), __LS__(30010), common.IconStop) # read log file for next grab if not failed self.ReadFromLogFile(True) common.writeLog('Grabbing finished ...') return (not self.__GrabFailed)
def setShutdown(command): if common.isPID(False): common.setCommand(command) else: common.writeLog('Service not running, performing normal shutdown action ...') common.notifyOSD(__LS__(30008),__LS__(30025),common.IconError) if command == common.CMD_SHUTDOWN: xbmc.shutdown() elif command == common.CMD_SUSPEND: xbmc.suspend() elif command == common.CMD_HIBERNATE: xbmc.hibernate() else: common.writeLog('Unable to perform action ...')
def StartGrabbing(self, try_): Failed = False if try_ == 1: # first try # Copy logfile to old if os.path.exists(self.__wg_logfile): shutil.copy2(self.__wg_logfile, "%s.old"%(self.__wg_logfile)) else: common.writeLog("log-file not found, no copy made",xbmc.LOGWARNING) # Make backup if self.__backup_xml == True: if os.path.exists(self.__wg_xmlfile): shutil.copy2(self.__wg_xmlfile, "%s.bak"%(self.__wg_xmlfile)) else: common.writeLog("xml-file not found, no backup made",xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30007), common.IconStop) # try scan if os.path.exists(self.__wg_script): self.Command.Run([self.__wg_script]) else: common.writeLog("EPG-update script not found",xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30008), common.IconError) Failed = True elif try_ == 2: # second try # use fallback backup if failed if self.__backup_xml == True: if os.path.exists("%s.fallback"%(self.__wg_xmlfile)): common.writeLog("Try again using fallback xml-file",xbmc.LOGWARNING) shutil.move("%s.fallback"%(self.__wg_xmlfile),self.__wg_xmlfile) else: common.writeLog("No fallback file found: Delete xml-file and try again with full grab",xbmc.LOGWARNING) if os.path.exists(self.__wg_xmlfile): os.remove(self.__wg_xmlfile) else: common.writeLog("No xml-file found to remove") else: common.writeLog("No backup set: Delete xml-file and try again with full",xbmc.LOGWARNING) if os.path.exists(self.__wg_xmlfile): os.remove(self.__wg_xmlfile) else: common.writeLog("No xml-file found to remove") if os.path.exists(self.__wg_script): self.Command.Run([self.__wg_script]) else: common.writeLog("EPG-update script not found",xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30008), common.IconError) Failed = True else: # third try # complete new grab if os.path.exists(self.__wg_xmlfile): os.remove(self.__wg_xmlfile) else: common.writeLog("No xml-file found to remove") if os.path.exists(self.__wg_script): self.Command.Run([self.__wg_script]) else: common.writeLog("EPG-update script not found",xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30008), common.IconError) Failed = True return Failed
def GrabPre(self): self.getSettings() self.CalcTimeOut() self.__CompChannelCounter = 0 #start self.__CurrentTry = 1 self.__GrabFailed = self.StartGrabbing(self.__CurrentTry) if (not self.__GrabFailed): common.writeLog('Grabbing started ...') #notify if self.__notify_status == True: common.notifyOSD(__LS__(30000), __LS__(30003), common.IconInfo) #progress bar if self.__progressbar_status == True: self.__ProgressBar = WGProgressBar() self.__ProgressBar.Create(0, 0) return (not self.__GrabFailed)
def GrabPre(self): self.getSettings() self.CalcTimeOut() self.__CompChannelCounter = 0 #start self.__CurrentTry = 1 self.__GrabFailed = self.StartGrabbing(self.__CurrentTry) if (not self.__GrabFailed): common.writeLog('Grabbing started ...') #notify if self.__notify_status == True: common.notifyOSD(__LS__(30000), __LS__(30003),common.IconInfo) #progress bar if self.__progressbar_status == True: self.__ProgressBar = WGProgressBar() self.__ProgressBar.Create(0, 0) return (not self.__GrabFailed)
def PostProcCheck(self): Busy = True #finished if self.__post_transfer == True: ExitCode = self.Command.Busy() if ExitCode != None: Busy = False if ExitCode != 0: common.writeLog("Postprocessor execution error",xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30013), common.IconError) #timeout check else: if (self.__TimeOutTime > 0) and (self.__TimeOutTime < self.LogInfo.EpochGetNow()): common.writeLog('Postprocessor timeout, kill process') common.notifyOSD(__LS__(30000), __LS__(30016),common.IconError) self.Command.Kill() Busy = False return Busy
def CheckService(self, Timed): if not common.IsRunning(): common.notifyOSD(__LS__(30001), __LS__(30002), common.IconError) self.getControl(FIELD_STATUS).setLabel(__LS__(30115)) if self.rt != None: self.rt.stop() return False self.DisplayStatus() if not Timed: # First run, get everything and read logfile... self.LogInfo.ReadLogFile() self.WGInfoOld = self.LogInfo.CopyLog(self.WGInfoOld) self.LogInfo.ReadLogFile(True) self.DisplayNextGrab() self.DisplayProgress() self.DisplayPrevInfo() self.OldStatus = self.Status if (self.Status == common.STAT_IDLE): self.getControl(BUTTON_FORCE).setEnabled(True) else: # Check timed if (self.Status != self.OldStatus): # Status changed, if grabbing, only read current logfile and keep old if (self.Status == common.STAT_GRABBING): self.getControl(BUTTON_FORCE).setEnabled(False) self.LogInfo.ReadLogFile(True) self.DisplayNextGrab() self.DisplayProgress() # if idle, read log and copy once elif (self.Status == common.STAT_IDLE): self.getControl(BUTTON_FORCE).setEnabled(True) self.LogInfo.ReadLogFile() self.WGInfoOld = self.LogInfo.CopyLog(self.WGInfoOld) self.DisplayNextGrab() self.DisplayProgress() self.DisplayPrevInfo() elif (self.Status == common.STAT_GRABBING): # Read current logfile self.LogInfo.ReadLogFile(True) self.DisplayProgress() self.OldStatus = self.Status return True
def GrabPost(self): #notify if self.__notify_status == True: common.notifyOSD(__LS__(30000), __LS__(30004),common.IconInfo) #del ProgressBar if self.__ProgressBar != None: self.__ProgressBar.Close() del self.__ProgressBar self.__ProgressBar = None if self.__GrabFailed == False: # backup to fallback backup if not failed if self.__backup_xml == True: if os.path.exists("%s.bak"%(self.__wg_xmlfile)): shutil.copy2("%s.bak"%(self.__wg_xmlfile), "%s.fallback"%(self.__wg_xmlfile)) else: common.writeLog("xml-backup-file not found, no fallback file generated",xbmc.LOGWARNING) common.notifyOSD(__LS__(30006), __LS__(30010), common.IconStop) # read log file for next grab if not failed self.ReadFromLogFile(True) common.writeLog('Grabbing finished ...') return (not self.__GrabFailed)
def PostProcPre(self): Busy = (self.__sck_transfer == True) or (self.__post_transfer == True) or (self.__update_kodi == True) self.CalcTimeOut() #start if Busy == True: if not os.path.exists(self.__wg_xmlfile): common.writeLog("xml-file not found, no post-processing possible",xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30007), common.IconStop) Busy = False else: common.writeLog('Post processing started ...') if self.__sck_transfer == True: if os.path.exists(self.__sck_url): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(self.__sck_url) datafile = file(self.__wg_xmlfile) for line in datafile: s.send(line) s.close() else: common.writeLog("Socket not found, no socket transfer possible",xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30011), common.IconStop) Busy = (self.__post_transfer == True) or (self.__update_kodi == True) if self.__post_transfer == True: if os.path.exists(self.__post_script): self.Command.Run([self.__post_script]) else: common.writeLog("Postprocessor not found, no postprocessing possible",xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30012), common.IconStop) return Busy
def PostProcCheck(self): Busy = True #finished if self.__post_transfer == True: ExitCode = self.Command.Busy() if ExitCode != None: Busy = False if ExitCode != 0: common.writeLog("Postprocessor execution error", xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30013), common.IconError) #timeout check else: if (self.__TimeOutTime > 0) and (self.__TimeOutTime < self.LogInfo.EpochGetNow()): common.writeLog('Postprocessor timeout, kill process') common.notifyOSD(__LS__(30000), __LS__(30016), common.IconError) self.Command.Kill() Busy = False return Busy
def GrabCheck(self): Busy = True #update progressbar (we do need to read the logfile ...) if self.__ProgressBar != None: self.ReadFromLogFile(True) self.__ProgressBar.Update(self.LogInfo.WGInfo.ChannelCounter, self.LogInfo.WGInfo.Channels) #check if grab is finished ExitCode = self.Command.Busy() if ExitCode != None: if ExitCode == 0: #Correct execution self.__GrabFailed = False Busy = False else: if self.__GrabFailed == True: common.writeLog("Error executing EPG update (3rd try)",xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30009), common.IconError) Busy = False elif self.__CurrentTry == 1: common.writeLog("Error executing EPG update (1st try)",xbmc.LOGWARNING) self.CalcTimeOut() self.__CurrentTry = 2 Busy = not self.StartGrabbing(self.__CurrentTry) else: self.__GrabFailed = True common.writeLog("Error executing EPG update (2nd try)",xbmc.LOGWARNING) self.CalcTimeOut() self.__CurrentTry = 3 Busy = not self.StartGrabbing(self.__CurrentTry) #timeout check if Busy == True: # Only read logfile after timeout time to save readings (and if no progressbar. Otherwise logfile is already been read) if (self.__TimeOutTime > 0) and (self.__TimeOutTime < self.LogInfo.EpochGetNow()): if self.__ProgressBar == None: self.ReadFromLogFile(True) if (self.LogInfo.WGInfo.ChannelCounter > self.__CompChannelCounter): self.__CompChannelCounter = self.LogInfo.WGInfo.ChannelCounter self.CalcTimeOut() else: common.writeLog('EPG-grabbing timeout, kill process',xbmc.LOGERROR) common.notifyOSD(__LS__(30000), __LS__(30015),common.IconError) self.Command.Kill() if self.__GrabFailed == True: common.writeLog("Error executing EPG update (3rd try)",xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30009), common.IconError) Busy = False elif self.__CurrentTry == 1: common.writeLog("Error executing EPG update (1st try)",xbmc.LOGWARNING) self.CalcTimeOut() self.__CurrentTry = 2 Busy = not self.StartGrabbing(self.__CurrentTry) else: common.writeLog("Error executing EPG update (2nd try)",xbmc.LOGWARNING) self.__GrabFailed = True self.CalcTimeOut() self.__CurrentTry = 3 Busy = not self.StartGrabbing(self.__CurrentTry) return Busy
def PostProcPre(self): Busy = (self.__sck_transfer == True) or (self.__post_transfer == True) or (self.__update_kodi == True) self.CalcTimeOut() #start if Busy == True: if not os.path.exists(self.__wg_xmlfile): common.writeLog( "xml-file not found, no post-processing possible", xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30007), common.IconStop) Busy = False else: common.writeLog('Post processing started ...') if self.__sck_transfer == True: if os.path.exists(self.__sck_url): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(self.__sck_url) datafile = None with open(self.__wg_xmlfile, "r") as fp: datafile = fp.readlines() for line in datafile: s.send(line.encode('utf-8')) s.close() else: common.writeLog( "Socket not found, no socket transfer possible", xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30011), common.IconStop) Busy = (self.__post_transfer == True) or (self.__update_kodi == True) if self.__post_transfer == True: if os.path.exists(self.__post_script): self.Command.Run([self.__post_script]) else: common.writeLog( "Postprocessor not found, no postprocessing possible", xbmc.LOGERROR) common.notifyOSD(__LS__(30014), __LS__(30012), common.IconStop) return Busy
def GrabCheck(self): Busy = True #update progressbar (we do need to read the logfile ...) if self.__ProgressBar != None: self.ReadFromLogFile(True) self.__ProgressBar.Update(self.LogInfo.WGInfo.ChannelCounter, self.LogInfo.WGInfo.Channels) #check if grab is finished ExitCode = self.Command.Busy() if ExitCode != None: if ExitCode == 0: #Correct execution self.__GrabFailed = False Busy = False else: if self.__GrabFailed == True: common.writeLog("Error executing EPG update (3rd try)", xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30009), common.IconError) Busy = False elif self.__CurrentTry == 1: common.writeLog("Error executing EPG update (1st try)", xbmc.LOGWARNING) self.CalcTimeOut() self.__CurrentTry = 2 Busy = not self.StartGrabbing(self.__CurrentTry) else: self.__GrabFailed = True common.writeLog("Error executing EPG update (2nd try)", xbmc.LOGWARNING) self.CalcTimeOut() self.__CurrentTry = 3 Busy = not self.StartGrabbing(self.__CurrentTry) #timeout check if Busy == True: # Only read logfile after timeout time to save readings (and if no progressbar. Otherwise logfile is already been read) if (self.__TimeOutTime > 0) and (self.__TimeOutTime < self.LogInfo.EpochGetNow()): if self.__ProgressBar == None: self.ReadFromLogFile(True) if (self.LogInfo.WGInfo.ChannelCounter > self.__CompChannelCounter): self.__CompChannelCounter = self.LogInfo.WGInfo.ChannelCounter self.CalcTimeOut() else: common.writeLog('EPG-grabbing timeout, kill process', xbmc.LOGERROR) common.notifyOSD(__LS__(30000), __LS__(30015), common.IconError) self.Command.Kill() if self.__GrabFailed == True: common.writeLog("Error executing EPG update (3rd try)", xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30009), common.IconError) Busy = False elif self.__CurrentTry == 1: common.writeLog("Error executing EPG update (1st try)", xbmc.LOGWARNING) self.CalcTimeOut() self.__CurrentTry = 2 Busy = not self.StartGrabbing(self.__CurrentTry) else: common.writeLog("Error executing EPG update (2nd try)", xbmc.LOGWARNING) self.__GrabFailed = True self.CalcTimeOut() self.__CurrentTry = 3 Busy = not self.StartGrabbing(self.__CurrentTry) return Busy
def StartGrabbing(self, try_): Failed = False if try_ == 1: # first try # Copy logfile to old if os.path.exists(self.__wg_logfile): shutil.copy2(self.__wg_logfile, "%s.old" % (self.__wg_logfile)) else: common.writeLog("log-file not found, no copy made", xbmc.LOGWARNING) # Make backup if self.__backup_xml == True: if os.path.exists(self.__wg_xmlfile): shutil.copy2(self.__wg_xmlfile, "%s.bak" % (self.__wg_xmlfile)) else: common.writeLog("xml-file not found, no backup made", xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30007), common.IconStop) # try scan if os.path.exists(self.__wg_script): self.Command.Run([self.__wg_script]) else: common.writeLog("EPG-update script not found", xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30008), common.IconError) Failed = True elif try_ == 2: # second try # use fallback backup if failed if self.__backup_xml == True: if os.path.exists("%s.fallback" % (self.__wg_xmlfile)): common.writeLog("Try again using fallback xml-file", xbmc.LOGWARNING) shutil.move("%s.fallback" % (self.__wg_xmlfile), self.__wg_xmlfile) else: common.writeLog( "No fallback file found: Delete xml-file and try again with full grab", xbmc.LOGWARNING) if os.path.exists(self.__wg_xmlfile): os.remove(self.__wg_xmlfile) else: common.writeLog("No xml-file found to remove") else: common.writeLog( "No backup set: Delete xml-file and try again with full", xbmc.LOGWARNING) if os.path.exists(self.__wg_xmlfile): os.remove(self.__wg_xmlfile) else: common.writeLog("No xml-file found to remove") if os.path.exists(self.__wg_script): self.Command.Run([self.__wg_script]) else: common.writeLog("EPG-update script not found", xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30008), common.IconError) Failed = True else: # third try # complete new grab if os.path.exists(self.__wg_xmlfile): os.remove(self.__wg_xmlfile) else: common.writeLog("No xml-file found to remove") if os.path.exists(self.__wg_script): self.Command.Run([self.__wg_script]) else: common.writeLog("EPG-update script not found", xbmc.LOGERROR) common.notifyOSD(__LS__(30006), __LS__(30008), common.IconError) Failed = True return Failed