def pin_changed(gpio, level, tick):
  global g_gpio_pin
  global g_shutdown_time
  global g_reboot_time
  global g_pressed_time
  if (level == 0):
    g_pressed_time = datetime.now()
##    xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Shut:"+str((float(g_shutdown_time) - g_hibernate_time)/1000),1,__icon__))
##    xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Reb:"+str((float(g_reboot_time) - g_shutdown_time)/1000),1,__icon__))
##    time.sleep(float(g_shutdown_time)/1000)
##    lev = g_pi.read(g_gpio_pin)
##    if (lev == 0):
##      xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Shutdown",1,__icon__))
##    else:
##      return
##    time.sleep((float(g_reboot_time) - g_shutdown_time)/1000)
##    lev = g_pi.read(g_gpio_pin)
##    if (lev == 0):
##      xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Reboot",1,__icon__))
##    else:
##      return
  elif (level == 1):
    curtime = datetime.now()
    timediff = curtime - g_pressed_time
    ms = timediff.seconds*1000+timediff.microseconds/1000
    if ms > g_reboot_time:
      xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Rebooting",10,__icon__))
      time.sleep(5)
      xbmc.restart()
    elif ms > g_shutdown_time:
      xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Shuting down",10,__icon__))
      time.sleep(5)
      xbmc.shutdown()
Ejemplo n.º 2
0
    def setWakeup(self):

        if self.calcNextSched():
            __task = ['Recording', 'EPG-Update']
            writeLog('Wakeup for %s by %s at %s' %
                     (__task[self.__wakeUpStrOffset], self.__wakeup,
                      self.__wakeUp.strftime('%d.%m.%y %H:%M')),
                     level=xbmc.LOGDEBUG)
            if self.__nextsched:
                self.notifyOSD(
                    __LS__(30017),
                    __LS__(30018 + self.__wakeUpStrOffset) %
                    (self.__wakeUp.strftime('%d.%m.%Y %H:%M')))
        elif self.__nextsched:
            self.notifyOSD(__LS__(30010), __LS__(30014))
        if self.__nextsched: xbmc.sleep(5000)

        _sm = ['Kodi/XBMC', 'OS']
        writeLog('Instruct the system to shut down using %s method' %
                 (_sm[self.__shutdown]),
                 level=xbmc.LOGDEBUG)

        if self.__sudo:
            os.system('sudo %s %s %s %s' % (SHUTDOWN_CMD, self.__wakeup,
                                            self.__wakeUpUT, self.__shutdown))
        else:
            os.system('%s %s %s %s' % (SHUTDOWN_CMD, self.__wakeup,
                                       self.__wakeUpUT, self.__shutdown))
        if self.__shutdown == 0: xbmc.shutdown()
Ejemplo n.º 3
0
    def setWakeup(self):

        if xbmc.getCondVisibility('Player.Playing'):
            tools.writeLog('Stopping Player')
            xbmc.Player().stop()

        _flags = self.calcNextSched()
        tools.writeLog(
            'Instruct the system to shut down using %s' %
            ('Application' if self.__shutdown == 0 else 'OS'), xbmc.LOGNOTICE)
        tools.writeLog('Wake-Up Unix Time: %s' % (self.__wakeUpUT),
                       xbmc.LOGNOTICE)
        tools.writeLog(
            'Flags on resume points will be later {0:05b}'.format(_flags))

        os.system(
            '%s%s %s %s' %
            (self.__sudo, SHUTDOWN_CMD, self.__wakeUpUT, self.__shutdown))
        if self.__shutdown == 0: xbmc.shutdown()
        xbmc.sleep(1000)

        # If we suspend instead of poweroff the system, we need the flags to control the main loop of the service.
        # On suspend we have to resume the service on resume points instead of start on poweron/login.
        # additional we set the resume flag in calcNextSched if necessary

        return _flags
