Esempio n. 1
0
def main():
    feedback = argument_opt()
    if feedback.result == False:
        sys.stdout.write(handler.info)
        sys.exit(1)
    elif feedback.shutdown:
        shutdown()
    else:
        if feedback.watchdog:
            walk_watchdog()
        run_app(feedback)
Esempio n. 2
0
def main():
    feedback = argument_opt()
    if feedback.result == False:
        sys.stdout.write(handler.info)
        sys.exit(1)
    elif feedback.shutdown:
        shutdown()
    else:
        if feedback.watchdog:
            walk_watchdog()
        run_app(feedback)
Esempio n. 3
0
def shutdown(menuw=None, argshutdown=None, argrestart=None, exit=False):
    """
    Function to shut down freevo or the whole system. This system will be
    shut down when argshutdown is True, restarted when argrestart is true,
    else only Freevo will be stopped.
    """
    _debug_(
        'shutdown(menuw=%r, argshutdown=%r, argrestart=%r, exit=%r)' %
        (menuw, argshutdown, argrestart, exit), 2)
    import osd
    import plugin
    import rc
    import util.mediainfo

    osd = osd.get_singleton()

    util.mediainfo.sync()
    if not osd.active:
        # this function is called from the signal handler, but
        # we are dead already.
        sys.exit(0)

    osd.clearscreen(color=osd.COL_BLACK)
    osd.drawstringframed(_('shutting down...'),
                         0,
                         0,
                         osd.width,
                         osd.height,
                         osd.getfont(config.OSD_DEFAULT_FONTNAME,
                                     config.OSD_DEFAULT_FONTSIZE),
                         fgcolor=osd.COL_ORANGE,
                         align_h='center',
                         align_v='center')
    osd.update()
    time.sleep(0.5)

    if argshutdown or argrestart:
        # shutdown dual head for mga
        if config.CONF.display == 'mga':
            os.system('%s runapp matroxset -f /dev/fb1 -m 0' %
                      os.environ['FREEVO_SCRIPT'])
            time.sleep(1)
            os.system('%s runapp matroxset -f /dev/fb0 -m 1' %
                      os.environ['FREEVO_SCRIPT'])
            time.sleep(1)

        _debug_('mga:plugin.shutdown()', 2)
        plugin.shutdown()
        _debug_('mga:rc.shutdown()', 2)
        rc.shutdown()
        _debug_('mga:osd.shutdown()', 2)
        osd.shutdown()

        if argshutdown and not argrestart:
            os.system(config.SYS_SHUTDOWN_CMD)
        elif argrestart and not argshutdown:
            os.system(config.SYS_RESTART_CMD)
        # let freevo be killed by init, looks nicer for mga
        while 1:
            time.sleep(1)
        return

    #
    # Exit Freevo
    #

    # Shutdown any daemon plugins that need it.
    _debug_('plugin.shutdown()', 2)
    plugin.shutdown()

    # Shutdown all children still running
    _debug_('rc.shutdown()', 2)
    rc.shutdown()

    # SDL must be shutdown to restore video modes etc
    _debug_('osd.clearscreen(color=osd.COL_BLACK)', 2)
    osd.clearscreen(color=osd.COL_BLACK)
    _debug_('osd.shutdown()', 2)
    osd.shutdown()

    _debug_('config.shutdown()', 2)
    config.shutdown()

    if exit:
        # realy exit, we are called by the signal handler
        sys.exit(0)

    _debug_('%s stop' % os.environ['FREEVO_SCRIPT'], 2)
    os.system('%s stop' % os.environ['FREEVO_SCRIPT'])

    # Just wait until we're dead. SDL cannot be polled here anyway.
    while 1:
        time.sleep(1)
