From fd95c19665dac97efb68ed5834dd41bc5bdc1c67 Mon Sep 17 00:00:00 2001 From: Eric von Bayer Date: Mon, 5 Oct 2009 18:19:11 -0700 Subject: [PATCH] Generalized staged callbacks (will be used for togo changes) --- beacon.py | 4 ++++ httpserver.py | 0 metadata.py | 0 pyTivo.conf.dist | 0 stager.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+) mode change 100755 => 100644 httpserver.py mode change 100755 => 100644 metadata.py mode change 100755 => 100644 pyTivo.conf.dist create mode 100644 stager.py diff --git a/beacon.py b/beacon.py index bc40961..e42b101 100644 --- a/beacon.py +++ b/beacon.py @@ -2,6 +2,7 @@ import logging import re import struct import time +import stager from socket import * from threading import Timer from urllib import quote @@ -66,6 +67,9 @@ class ZCBroadcast: address = inet_ntoa(info.getAddress()) config.tivos[tsn] = address config.tivo_names[tsn] = name.replace('.' + VIDS, '') + + # Execute anything waiting on the scan + stager.Execute( "post_scan" ) def shutdown(self): self.logger.info('Unregistering: %s' % ' '.join(self.share_names)) diff --git a/httpserver.py b/httpserver.py old mode 100755 new mode 100644 diff --git a/metadata.py b/metadata.py old mode 100755 new mode 100644 diff --git a/pyTivo.conf.dist b/pyTivo.conf.dist old mode 100755 new mode 100644 diff --git a/stager.py b/stager.py new file mode 100644 index 0000000..0a5376b --- /dev/null +++ b/stager.py @@ -0,0 +1,71 @@ +# Module: stager.py +# Author: Eric von Bayer +# Contact: +# Date: August 18, 2009 +# Description: +# Module to handle deferred callbacks in stages. +# +# Copyright (c) 2009, Eric von Bayer +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * The names of the contributors may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Class to hold a stage +class Stage(object): + """An individual stage to be executed at a later time""" + + # Initialize the stage + def __init__(self): + self.__callbacks = list() + self.__done = False + + # Execute all the callbacks in the stage + def Execute(self): + if self.__done == False: + self.__done = True + for call in self.__callbacks: + call() + del self.__callbacks + + # Add a callback to the stage + def AddCallback(self, call): + if self.__done == True: + call() + else: + self.__callbacks.append( call ) + +# Internal storage for the stages +stager_stages = dict() + +# Execute the named stage +def Execute(name): + if name in stager_stages: + stager_stages[name].Execute() + +# Add a callback to the named stage +def AddCallback(name, call): + if not name in stager_stages: + stager_stages[name] = Stage() + + stager_stages[name].AddCallback( call ) -- 2.11.4.GIT