Ejemplo n.º 4
0
    def setWakeup(self, shutdown=True):
        if not self.__wakeUpUT:
            tools.writeLog('No recordings or EPG update to schedule')
        elif self.__wakeUpUT == self.__wakeUpUTRec:
            tools.writeLog('Recording wake-up time: %s' %
                           (self.__wakeUp.strftime('%d.%m.%y %H:%M')))
        elif self.__wakeUpUT == self.__wakeUpUTEpg:
            tools.writeLog('EPG update wake-up time: %s' %
                           (self.__wakeUp.strftime('%d.%m.%y %H:%M')))

        tools.writeLog('Wake-up Unix time: %s' % (self.__wakeUpUT),
                       xbmc.LOGINFO)
        #        tools.writeLog('Flags before shutdown are: {0:05b}'.format(self.__flags))

        if shutdown:
            # Show notifications
            if self.__nextsched:
                if self.__wakeUpUT == self.__wakeUpUTRec:
                    tools.Notify().notify(
                        __LS__(30017),
                        __LS__(30018) %
                        (self.__wakeUp.strftime('%d.%m.%Y %H:%M')))
                elif self.__wakeUpUT == self.__wakeUpUTEpg:
                    tools.Notify().notify(
                        __LS__(30017),
                        __LS__(30019) %
                        (self.__wakeUp.strftime('%d.%m.%Y %H:%M')))
                else:
                    tools.Notify().notify(__LS__(30010), __LS__(30014))

            if xbmc.getCondVisibility(
                    'Player.Playing') or xbmc.getCondVisibility(
                        'Player.Paused'):
                tools.writeLog('Stopping Player')
                xbmc.Player().stop()

            tools.writeLog(
                'Instruct the system to shut down using %s' %
                ('Application' if self.__shutdown == 0 else 'OS'),
                xbmc.LOGINFO)
            os.system(
                '%s%s %s %s' %
                (self.__sudo, SHUTDOWN_CMD, self.__wakeUpUT, self.__shutdown))
            if self.__shutdown == 0:
                xbmc.shutdown()
            xbmc.sleep(1000)
            return True
        else:
            os.system('%s%s %s %s' %
                      (self.__sudo, SHUTDOWN_CMD, self.__wakeUpUT, 0))

        return False
Ejemplo n.º 5
0
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 ...')
Ejemplo n.º 6
0
    def download_queue(self, shutdown=False):
        self.state = 0  #success

        counter = 0

        self.MainWindow.download_logo.setVisible(1)
        self.MainWindow.dlinfotekst.setVisible(1)

        while (self.state != -2) and (self.playlist_src.size() > 0) and (
                self.killed == False) and (self.running == True):
            header = str(counter + 1) + " of " + str(self.playlist_src.size() +
                                                     counter)
            self.download_file(self.playlist_src.list[0],
                               header)  #download single file

            if self.state == 0:
                #Download file completed successfully
                self.playlist_src.remove(0)
                #self.playlist_src.save(RootDir + downloads_queue)
                self.playlist_src.save(datapaths + downloads_queue)
                counter += 1
            elif self.state == -1:
                #Downlaod failed
                dialog = xbmcgui.Dialog()
                if dialog.yesno("Error", str(self.playlist_src.list[0].name),
                                "Download failed. Retry?") == False:
                    self.playlist_src.remove(0)
                    #self.playlist_src.save(RootDir + downloads_queue)
                    self.playlist_src.save(datapaths + downloads_queue)
                    counter += 1

            #Display the updated Queue playlist
            if (self.MainWindow.pl_focus == self.MainWindow.downloadqueue) or \
               (self.MainWindow.pl_focus == self.MainWindow.incompletelist) or \
               (self.MainWindow.pl_focus == self.MainWindow.downloadslist):
                self.MainWindow.ParsePlaylist(
                    reload=False)  #display download list

        if (self.shutdown == True) and (self.killed == False) and (self.running
                                                                   == True):
            self.MainWindow.onSaveSettings()
            self.MainWindow.delFiles(cacheDir)  #clear the cache first
            self.MainWindow.bkgndloadertask.kill()
            self.MainWindow.bkgndloadertask.join(10)  #timeout after 10 seconds
            xbmc.shutdown()  #shutdown XBMC

        self.running = False  #disable downloading

        self.MainWindow.dlinfotekst.setVisible(0)
        self.MainWindow.download_logo.setVisible(0)
