Author: duncan
Date: Fri Sep 29 12:59:41 2006
New Revision: 8267
Modified:
branches/rel-1-5/freevo/freevo_config.py
branches/rel-1-5/freevo/local_conf.py.example
branches/rel-1-5/freevo/src/plugins/shutdown.py
Log:
[ 1567504 ] nvram-wakeup patch
Patch applied.
Modified: branches/rel-1-5/freevo/freevo_config.py
==============================================================================
--- branches/rel-1-5/freevo/freevo_config.py (original)
+++ branches/rel-1-5/freevo/freevo_config.py Fri Sep 29 12:59:41 2006
@@ -303,6 +303,24 @@
ENABLE_SHUTDOWN_SYS = 0 # Performs a whole system shutdown at SHUTDOWN!
# For standalone boxes.
+# Warn before shutting down the system if the next recording is
+# scheduled for starting in less than this number of seconds:
+WARN_SHUTDOWN = 15 * 60
+
+# On Freevo shutdown, use nvram-wakeup to program the computer to
+# wakeup / boot up right before the next recording:
+USE_NVRAM_WAKEUP = 0
+
+# See SHUTDOWN_SYS_CMD for sudo comment.
+# If you change this, note that an exitcode of 1 means "reboot needed"
+# and should get through to Freevo
+NVRAM_WAKEUP_CMD = 'nvram-wakeup -s %d'
+
+# If using nvram-wakeup, time in seconds to startup before recording:
+BOOTTIME_PADDING = 150
+
+# Location of the reboot-flag used if nvram-wakeup returns 1:
+NVRAM_REBOOT_FLAG = '%s/reboot_flag' % FREEVO_CACHEDIR
#
# You can add more keybindings by adding them to the correct hash.
Modified: branches/rel-1-5/freevo/local_conf.py.example
==============================================================================
--- branches/rel-1-5/freevo/local_conf.py.example (original)
+++ branches/rel-1-5/freevo/local_conf.py.example Fri Sep 29 12:59:41 2006
@@ -810,12 +810,25 @@
# TV_RECORD_SERVER_IP = 'localhost'
# TV_RECORD_SERVER_PORT = 18001
-# start every recording X minutes before scheduled,
+# Start every recording X minutes before scheduled,
# and stop X minutes after scheduled - default to zero minutes.
# This must be a value in seconds although at the moment only has
# the percision of one minute.
# TV_RECORD_PADDING = 0 * 60
+# Warn before shutting down the system if the next recording is
+# scheduled for starting in less than this number of seconds:
+# WARN_SHUTDOWN = 15 * 60 # quarter hour
+# (This has no extra effect if CONFIRM_SHUTDOWN is set, since then
+# the shutdown is already confirmed.)
+
+# On Freevo shutdown, use nvram-wakeup to program the computer to
+# wakeup / boot up right before the next recording:
+# USE_NVRAM_WAKEUP = 1
+
+# If using nvram-wakeup, time in seconds to startup before recording:
+# BOOTTIME_PADDING = 2 * 60
+
# VCR_AUDIO = (':adevice=%s' % AUDIO_DEVICE +
# ':audiorate=32000' + # 44100 for better sound
# ':forceaudio:forcechan=1:' + # Forced mono for bug in my driver
Modified: branches/rel-1-5/freevo/src/plugins/shutdown.py
==============================================================================
--- branches/rel-1-5/freevo/src/plugins/shutdown.py (original)
+++ branches/rel-1-5/freevo/src/plugins/shutdown.py Fri Sep 29 12:59:41 2006
@@ -50,6 +50,9 @@
from item import Item
from plugin import MainMenuPlugin
+if config.WARN_SHUTDOWN or config.USE_NVRAM_WAKEUP:
+ import tv.record_client as record_client
+
def shutdown(menuw=None, argshutdown=None, argrestart=None, exit=False):
"""
@@ -126,7 +129,6 @@
time.sleep(1)
-
class ShutdownItem(Item):
"""
Item for shutdown
@@ -146,7 +148,7 @@
(self.confirm_system_restart, _('Restart system') ) ]
else:
items = [ (self.shutdown_freevo, _('Shutdown Freevo') ),
- (self.shutdown_system, _('Shutdown system') ),
+ (self.check_shutdown_system, _('Shutdown system') ),
(self.shutdown_system_restart, _('Restart system') )
]
if config.ENABLE_SHUTDOWN_SYS:
items = [ items[1], items[0], items[2] ]
@@ -154,12 +156,46 @@
return items
+ def next_scheduled_recording(self):
+ """
+ return starting time of next scheduled recording (or None)
+ """
+ (server_available, msg) = record_client.connectionTest()
+ if not server_available:
+ return None
+ (result, recordings) = record_client.getScheduledRecordings()
+ if result:
+ progs = recordings.getProgramList().values()
+ if len(progs):
+ progs.sort(lambda a, b: cmp(a.start, b.start))
+ return progs[0].start
+ return None
+
+
+ def next_recording_message(self, format, start_time = None):
+ if start_time == None:
+ start_time = self.next_scheduled_recording()
+ if start_time == None:
+ return ""
+ rec_distance = start_time - time.time() - config.TV_RECORD_PADDING
+ if rec_distance < 0:
+ result = _('A recording is in progress.')
+ elif rec_distance < 60*60:
+ result = _('The next scheduled recording begins in %d minutes.') %
int(rec_distance/60)
+ elif rec_distance < 60*60*10:
+ result = _('The next scheduled recording begins at %s.') %
time.strftime(config.TV_TIMEFORMAT, time.localtime(start_time))
+ else:
+ result = _('The next recording is scheduled for %s.') %
time.strftime(config.TV_DATETIMEFORMAT, time.localtime(start_time))
+ return format % result
+
+
def confirm_freevo(self, arg=None, menuw=None):
"""
Pops up a ConfirmBox.
"""
self.menuw = menuw
- what = _('Do you really want to shut down Freevo?')
+ what = _('Do you really want to shut down Freevo?') \
+ + self.next_recording_message(" %s")
ConfirmBox(text=what, handler=self.shutdown_freevo,
default_choice=1).show()
@@ -168,39 +204,95 @@
Pops up a ConfirmBox.
"""
self.menuw = menuw
- what = _('Do you really want to shut down the system?')
+ what = _('Do you really want to shut down the system?') \
+ + self.next_recording_message(" %s")
ConfirmBox(text=what, handler=self.shutdown_system,
default_choice=1).show()
+
def confirm_system_restart(self, arg=None, menuw=None):
"""
Pops up a ConfirmBox.
"""
self.menuw = menuw
- what = _('Do you really want to restart the system?')
+ what = _('Do you really want to restart the system?') \
+ + self.next_recording_message(" %s")
ConfirmBox(text=what, handler=self.shutdown_system_restart,
default_choice=1).show()
+ def check_shutdown_system(self, arg=None, menuw=None):
+ """
+ Shutdown the complete system if the next recording is not too far away
+ """
+ if config.WARN_SHUTDOWN:
+ start_time = self.next_scheduled_recording()
+ if start_time != None:
+ if start_time - config.TV_RECORD_PADDING - time.time() \
+ < config.WARN_SHUTDOWN:
+ what = self.next_recording_message("%s ", start_time) + \
+ _('Do you really want to shut down the system?')
+ ConfirmBox(text=what, handler=self.shutdown_system,
default_choice=1).show()
+ return
+ self.shutdown_system(arg, menuw)
+
+
def shutdown_freevo(self, arg=None, menuw=None):
"""
- shutdown freevo, don't shutdown the system
+ Shutdown freevo, don't shutdown the system
"""
shutdown(menuw=menuw, argshutdown=False, argrestart=False)
def shutdown_system(self, arg=None, menuw=None):
"""
- shutdown the complete system
+ Shutdown the complete system, use nvram-wakeup to schedule
+ boot-up before next recording (if configured to do so).
+ nvram-wakup may signal that an additional reboot is needed
+ (with exitcode 1), in this case a flag file is created and the
+ system is rebooted.
+ """
+ doShutdown = True
+ if config.USE_NVRAM_WAKEUP:
+ start_time = self.next_scheduled_recording()
+ if start_time != None:
+ wakeupTime = start_time \
+ - config.TV_RECORD_PADDING \
+ - config.BOOTTIME_PADDING
+ _debug_("calling nvram-wakeup with %d" % wakeupTime)
+ ec = os.system(config.NVRAM_WAKEUP_CMD % (wakeupTime,))
+ _debug_(".. exitcode was %d" % ec)
+ if ec == 256:
+ doShutdown = False
+ file(config.NVRAM_REBOOT_FLAG, "w").close()
+ elif ec > 0:
+ ConfirmBox(text=_('Could not program computer to boot up
before next recording. Shutdown anyway?'),
+ handler=self.shutdown_system_anyway,
default_choice=1).show()
+ return
+ shutdown(menuw=menuw, argshutdown=doShutdown, argrestart=not
doShutdown)
+
+
+ def shutdown_system_anyway(self, arg=None, menuw=None):
+ """
+ Shutdown freevo, don't shutdown the system
"""
shutdown(menuw=menuw, argshutdown=True, argrestart=False)
+
def shutdown_system_restart(self, arg=None, menuw=None):
"""
- restart the complete system
+ Restart the complete system
"""
shutdown(menuw=menuw, argshutdown=False, argrestart=True)
+# According to
+# http://mail.python.org/pipermail/python-list/2004-September/241553.html
+# a) Python has no uptime() implementation and
+# b) calling "uptime" is not more portable than parsing /proc/uptime.
+# Since the latter is much easier, I will do so.. ;-)
+def uptime():
+ uptime, idletime = [float(f) for f in file("/proc/uptime").read().split()]
+ return uptime
#
@@ -212,7 +304,8 @@
Plugin to shutdown Freevo from the main menu
"""
+ def __init__(self, *args):
+ MainMenuPlugin.__init__(self, *args)
+
def items(self, parent):
return [ ShutdownItem(parent) ]
-
-
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog