Beispiel #1
0
 def onClick(self, controlId):
     if (controlId == BUTTON_FORCE):
         self.getControl(BUTTON_FORCE).setEnabled(False)
         common.writeLog("Force Grabbing ....")
         common.DoComm(common.CMD_FORCESTART)
     if (controlId == BUTTON_EXIT):
         self.ExitScript()
Beispiel #2
0
 def ExitScript(self):
     common.writeLog("Exit script")
     if self.rt != None:
         self.rt.stop()
     del self.LogInfo
     del self.WGInfoOld
     self.close()
 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 ExitScript(self):
     common.writeLog("Exit script")
     if self.rt != None:
         self.rt.stop()
     del self.LogInfo
     del self.WGInfoOld
     self.close()
 def onClick(self, controlId):
     if (controlId == BUTTON_FORCE):
         self.getControl(BUTTON_FORCE).setEnabled(False)
         common.writeLog("Force Grabbing ....")
         common.DoComm(common.CMD_FORCESTART)
     if (controlId == BUTTON_EXIT):
         self.ExitScript()
Beispiel #6
0
def SocketMsg(msg):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        port = int(__addon__.getSetting('socket_port'))
        s.connect(('localhost', port))
        s.send(msg)
        s.close()
    except:
        common.writeLog("[Remote] Error sending return message: %s" % msg)