Ejemplo n.º 7
0
def shutdown_check():
    shutdown_pin = 4
    GPIO.setup(shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    while True:
        pulsetime = 1
        GPIO.wait_for_edge(shutdown_pin, GPIO.RISING)
        time.sleep(0.01)
        while GPIO.input(shutdown_pin) == GPIO.HIGH:
            time.sleep(0.01)
            pulsetime += 1
        if pulsetime >= 2 and pulsetime <= 3:
            xbmc.restart()
        elif pulsetime >= 4 and pulsetime <= 5:
            xbmc.shutdown()
Ejemplo n.º 8
0
    def execute_system_action(self) -> None:

        if self.i_system_action == SYSTEM_ACTION_SHUTDOWN_KODI:
            xbmc.shutdown()

        elif self.i_system_action == SYSTEM_ACTION_QUIT_KODI:
            xbmc.executebuiltin("Quit()")

        elif self.i_system_action == SYSTEM_ACTION_STANDBY:
            xbmc.executebuiltin("Suspend()")

        elif self.i_system_action == SYSTEM_ACTION_HIBERNATE:
            xbmc.executebuiltin("Hibernate()")

        elif self.i_system_action == SYSTEM_ACTION_POWEROFF:
            xbmc.executebuiltin("Powerdown()")
Ejemplo n.º 9
0
    def setWakeup(self):

        if self.calcNextSched():
            __task = ['Recording', 'EPG-Update']
            writeLog('Wakeup for %s by %s at %s' % (__task[self.__wakeUpStrOffset], self.__wakeup,  self.__wakeUp.strftime('%d.%m.%y %H:%M')), level=xbmc.LOGDEBUG)
            if self.__nextsched: self.notifyOSD(__LS__(30017), __LS__(30018 + self.__wakeUpStrOffset) % (self.__wakeUp.strftime('%d.%m.%Y %H:%M')))
        elif self.__nextsched:
            self.notifyOSD(__LS__(30010), __LS__(30014))
        if self.__nextsched: xbmc.sleep(5000)

        _sm = ['Kodi/XBMC', 'OS']
        writeLog('Instruct the system to shut down using %s method' % (_sm[self.__shutdown]), level=xbmc.LOGDEBUG)

        if self.__sudo:
            os.system('sudo %s %s %s %s' % (SHUTDOWN_CMD, self.__wakeup, self.__wakeUpUT, self.__shutdown))
        else:
            os.system('%s %s %s %s' % (SHUTDOWN_CMD, self.__wakeup, self.__wakeUpUT, self.__shutdown))
        if self.__shutdown == 0: xbmc.shutdown()
Ejemplo n.º 10
0
    def download_queue(self, shutdown = False):
        self.state = 0 #success
        
        counter = 0
        
        self.MainWindow.download_logo.setVisible(1)
        self.MainWindow.dlinfotekst.setVisible(1)
        
        while (self.state != -2) and (self.playlist_src.size() > 0) and (self.killed == False) and (self.running == True):
            header = str(counter+1) + " of " + str(self.playlist_src.size()+counter)
            self.download_file(self.playlist_src.list[0], header) #download single file

            if self.state == 0:
                #Download file completed successfully
                self.playlist_src.remove(0)
                #self.playlist_src.save(RootDir + downloads_queue)
                self.playlist_src.save(datapaths + downloads_queue)
                counter += 1
            elif self.state == -1:     
                #Downlaod failed
                dialog = xbmcgui.Dialog()
                if dialog.yesno("Error",str(self.playlist_src.list[0].name),"Download failed. Retry?") == False:
                    self.playlist_src.remove(0)
                    #self.playlist_src.save(RootDir + downloads_queue)
                    self.playlist_src.save(datapaths + downloads_queue)
                    counter += 1
                                            
            #Display the updated Queue playlist
            if (self.MainWindow.pl_focus == self.MainWindow.downloadqueue) or \
               (self.MainWindow.pl_focus == self.MainWindow.incompletelist) or \
               (self.MainWindow.pl_focus == self.MainWindow.downloadslist):
                self.MainWindow.ParsePlaylist(reload=False) #display download list
               
        if (self.shutdown == True) and (self.killed == False) and (self.running == True):
            self.MainWindow.onSaveSettings()
            self.MainWindow.delFiles(cacheDir) #clear the cache first        
            self.MainWindow.bkgndloadertask.kill()
            self.MainWindow.bkgndloadertask.join(10) #timeout after 10 seconds        
            xbmc.shutdown() #shutdown XBMC
        
        self.running = False #disable downloading
        
        self.MainWindow.dlinfotekst.setVisible(0)        
        self.MainWindow.download_logo.setVisible(0)
    def hook_turn_off_action(self):
        log(["Turn off post action?", self.turn_off_action])
        if self.turn_off_action == "none": return False

        while self.scan_running():
            log(["scan running", "waiting"])
            time.sleep(10)

        self.post_action_executed = True

        if self.turn_off_action == "restart":
            xbmc.executebuiltin('XBMC.RestartApp()')
        elif self.turn_off_action == "quit":
            xbmc.executebuiltin('XBMC.Quit()')
        elif self.turn_off_action == "reboot":
            xbmc.restart()
        elif self.turn_off_action == "shutdown":
            xbmc.shutdown()

        return True
Ejemplo n.º 12
0
    def download_queue(self, shutdown=False):
        self.state = 0  # success

        index = 0
        counter = 0
        size = self.playlist_src.size()

        self.MainWindow.download_logo.setVisible(1)
        self.MainWindow.dlinfotekst.setVisible(1)

        while (
            (self.state != -2)
            and (index < self.playlist_src.size())
            and (self.killed == False)
            and (self.running == True)
        ):
            header = str(counter + 1) + " of " + str(size)
            self.download_file(self.playlist_src.list[0], shutdown, header)  # download single file

            if self.state == 0:
                # only on success remove the item
                self.playlist_src.remove(0)
                self.playlist_src.save(RootDir + downloads_queue)
            else:
                index = index + 1

            counter = counter + 1

            # Display the updated Queue playlist
            if (self.MainWindow.pl_focus == self.MainWindow.downloadqueue) or (
                self.MainWindow.pl_focus == self.MainWindow.downloadslist
            ):
                self.MainWindow.ParsePlaylist(reload=False)  # display download list

        if (self.shutdown == True) and (self.killed == False) and (self.running == True):
            xbmc.shutdown()  # shutdown the X-box

        self.MainWindow.dlinfotekst.setVisible(0)
        self.MainWindow.download_logo.setVisible(0)
Ejemplo n.º 13
0
def pin_changed(gpio, level, tick):
    global g_gpio_pin
    global g_shutdown_time
    global g_reboot_time
    global g_pressed_time
    if (level == 0):
        g_pressed_time = datetime.now()


##    xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Shut:"+str((float(g_shutdown_time) - g_hibernate_time)/1000),1,__icon__))
##    xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Reb:"+str((float(g_reboot_time) - g_shutdown_time)/1000),1,__icon__))
##    time.sleep(float(g_shutdown_time)/1000)
##    lev = g_pi.read(g_gpio_pin)
##    if (lev == 0):
##      xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Shutdown",1,__icon__))
##    else:
##      return
##    time.sleep((float(g_reboot_time) - g_shutdown_time)/1000)
##    lev = g_pi.read(g_gpio_pin)
##    if (lev == 0):
##      xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__scriptname__,"Reboot",1,__icon__))
##    else:
##      return
    elif (level == 1):
        curtime = datetime.now()
        timediff = curtime - g_pressed_time
        ms = timediff.seconds * 1000 + timediff.microseconds / 1000
        if ms > g_reboot_time:
            xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" %
                                (__scriptname__, "Rebooting", 10, __icon__))
            time.sleep(5)
            xbmc.restart()
        elif ms > g_shutdown_time:
            xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" %
                                (__scriptname__, "Shuting down", 10, __icon__))
            time.sleep(5)
            xbmc.shutdown()
