Ñò
m`¤Mc           @   sª   d  d k  Z  d  d k Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k l	 Z
 d  d k l	 Z d Z d Z d	 Z d
 Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   HttpResponse(   t
   siteconfig(   t   dbinit(   t   dbupdate(   t   buildie  if  i N  iå.  t   SiteConfigMiddlewarec           B   s    e  Z d  Z d „  Z d „  Z RS(   s¸  
    This middleware does two things, it reload djblet siteconfigs on
    every request to ensure they're uptodate. but also works as an
    early detection system for database errors.

    It might seem strange that the middleware does these two unrelated
    tasks, but since the only way to test the database is to run a
    query, it would be too wasteful to add another query per request
    when siteconfig already requires one.

    c         C   sH  yù t  ƒ  } t | _ t i ƒ  } t | i d t ƒ ƒ } | t j  o | | _	 t
 i | _ n t
 i | _	 t | i d t ƒ ƒ } | t j  o> t i d ƒ t i ƒ  | i d t ƒ | i ƒ  | | _ n | i	 | i f t
 i t
 i f j o | SWnH t j
 o< } | i i d j o  t  ƒ  } t | _ | | _ | Sn Xd S(	   sI   load site config, return a dummy response if database seems uninitializedt   BUILDVERSIONt   TT_BUILDVERSIONs6   New Translate Toolkit version, flushing quality checkst   OperationalErrort   ProgrammingErrort   DatabaseErrorN(   s   OperationalErrors   ProgrammingErrors   DatabaseError(   R    t   UPDATE_STATUS_CODEt   status_codeR   t   load_site_configt   intt   gett   DEFAULT_BUILDVERSIONt   code_buildversiont   db_buildversiont   syst   maxintt   tt_buildversiont   DEFAULT_TT_BUILDVERSIONt   code_tt_buildversiont   loggingt   infoR   t   flush_quality_checkst   sett   savet	   Exceptiont	   __class__t   __name__t   INSTALL_STATUS_CODEt	   exception(   t   selft   requestt   responset   configR   t   db_tt_buildversiont   e(    (    s?   /var/www/Pootle/local_apps/pootle_misc/middleware/siteconfig.pyt   process_request=   s0    			

%				c         C   s\   | i  t j o t t i | i ƒ ƒ S| i  t j o t t i | i	 | i
 ƒ ƒ S| Sd S(   s›    this should be the last response processor to run, detect
        dummy response with INSTALL_STATUS_CODE status code and start
        db install processN(   R   R    R    R   t   staggered_installR!   R   R   t   staggered_updateR   R   (   R"   R#   R$   (    (    s?   /var/www/Pootle/local_apps/pootle_misc/middleware/siteconfig.pyt   process_responsek   s
    (   R   t
   __module__t   __doc__R(   R+   (    (    (    s?   /var/www/Pootle/local_apps/pootle_misc/middleware/siteconfig.pyR   1   s   	.(   R   R   t   django.httpR    t   pootle_miscR   R   R   t   pootle.__version__R   R   t   translate.__version__R   R    R   R   R   t   objectR   (    (    (    s?   /var/www/Pootle/local_apps/pootle_misc/middleware/siteconfig.pyt   <module>   s   