def SocketMsg(msg):
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        port = int(__addon__.getSetting('socket_port'))
        s.connect(('localhost', port))
        s.send(msg)
        s.close()
    except:
        common.writeLog("[Remote] Error sending return message: %s"%msg)
 def PostProcPost(self):
     #notify
     #if self.__notify_status == True:
     #    common.notifyOSD(__LS__(30000), __LS__(30018),common.IconInfo)
     # Update kodi
     if self.__update_kodi == True:
         if self.__not_update_running == True:
             if xbmc.getCondVisibility('Pvr.IsPlayingTv|Pvr.IsPlayingRadio|Pvr.IsPlayingRecording|Pvr.IsRecording') == True:
                 return
         xbmc.executebuiltin('StartPVRManager')
     common.writeLog('Post processing finished ...')
     return   
 def Receive(self):
     msg = None
     try: 
         msg = self.ss.recv(63)
     except socket.timeout:
         msg = None
     except socket.error, e:
         msg = None
         common.writeLog("[Remote] Error socket connection: %s"%e)
         if self.ss != None:
             self.ss.close()
             self.ss = None
 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 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 PostProcPost(self):
     #notify
     #if self.__notify_status == True:
     #    common.notifyOSD(__LS__(30000), __LS__(30018),common.IconInfo)
     # Update kodi
     if self.__update_kodi == True:
         if self.__not_update_running == True:
             if xbmc.getCondVisibility(
                     'Pvr.IsPlayingTv|Pvr.IsPlayingRadio|Pvr.IsPlayingRecording|Pvr.IsRecording'
             ) == True:
                 return
         xbmc.executebuiltin('StartPVRManager')
     common.writeLog('Post processing finished ...')
     return
 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 TryConn(self):
     Success = False
     if self.ss != None:
         Success = True
     else:
         try:
             self.ss,sockname = self.sock.accept()
             self.ss.settimeout(0.05)
             self.Counter = 0
             common.writeLog("[Remote] Socket connection established to: %s"%str(sockname))
             Success = True
         except socket.error, e:
             #common.writeLog("[Remote] Error socket connection: %s"%e)
             if self.ss != None:
                 self.ss.close()
                 self.ss = None
             Success = False
 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 TryConn(self):
     Success = False
     if self.ss != None:
         Success = True
     else:
         try:
             self.ss, sockname = self.sock.accept()
             self.ss.settimeout(0.05)
             self.Counter = 0
             common.writeLog(
                 "[Remote] Socket connection established to: %s" %
                 str(sockname))
             Success = True
         except socket.error as e:
             #common.writeLog("[Remote] Error socket connection: %s"%e)
             if self.ss != None:
                 self.ss.close()
                 self.ss = None
             Success = False
     return Success
 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 start(self):
        if common.IsRunning():
            common.writeLog(
                'Attempting to start service while service already running, quit ....',
                xbmc.LOGERROR)
            return

        common.Run()
        common.writeLog('Starting service (%s)' % (self.__rndProcNum))

        bKillMain = False
        bStartApp = True

        ### START MAIN LOOP ###
        # Wait 10 seconds before reading old logfile to overcome python timer bug
        SchedulerCount = 0
        while (not xbmc.Monitor().abortRequested()) and (not bKillMain):
            xbmc.sleep(common.COMMAND_LOOP)
            self.GetAndExecuteCommand()
            self.GetAndExecuteSockCommand()
            if (SchedulerCount < SCHEDULERTIME):
                SchedulerCount += 1
            else:
                SchedulerCount = 0
                if bStartApp == True:
                    bStartApp = False
                    self.ReadFromLogFile()
                self.Scheduler()

        ### END MAIN LOOP ###

        self.KillThreads()
        self.SockComm.Close()
        common.Stop()
        common.writeLog('Service(%s) finished' % (self.__rndProcNum))
    def start(self):
        if common.IsRunning():
            common.writeLog('Attempting to start service while service already running, quit ....', xbmc.LOGERROR)
            return

        common.Run()
        common.writeLog('Starting service (%s)' % (self.__rndProcNum))
             
        bKillMain = False
        bStartApp = True

        ### START MAIN LOOP ###
        # Wait 10 seconds before reading old logfile to overcome python timer bug
        SchedulerCount = 0
        while (not xbmc.abortRequested) and (not bKillMain):
            xbmc.sleep(common.COMMAND_LOOP)
            self.GetAndExecuteCommand()
            self.GetAndExecuteSockCommand()
            if (SchedulerCount < SCHEDULERTIME):
                SchedulerCount += 1
            else:
                SchedulerCount = 0
                if bStartApp == True:
                    bStartApp = False
                    self.ReadFromLogFile()
                self.Scheduler()

        ### END MAIN LOOP ###
        
        self.KillThreads()
        self.SockComm.Close()
        common.Stop()
        common.writeLog('Service(%s) finished' % (self.__rndProcNum))
 def Receive(self):
     msg = None
     try:
         msg = self.ss.recv(63).decode("utf-8")
     except socket.timeout:
         msg = None
     except socket.error as e:
         msg = None
         common.writeLog("[Remote] Error socket connection: %s" % e)
         if self.ss != None:
             self.ss.close()
             self.ss = None
     else:
         if len(msg) == 0:
             msg = None
             if (self.Counter < SOCKET_TIMEOUT):
                 self.Counter += 1
             else:
                 if self.ss != None:
                     self.ss.close()
                     self.ss = None
                 common.writeLog(
                     "[Remote] Socket connection closed by timeout")
         else:
             if (msg == CMD_CONNQUIT):
                 if self.ss != None:
                     self.ss.close()
                     self.ss = None
                 common.writeLog("[Remote] Socket connection closed")
                 msg = None
             else:
                 self.Counter = 0
     return msg
 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 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
        s.send(msg)
        s.close()
    except:
        common.writeLog("[Remote] Error sending return message: %s"%msg)



#########################################################
######################## MAIN ###########################
#########################################################
if len(sys.argv) > 1:
    if sys.argv[1].lower() == "-h":
        PrintHelp()
    elif sys.argv[1].lower() == "-l": ## Just for testing, remove later
        SocketMsg("I'm alive !!!!")
        common.writeLog("[Remote] Testing communication ...")
    elif sys.argv[1].lower() == "-s":
        if common.IsRunning():
            status = common.DoComm(common.CMD_GETSTATUS)
            SocketMsg(status)
            #common.writeLog("[Remote] Get Status: %s"%status)
        else:
            SocketMsg("<Error>")
            common.writeLog("[Remote] Get Status")
            common.writeLog("Error: Service not running ...")
    elif sys.argv[1].lower() == "-g":
        common.writeLog("[Remote] Start Grabbing ...")
        if common.IsRunning():
            common.DoComm(common.CMD_FORCESTART)
            SocketMsg("<Ready>")
        else:
 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 
