Changeset 230 for indytube/trunk

Show
Ignore:
Timestamp:
10/14/07 09:39:11 (15 months ago)
Author:
andy
Message:

install a siganl handler on USR2, so that indytube will re-read its configuration file

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • indytube/trunk/indytube.py

    r229 r230  
    88import traceback 
    99import sys 
     10import signal 
    1011 
    1112#3rd party libraries 
     
    2021   checked = 0 
    2122   converted = 0 
     23   conf_file = "" 
    2224 
    2325   def __init__(self): 
    2426        """constructor for IndyTubeTranscoder""" 
     27 
     28   def rereadConfig(self,signal,frame): 
     29        self.parse_config(self.conf_file) 
    2530 
    2631   def parse_config(self,conf_file): 
     
    2833        config = ConfigParser.RawConfigParser() 
    2934        config.read(conf_file) 
     35        self.conf_file = conf_file 
     36 
    3037 
    3138        self.MENCODER_LOCATION=config.get('mencoder','MENCODER_LOCATION') 
     
    5865        self.LOG_LEVEL=eval(config.get('logging','LOG_LEVEL')) 
    5966 
     67        self.ENCODER_LOCKFILE = "" 
     68 
    6069        logging.basicConfig(level=self.LOG_LEVEL, format='%(asctime)s %(levelname)s %(message)s', filename=self.LOG_FILE, filemode='a')  
    6170 
    62         self.ENCODER_LOCKFILE = "" 
     71        logging.info("finished parse_config function at %s, using file %s " % (time.strftime("%D %H:%M:%S"), self.conf_file)) 
    6372 
    6473   def check_lock_file(self): 
     
    101110 
    102111def attempt_transcode_file(self, f): 
    103         '''Start the transcoding attempt with file 'f'. Converts to FLV format, possibly OGG/Theora in future. Produces HTML snippets for including 
     112        '''Start the transcoding attempt with file 'f'. Converts to FLV format, and OGG/Theora. Produces HTML snippets for including 
    104113           the players appropriate for the produced video format. At the moment, this is FlowPlayer for FLV, and Cortado java applet for OGG/Theora ''' 
    105114        #whether or not the transcoding worked for the given file 'f' 
     
    212221        # passing along the indytube object as an argument. (try not to _call_ this function or else you'll end up in infinite recursion!) 
    213222        reactor.callLater(indytuber.POLLTIME,looperInvoker,indytuber) 
    214  
     223   
    215224    #make an IndyTubeTranscoder object 
    216225    indytuber = IndyTubeTranscoder() 
    217226    #parse our config 
    218227    indytuber.parse_config('indytube.conf') 
     228 
    219229    #we have started! 
    220230    logging.info("started main function at %s, calling loop every %s seconds " % (time.strftime("%D %H:%M:%S"), indytuber.POLLTIME)) 
    221231    #start it for real, once off 
    222232    looperInvoker(indytuber) 
     233 
     234    #install a signal handler to re-read configuration files. 
     235    signal.signal(signal.SIGUSR2, indytuber.rereadConfig) 
     236 
    223237    #start the twisted reactor 
    224238    # see http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#Igetexceptions.ValueError:signalonlyworksinmainthreadwhenItrytorunmyTwistedprogramWhatswrong