Ejemplo n.º 14
0
 def download_queue(self, shutdown = False):
     self.state = 0 #success
     
     index = 0
     counter = 0
     size = self.playlist_src.size()
     
     self.MainWindow.download_logo.setVisible(1)
     self.MainWindow.dlinfotekst.setVisible(1)
     
     while (self.state != -2) and (index < self.playlist_src.size()) and (self.killed == False) and (self.running == True):
         header = str(counter+1) + " of " + str(size)
         self.download_file(self.playlist_src.list[0], shutdown, header) #download single file
         
         if self.state == 0:
             #only on success remove the item
             self.playlist_src.remove(0)
             self.playlist_src.save(RootDir + downloads_queue)
         else:
             index = index + 1
         
         counter = counter + 1
         
         #Display the updated Queue playlist
         if (self.MainWindow.pl_focus == self.MainWindow.downloadqueue) or \
            (self.MainWindow.pl_focus == self.MainWindow.downloadslist):
             self.MainWindow.ParsePlaylist(reload=False) #display download list
            
     if (self.shutdown == True) and (self.killed == False) and (self.running == True):
         self.MainWindow.onSaveSettings()
         self.MainWindow.delFiles(cacheDir) #clear the cache first        
         self.MainWindow.bkgndloadertask.kill()
         self.MainWindow.bkgndloadertask.join(10) #timeout after 10 seconds        
         xbmc.shutdown() #shutdown the X-box
     
     self.MainWindow.dlinfotekst.setVisible(0)        
     self.MainWindow.download_logo.setVisible(0)
