³ò
+e|Mc           @   sá   d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z d d „ Z d e	 f d „  ƒ  YZ
 e i i d ƒ oD y d d	 k l Z Wn e j
 o qË Xd
 e
 f d „  ƒ  YZ n e
 i Z e
 i Z d S(   sÊ  
A file monitor and server restarter.

Use this like:

..code-block:: Python

    import reloader
    reloader.install()

Then make sure your server is installed with a shell script like::

    err=3
    while test "$err" -eq 3 ; do
        python server.py
        err="$?"
    done

or is run from this .bat file (if you use Windows)::

    @echo off
    :repeat
        python server.py
    if %errorlevel% == 3 goto repeat

or run a monitoring process in Python (``paster serve --reload`` does
this).  

Use the ``watch_file(filename)`` function to cause a reload/restart for
other other non-Python files (e.g., configuration files).  If you have
a dynamic set of files that grows over time you can use something like::

    def watch_config_files():
        return CONFIG_FILE_CACHE.keys()
    paste.reloader.add_file_callback(watch_config_files)

Then every time the reloader polls files it will call
``watch_config_files`` and check all the filenames it returns.
iÿÿÿÿN(   t   classinstancemethodi   c         C   s?   t  d |  ƒ } t i d | i ƒ } | i t ƒ | i ƒ  d S(   s,  
    Install the reloading monitor.

    On some platforms server threads may not terminate when the main
    thread does, causing ports to remain open/locked.  The
    ``raise_keyboard_interrupt`` option creates a unignorable signal
    which causes the whole application to shut-down (rudely).
    t   poll_intervalt   targetN(   t   Monitort	   threadingt   Threadt   periodic_reloadt	   setDaemont   Truet   start(   R   t   mont   t(    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyt   install2   s    	R   c           B   s_   e  Z g  Z g  Z g  Z d  „  Z d „  Z d „  Z d „  Z e	 e ƒ Z d „  Z
 e	 e
 ƒ Z
 RS(   c         C   sS   h  |  _  t |  _ | |  _ t |  i ƒ |  _ |  i i |  ƒ t |  i	 ƒ |  _
 d  S(   N(   t   module_mtimesR   t   keep_runningR   t   listt   global_extra_filest   extra_filest	   instancest   appendt   global_file_callbackst   file_callbacks(   t   selfR   (    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyt   __init__F   s    			c         C   sB   x; t  o3 |  i ƒ  p t i d ƒ Pn t i |  i ƒ q Wd  S(   Ni   (   R   t   check_reloadt   ost   _exitt   timet   sleepR   (   R   (    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyR   N   s     c         C   s  t  |  i ƒ } xJ |  i D]? } y | i | ƒ  ƒ Wq t i d | IJt i ƒ  q Xq Wxc t i i	 ƒ  D]R } y | i
 } Wn t t f j
 o } ql n X| d  j	 o | i | ƒ ql ql WxG| D]?} y- t i | ƒ } | o | i } n d } Wn t t f j
 o
 qÉ n X| i d ƒ o: t i i | d  ƒ o# t t i | d  ƒ i | ƒ } nS | i d ƒ oB t i i | d  d ƒ o' t t i | d  d ƒ i | ƒ } n |  i i | ƒ p | |  i | <qÉ |  i | | j  o t i d | IJt SqÉ qÉ Wt S(	   Ns)   Error calling paste.reloader callback %r:i    s   .pyciÿÿÿÿs	   $py.classi÷ÿÿÿs   .pys   %s changed; reloading...(   R   R   R   t   extendt   syst   stderrt	   tracebackt	   print_exct   modulest   valuest   __file__t   AttributeErrort   ImportErrort   NoneR   R   t   statt   st_mtimet   OSErrort   IOErrort   endswitht   patht   existst   maxR   t   has_keyt   FalseR   (   R   t	   filenamest   file_callbackt   modulet   filenamet   excR(   t   mtime(    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyR   Z   sJ    
   
'#'
c         C   sh   t  i i | ƒ } |  d j o5 x | i D] } | i | ƒ q) W| i i | ƒ n |  i i | ƒ d S(   s    Watch the named file for changesN(	   R   R-   t   abspathR'   R   t
   watch_fileR   R   R   (   R   t   clsR5   t   instance(    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyR9      s    
 c         C   sV   |  d j o5 x | i D] } | i | ƒ q W| i i | ƒ n |  i i | ƒ d S(   s{   Add a callback -- a function that takes no parameters -- that will
        return a list of filenames to watch for changes.N(   R'   R   t   add_file_callbackR   R   R   (   R   R:   t   callbackR;   (    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyR<   ‹   s    
 (   t   __name__t
   __module__R   R   R   R   R   R   R9   R    R<   (    (    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyR   @   s   			%	
	
t   java(   t   SystemRestartt   JythonMonitorc           B   s   e  Z d  Z d „  Z RS(   s  
            Monitor that utilizes Jython's special
            ``_systemrestart.SystemRestart`` exception.

            When raised from the main thread it causes Jython to reload
            the interpreter in the existing Java process (avoiding
            startup time).

            Note that this functionality of Jython is experimental and
            may change in the future.
            c         C   s=   x6 t  o. |  i ƒ  p t ƒ  ‚ n t i |  i ƒ q Wd  S(   N(   R   R   RA   R   R   R   (   R   (    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyR   «   s
     (   R>   R?   t   __doc__R   (    (    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pyRB      s   (   RC   R   R   R   R   R    t   paste.util.classinstanceR    R   t   objectR   t   platformt
   startswitht   _systemrestartRA   R&   RB   R9   R<   (    (    (    s]   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/reloader.pys   <module>)   s    W	