Beispiel #27
0
        s.connect(('localhost', port))
        s.send(msg)
        s.close()
    except:
        common.writeLog("[Remote] Error sending return message: %s" % msg)


#########################################################
######################## MAIN ###########################
#########################################################
if len(sys.argv) > 1:
    if sys.argv[1].lower() == "-h":
        PrintHelp()
    elif sys.argv[1].lower() == "-l":  ## Just for testing, remove later
        SocketMsg("I'm alive !!!!")
        common.writeLog("[Remote] Testing communication ...")
    elif sys.argv[1].lower() == "-s":
        if common.IsRunning():
            status = common.DoComm(common.CMD_GETSTATUS)
            SocketMsg(status)
            #common.writeLog("[Remote] Get Status: %s"%status)
        else:
            SocketMsg("<Error>")
            common.writeLog("[Remote] Get Status")
            common.writeLog("Error: Service not running ...")
    elif sys.argv[1].lower() == "-g":
        common.writeLog("[Remote] Start Grabbing ...")
        if common.IsRunning():
            common.DoComm(common.CMD_FORCESTART)
            SocketMsg("<Ready>")
        else:
 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 Send(self, msg):
     try:
         self.ss.send(msg.encode("utf-8"))
     except socket.error as e:
         common.writeLog("[Remote] Error socket connection: %s" % e)
         self.ss = None
        common.writeLog('Service(%s) finished' % (self.__rndProcNum))

        ##################################### END OF MAIN SERVICE #####################################


#########################################################

#########################################################
######################## MAIN ###########################
#########################################################
WGMan = Manager()

#always check if manager is not already running, otherwise start manager
if not common.IsRunning():
    WGMan.start()

    __p = platform.uname()

    common.writeLog('<<<')
    common.writeLog('              _\|:|/_        BYE BYE')
    common.writeLog('               (o -)')
    common.writeLog('------------ooO-(_)-Ooo----- V.%s on %s --' %
                    (__version__, __p[1]))
    common.writeLog('<<<\n')
else:
    common.writeLog(
        'Attempting to start service while service already running')

del WGMan
#########################################################
 def Send(self,msg):
     try:
         self.ss.send(msg)
     except socket.error, e:
         common.writeLog("[Remote] Error socket connection: %s"%e)
         self.ss = None
            xbmc.shutdown()
        elif command == common.CMD_SUSPEND:
            xbmc.suspend()
        elif command == common.CMD_HIBERNATE:
            xbmc.hibernate()
        else:
            common.writeLog('Unable to perform action ...')
#########################################################

#########################################################
######################## MAIN ###########################
#########################################################
if len(sys.argv) > 1:
    s = sys.argv[1].lower()
    if s == 'checkmailsettings':
        common.writeLog('Send test E-Mail')
        setShutdown(common.CMD_SENDMAIL)
    elif s == "shutdown":
        common.writeLog('Powerbutton is pressed')
        setShutdown(common.CMD_SHUTDOWN)
    elif s == "suspend":
        common.writeLog('Powerbutton is pressed')
	setShutdown(common.CMD_SUSPEND)
    elif s == "hibernate":
        common.writeLog('Powerbutton is pressed')
	setShutdown(common.CMD_HIBERNATE)
    else: # remote
        common.writeLog('Powerbutton is pressed')
	setShutdown(common.getShutdownAction())
else:
    common.writeLog('Powerbutton is pressed')
     except socket.error, e:
         msg = None
         common.writeLog("[Remote] Error socket connection: %s"%e)
         if self.ss != None:
             self.ss.close()
             self.ss = None
     else:
         if len(msg) == 0:
             msg = None
             if (self.Counter < SOCKET_TIMEOUT):
                 self.Counter += 1
             else:
                 if self.ss != None:
                     self.ss.close()
                     self.ss = None
                 common.writeLog("[Remote] Socket connection closed by timeout")
         else:
             if (msg == CMD_CONNQUIT):
                 if self.ss != None:
                     self.ss.close()
                     self.ss = None
                 common.writeLog("[Remote] Socket connection closed")
                 msg = None
             else:
                 self.Counter = 0
     return msg
 
 def Send(self,msg):
     try:
         self.ss.send(msg)
     except socket.error, e:
 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