Ejemplo n.º 15
0
	def save_playlist(self):
		self.time = self.player.getTime()
		self.plist = xbmc.PlayList(0)
		self.plsize = self.plist.size()
		if self.plsize > self.maximum_pls_size:#XBMC chokes on large playlists, this limits the # of entries to be safe
			self.plsize = self.maximum_pls_size
		self.place = self.plist.getposition()
		self.playing = self.player.getPlayingFile()
		
		f = open(self.xmlfile, "wb")
		f.write("<data>\n")
		f.write("\t<time>"+str(self.time)+"</time>\n")
		f.write("\t<plspos>"+str(self.place)+"</plspos>\n")
		if self.plsize != "-":
			for i in range (0 , self.plsize): 
				f.write("\t<plistfile>"+str(xbmc.PlayListItem.getfilename(self.plist[i]))+"</plistfile>\n")
		f.write("\t<playing>"+str(self.playing)+"</playing>\n")
		f.write("</data>\n")
		f.close()
		
		self.fade_out_music()
		self.player.stop()
		xbmc.executebuiltin("XBMC.SetVolume(100)")
		xbmc.shutdown()
Ejemplo n.º 16
0
def close_kodi_force():
    xbmc.shutdown()
Ejemplo n.º 17
0
 def systemShutdown(self):
     notifyLog('init system shutdown')
     xbmc.shutdown()
Ejemplo n.º 18
0
def shutdown():
    xbmc.shutdown()
Ejemplo n.º 19
0
 def systemShutdown(self):
     notifyLog('init system shutdown')
     xbmc.shutdown()
Ejemplo n.º 20
0
    # Create a summary file for quick viewing without looking into dat files
    with open('/home/osmc/.kodi/userdata/Automation.dat/summary.dat',
              'w+') as f_info:
        f_info.write('Current show: %s\n' % (show))
        f_info.write('Current episode: %d\n' % (start + k))
        f_info.write('Current playlist:\n')
        for i in range(len(current_playlist)):
            if i == k:
                f_info.write('> %d. %s\n' % (i + 1, current_playlist[i]))
            else:
                f_info.write('  %d. %s\n' % (i + 1, current_playlist[i]))

        # Create a history log
        with open(
                "/home/osmc/.kodi/userdata/Automation.dat/" + show +
                "_hist.dat", "a") as f_hist:
            f_hist.write('%d\n' % (start + k))

    # Sleep until episode ends         # REMOVE ON TEST
    time.sleep(episode_duration)  # REMOVE ON TEST
time.sleep(60 * 3)  # REMOVE ON TEST

with open('/home/osmc/.kodi/userdata/Automation.dat/summary.dat',
          'w+') as f_info:
    f_info.write('No show playing at the moment.\n')
    f_info.close()

## Log playlist at the end of playthrough    # REMOVE ON TEST
xbmc.shutdown()  # REMOVE ON TEST
Ejemplo n.º 21
0
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with XBMC; see the file COPYING.  If not, write to
#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html
#

import xbmc, xbmcgui

dialog = xbmcgui.Dialog()

list = [
    'yes', 'no', 'cancel', 'movies', 'f:\\music\\test', 'test', '67', 'true'
]
list.append('last item')
selected = dialog.select('select an item', list)
dialog.ok('user selected', 'item nr : ' + str(selected), list[selected])

selected = dialog.select('select an action', ['Cancel', 'Reboot', 'Shut Down'])

if selected == 1:
    xbmc.restart()
elif selected == 2:
    xbmc.shutdown()
Ejemplo n.º 22
0
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with XBMC; see the file COPYING.  If not, write to
#  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html
#

import xbmc, xbmcgui

dialog = xbmcgui.Dialog()

list = ['yes','no','cancel','movies','f:\\music\\test','test','67','true']
list.append('last item')
selected = dialog.select('select an item', list)
dialog.ok('user selected', 'item nr : ' + str(selected), list[selected])

