/usr/share/pyshared/freevo/plugins/shutdown.py is in python-freevo 1.9.2b2-4.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | # -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# shutdown plug-in and handling
# -----------------------------------------------------------------------
# $Id: shutdown.py 11905 2011-11-14 21:54:46Z adam $
#
# Author:
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, 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 MER-
# CHANTABILITY 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 this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------
import logging
logger = logging.getLogger("freevo.plugins.shutdown")
import os
import time
import sys
import config
import skin
from gui import ConfirmBox
from item import Item
from plugin import MainMenuPlugin
from dialog.dialogs import ButtonDialog, WidgetDialog
from dialog.widgets import ButtonModel
class ShutdownModes:
FREEVO_SHUTDOWN = 'freevo_shutdown'
SYSTEM_SHUTDOWN = 'system_shutdown'
SYSTEM_RESTART = 'system_restart'
shutdown_in_progress = False
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.
"""
_debug_('shutdown(menuw=%r, mode=%r, exit=%r)' % (menuw, mode, exit), 1)
if ShutdownModes.shutdown_in_progress:
_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)
_debug_('sys:plugin.shutdown()')
plugin.shutdown()
_debug_('sys:rc.shutdown()')
rc.shutdown()
#if config.CONF.display == 'mga':
_debug_('sys:osd.shutdown()')
osd.shutdown()
if mode == ShutdownModes.SYSTEM_SHUTDOWN:
_debug_('os.system(%r)' % (config.SYS_SHUTDOWN_CMD,))
os.system(config.SYS_SHUTDOWN_CMD)
elif ShutdownModes.SYSTEM_RESTART:
_debug_('os.system(%r)' % (config.SYS_RESTART_CMD,))
os.system(config.SYS_RESTART_CMD)
# this closes the log
_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.
_debug_('plugin.shutdown()')
plugin.shutdown()
# shutdown registered callbacks
_debug_('rc.shutdown()')
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()')
osd.shutdown()
_debug_('config.shutdown()')
config.shutdown()
if exit:
# really exit, we are called by the signal handler
_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.
_debug_('%s --stop' % os.environ['FREEVO_SCRIPT'], 2)
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)
class ShutdownItem(Item):
"""
Item for shutdown
"""
def __init__(self, parent=None):
_debug_('ShutdownItem.__init__(parent=%r)' % (parent,), 2)
Item.__init__(self, parent, skin_type='shutdown')
self.menuw = None
def actions(self):
"""
return a list of actions for this item
"""
_debug_('ShutdownItem.actions()', 2)
if config.SYS_SHUTDOWN_CONFIRM:
if config.SHUTDOWN_NEW_STYLE_DIALOG:
items = [ (self.new_confirm_exit, _('Shutdown Freevo'))]
else:
items = [ (self.confirm_freevo, _('Shutdown Freevo') ),
(self.confirm_system, _('Shutdown system') ),
(self.confirm_system_restart, _('Restart system') ) ]
else:
items = [ (self.shutdown_freevo, _('Shutdown Freevo') ),
(self.shutdown_system, _('Shutdown system') ),
(self.shutdown_system_restart, _('Restart system') ) ]
if config.SYS_SHUTDOWN_ENABLE and not config.SHUTDOWN_NEW_STYLE_DIALOG:
items = [ items[1], items[0], items[2] ]
return items
def new_confirm_exit(self, arg=None, menuw=None):
"""
Pops up a ConfirmBox.
"""
_debug_('confirm_freevo(arg=%r, menuw=%r)' % (arg, menuw), 2)
self.menuw = menuw
dialog = ShutdownDialog()
dialog.show()
def confirm_freevo(self, arg=None, menuw=None):
"""
Pops up a ConfirmBox.
"""
_debug_('confirm_freevo(arg=%r, menuw=%r)' % (arg, menuw), 2)
self.menuw = menuw
what = _('Do you really want to shut down Freevo?')
dialog = ButtonDialog(((_('Shutdown'), self.shutdown_freevo), (_('Cancel'), None, True)),
what, ButtonDialog.QUESTION_TYPE)
dialog.show()
def confirm_system(self, arg=None, menuw=None):
"""
Pops up a ConfirmBox.
"""
_debug_('confirm_system(arg=%r, menuw=%r)' % (arg, menuw), 2)
self.menuw = menuw
what = _('Do you really want to shut down the system?')
dialog = ButtonDialog(((_('Shutdown'), self.shutdown_system), (_('Cancel'), None, True)),
what, ButtonDialog.QUESTION_TYPE)
dialog.show()
def confirm_system_restart(self, arg=None, menuw=None):
"""
Pops up a ConfirmBox.
"""
_debug_('confirm_system_restart(arg=%r, menuw=%r)' % (arg, menuw), 2)
self.menuw = menuw
what = _('Do you really want to restart the system?')
dialog = ButtonDialog(((_('Restart'), self.shutdown_system_restart), (_('Cancel'), None, True)),
what, ButtonDialog.QUESTION_TYPE)
dialog.show()
def shutdown_freevo(self, arg=None, menuw=None):
"""
shutdown freevo, don't shutdown the system
"""
_debug_('shutdown_freevo(arg=%r, menuw=%r)' % (arg, menuw), 2)
shutdown(menuw=menuw, mode=ShutdownModes.FREEVO_SHUTDOWN)
def shutdown_system(self, arg=None, menuw=None):
"""
shutdown the complete system
"""
_debug_('shutdown_system(arg=%r, menuw=%r)' % (arg, menuw), 2)
shutdown(menuw=menuw, mode=ShutdownModes.SYSTEM_SHUTDOWN)
def shutdown_system_restart(self, arg=None, menuw=None):
"""
restart the complete system
"""
_debug_('shutdown_system_restart(arg=%r, menuw=%r)' % (arg, menuw), 2)
shutdown(menuw=menuw, mode=ShutdownModes.SYSTEM_RESTART)
class ShutdownDialog(WidgetDialog):
def __init__(self):
self.exit_model = ButtonModel(_('Exit Freevo'))
self.exit_model.signals['activated'].connect(self.button_activated)
self.exit_model.signals['pressed'].connect(self.button_pressed)
self.reboot_model = ButtonModel(_('Restart System'))
self.reboot_model.signals['activated'].connect(self.button_activated)
self.reboot_model.signals['pressed'].connect(self.button_pressed)
self.shutdown_model = ButtonModel(_('Shutdown System'))
self.shutdown_model.signals['activated'].connect(self.button_activated)
self.shutdown_model.signals['pressed'].connect(self.button_pressed)
self.cancel_model = ButtonModel(_('Cancel'))
self.cancel_model.signals['activated'].connect(self.button_activated)
self.cancel_model.signals['pressed'].connect(self.button_pressed)
buttons = { 'exit' : self.exit_model,
'reboot' : self.reboot_model,
'shutdown': self.shutdown_model,
'cancel' : self.cancel_model}
super(ShutdownDialog, self).__init__('shutdown', buttons, {})
if config.SYS_SHUTDOWN_ENABLE:
self.shutdown_model.set_active(True)
else:
self.exit_model.set_active(True)
def button_activated(self, button):
self.info['message'] = button.text
def button_pressed(self, button):
self.hide()
if self.exit_model == button:
shutdown(mode=ShutdownModes.FREEVO_SHUTDOWN)
elif self.reboot_model == button:
shutdown(mode=ShutdownModes.SYSTEM_RESTART)
elif self.shutdown_model == button:
shutdown(mode=ShutdownModes.SYSTEM_SHUTDOWN)
class PluginInterface(MainMenuPlugin):
"""
Plugin to shutdown Freevo from the main menu
"""
def items(self, parent):
_debug_('items(parent=%r)' % (parent,), 2)
return [ ShutdownItem(parent) ]
|