Esempio n. 4
0
def shutdown(menuw=None, mode=None, exit=False):
    """
    Function to shut down freevo or the whole system. This system will be
    shut down when argshutdown is True, restarted when argrestart is true,
    else only Freevo will be stopped.
    """
    logger.debug('shutdown(menuw=%r, mode=%r, exit=%r)', menuw, mode, exit)
    if ShutdownModes.shutdown_in_progress:
        logger.debug('shutdown in progress')
        return
    ShutdownModes.shutdown_in_progress = True
    import osd
    import plugin
    import rc
    import util.mediainfo
    osd = osd.get_singleton()
    util.mediainfo.sync()
    if not osd.active:
        # this function is called from the signal handler, but we are dead
        # already.
        sys.exit(0)

    skin.get_singleton().suspend()
    osd.clearscreen(color=osd.COL_BLACK)
    if mode == ShutdownModes.SYSTEM_SHUTDOWN:
        msg = _('Shutting down...')
    elif mode == ShutdownModes.SYSTEM_RESTART:
        msg = _('Restarting...')
    else:
        msg = _('Exiting...')
    osd.drawstringframed(msg, 0, 0, osd.width, osd.height,
        osd.getfont(config.OSD_DEFAULT_FONTNAME, config.OSD_DEFAULT_FONTSIZE),
        fgcolor=osd.COL_ORANGE, align_h='center', align_v='center')
    osd.update()
    time.sleep(0.5)

    if mode == ShutdownModes.SYSTEM_SHUTDOWN or mode == ShutdownModes.SYSTEM_RESTART:
        # shutdown dual head for mga
        if config.CONF.display == 'mga':
            os.system('%s runapp matroxset -f /dev/fb1 -m 0' % os.environ['FREEVO_SCRIPT'])
            time.sleep(1)
            os.system('%s runapp matroxset -f /dev/fb0 -m 1' % os.environ['FREEVO_SCRIPT'])
            time.sleep(1)

        logger.debug('sys:plugin.shutdown()')
        plugin.shutdown()
        logger.debug('sys:rc.shutdown()')
        rc.shutdown()
        #if config.CONF.display == 'mga':
        logger.debug('sys:osd.shutdown()')
        osd.shutdown()

        if mode == ShutdownModes.SYSTEM_SHUTDOWN:
            logger.debug('os.system(%r)', config.SYS_SHUTDOWN_CMD)
            os.system(config.SYS_SHUTDOWN_CMD)
        elif ShutdownModes.SYSTEM_RESTART:
            logger.debug('os.system(%r)', config.SYS_RESTART_CMD)
            os.system(config.SYS_RESTART_CMD)

        # this closes the log
        logger.debug('sys:config.shutdown()')
        config.shutdown()

        # let freevo be killed by init, looks nicer for mga
        print 'Freevo shutdown'
        while True:
            time.sleep(1)

    #
    # Exit Freevo
    #

    # shutdown any daemon plugins that need it.
    logger.debug('plugin.shutdown()')
    plugin.shutdown()
    # shutdown registered callbacks
    logger.debug('rc.shutdown()')
    rc.shutdown()
    # SDL must be shutdown to restore video modes etc
    logger.log( 9, 'osd.clearscreen(color=osd.COL_BLACK)')
    osd.clearscreen(color=osd.COL_BLACK)
    logger.debug('osd.shutdown()')
    osd.shutdown()
    logger.debug('config.shutdown()')
    config.shutdown()

    if exit:
        # really exit, we are called by the signal handler
        logger.debug('raise SystemExit')
        raise SystemExit

    # We must use spawn instead of os.system here because the python interpreter
    # lock is held by os.system until the command returns, which prevents receiving
    # any signals.
    logger.log( 9, '%s --stop', os.environ['FREEVO_SCRIPT'])
    os.spawnlp(os.P_NOWAIT, os.environ['FREEVO_SCRIPT'], os.environ['FREEVO_SCRIPT'], '--stop')

    # Just wait until we're dead. SDL cannot be polled here anyway.
    while True:
        time.sleep(1)