selected = dialog.select('select an action', ['Cancel', 'Reboot', 'Shut Down'])

if selected == 1:
	xbmc.restart()
elif selected == 2:
	xbmc.shutdown()
Ejemplo n.º 23
0
def service():

    flags = getStatusFlags(isUSR)
    Mon.waitForShutdown = True if Mon.setting['server_mode'] else False

    # This is the initial startup after boot, if flags isREC | isEPG are set, a recording
    # or EPG update is immediately started. set 'poweroff' to true, also set 'observe' to true
    # avoiding notifications on initial startup

    if flags & (isREC | isEPG | isATF):
        Mon.waitForShutdown = True
        Mon.observe = True

    # start EPG grabber threads

    if flags & isEPG:
        thread = EpgThread(Mon.setting['epg_mode'])
        thread.start()

    # ::MAIN LOOP::

    walker = 0
    cycle = Mon.setting['idle_time'] if Mon.setting['server_mode'] else DEFAULT_CYCLE

    while not Mon.abortRequested():

        while walker < cycle:
            if Mon.abortRequested():
                break

            if Mon.settingsChanged:
                Mon.getAddonSettings()
                Mon.settingsChanged = False

                # define check interval depending on addon mode
                cycle = Mon.setting['idle_time'] if Mon.setting['server_mode'] else DEFAULT_CYCLE

            idle = xbmc.getGlobalIdleTime()
            xbmc.sleep(1000)

            # check for user activity and power off required by user
            if xbmc.getGlobalIdleTime() < idle:

                if str2bool(getProperty('poweroff')):
                    log('Shutdown required by user')
                    Mon.waitForShutdown = True
                    Mon.observe = False
                    setProperty('poweroff', False)
                    break
                else:
                    if Mon.waitForShutdown:
                        log('User activity detected, revoke shutdown')
                        Mon.waitForShutdown = False

            walker += 1

        flags = getStatusFlags(flags)
        if flags & isPWR:

            if not flags & (isREC | isEPG | isPRG | isNET | isATF):

                if not countDown():
                    Mon.waitForShutdown = False
                    continue

                # power off
                _t = 0
                if Mon.calcNextEvent():
                    _m, _t = Mon.calcNextEvent()
                    _ft = datetime.strftime(datetime.fromtimestamp(_t), LOCAL_TIME_FORMAT)
                    log('next schedule: {}'.format(_ft))
                    if Mon.setting['show_next_sched'] and not Mon.setting['server_mode']:
                        notify(loc(30024), loc(_m).format(_ft))
                else:
                    log('no schedules')
                    if Mon.setting['show_next_sched'] and not Mon.setting['server_mode']:
                        notify(loc(30040), loc(30014))

                xbmc.sleep(5000)
                log('set RTC to {}'.format(_t))
                if osv['PLATFORM'] == 'Linux':
                    sudo = 'sudo ' if Mon.setting['sudo'] else ''
                    os.system('%s%s %s %s %s' % (sudo, SHUTDOWN_CMD, _t,
                                                 Mon.setting['shutdown_method'],
                                                 Mon.setting['shutdown_mode']))

                if Mon.setting['shutdown_method'] == 0 or osv['PLATFORM'] == 'Windows':
                    xbmc.shutdown()

            if not Mon.observe:
                if flags & isREC:
                    notify(loc(30015), loc(30020), icon=xbmcgui.NOTIFICATION_WARNING)  # Notify 'Recording in progress'
                elif flags & isEPG:
                    notify(loc(30015), loc(30021), icon=xbmcgui.NOTIFICATION_WARNING)  # Notify 'EPG-Update'
                elif flags & isPRG:
                    notify(loc(30015), loc(30022), icon=xbmcgui.NOTIFICATION_WARNING)  # Notify 'Postprocessing'
                elif flags & isNET:
                    notify(loc(30015), loc(30023), icon=xbmcgui.NOTIFICATION_WARNING)  # Notify 'Network active'
                elif flags & isATF:
                    notify(loc(30015), loc(30033), icon=xbmcgui.NOTIFICATION_WARNING)  # Notify 'Time Frame active'
                Mon.observe = True

        walker = 0
Ejemplo n.º 24
0
def shutdown():
    xbmc.shutdown()