Ñò
a¤Mc           @   sn  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 l Z l Z 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  d k l Z l Z l Z l Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* d „  Z+ d S(   iÿÿÿÿN(   t   call_command(   t   ugettext(   t	   ungettext(   t	   Directory(   t   Storet   QualityCheckt   CHECKEDt   PARSED(   t   OBSOLETE(   t   deletefromcache(   t   Language(   t   Project(   t   TranslationProject(   t   stats_startt   stats_languaget   stats_projectt	   stats_endc          C   sÏ   xÈ t  i i d t ƒ i ƒ  D]« }  t i i d |  ƒ } | i d t ƒ i ƒ  } | oA t i	 d |  i
 ƒ x[ |  i i ƒ  D] } | i d t ƒ qy Wq t i	 d |  i
 ƒ | i ƒ  t |  _ |  i ƒ  q Wd S(   s€   reverts stores to unchecked state. if store has false positives
    marked updates quality checks keeping false postivies intactt   statet   unit__storet   false_positives/   %s has false positives, updating quality checkst   keep_false_positivess*   %s has no false positives, deleting checksN(   R   t   objectst   filterR   t   iteratorR   t   Truet   countt   loggingt   debugt   pootle_patht   unitst   update_qualitycheckst   deleteR   R   t   save(   t   storet   store_checkst   false_positivest   unit(    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   flush_quality_checks&   s      
	c         C   s+   d h t  d ƒ d 6t  d |  ƒ d 6} | S(   Ns  
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>%(title)s</title>
    <meta content="text/html; charset=utf-8" http-equiv="content-type" />
    <style type="text/css">
    body
    {
        background-color: #ffffff;
        color: #000000;
        font-family: Georgia, serif;
        margin: 40px auto;
        width: 740px;
    }
    h1
    {
        font-size: 185%%;
    }
    ul
    {
        list-style-type: square;
    }
    .error
    {
        background-color: inherit;
        color: #d54e21;
        font-weight: bold;
    }
    </style>
    </head>
    <body>
    <h1>%(title)s</h1>
    <p class="error">%(msg)s</p>
    s   Pootle: Updatet   titlesW   Database tables are currently at build version %d. Pootle will now update the database.t   msg(   t   _(   t   db_buildversiont   text(    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   header6   s    $c          C   s1   d t  d ƒ }  t i d ƒ t d d t ƒ|  S(   Nu   
    <p>%s</p>
    s#   Creating missing database tables...s    Creating missing database tablest   syncdbt   interactive(   R(   R   t   infoR    t   False(   R*   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyR,   ^   s    c          C   s®   d t  d ƒ }  t i d ƒ d d k l } d d k l } | i i d d d	 d
 ƒ \ } } x6 | i i	 d d ƒ i
 ƒ  D] } | | _ | i ƒ  qz Wd | _ | i ƒ  |  S(   Ns   
    <p>%s</p>
    s   Fixing permission table...s   Fixing permission tableiÿÿÿÿ(   t
   Permission(   t   ContentTypet	   app_labelt
   pootle_appt   modelt	   directoryt   content_type__namet   pootle(   R(   R   R.   t   django.contrib.auth.modelsR0   t"   django.contrib.contenttypes.modelsR1   R   t   get_or_createR   R   t   content_typeR    t   name(   R*   R0   R1   t   contenttypet   createdt
   permission(    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   update_permissions_20030f   s    ! 		
c       
   C   sÏ  d t  d ƒ }  t i d ƒ d d k l } t i i } t i i d ƒ } | i	 | | i
 | ƒ | i | | i
 f ƒ t i i d ƒ } t | _ | i	 | | i
 | ƒ | i | | i
 d f ƒ t i i } t i i d	 ƒ } t | _ | i	 | | i
 | ƒ t i i d
 ƒ } y t i i d d ƒ } Wnb t i j
 oS t d d d d d d d d ƒ } t i i i | i ƒ | _ | i d t ƒ n X| i | _ | i	 | | i
 | ƒ | i | | i
 d f ƒ |  S(   Nu   
    <p>%s</p>
    s$   Updating existing database tables...s!   Updating existing database tablesiÿÿÿÿ(   t   dbR   t   translation_projectt   _idR5   t   source_languaget   codet   ent   fullnamet   Englisht   npluralsi   t   pluralequations   (n != 1)t   raw(   R(   R   R.   t   south.dbRA   R   t   _metat   db_tablet	   get_fieldt
   add_columnR<   t   create_indexR   t   nullR   R
   R   t   gett   DoesNotExistR   t   roott   get_or_make_subdirRE   R5   t	   save_baset   idt   default(   R*   RA   t
   table_namet   fieldRF   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   update_tables_21000u   s4    		!c          C   s(   d t  d ƒ }  t i d ƒ t ƒ  |  S(   Ns   
    <p>%s</p>
    s:   Removing quality checks, will be recalculated on demand...s   Fixing quality checks(   R(   R   R.   R%   (   R*   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   update_qualitychecks_21040˜   s    c          C   sf   d t  d ƒ }  t i d ƒ xB t i i d t ƒ i ƒ  i ƒ  D] } t	 | d d d d g ƒ q? W|  S(	   Ns   
    <p>%s</p>
    sD   Removing potentially incorrect cached stats, will be recalculated...s   flushing cached statst   stores__unit__statet   getquickstatst   getcompletestatst	   get_mtimet   has_suggestions(
   R(   R   R.   R   R   R   R   t   distinctR   R	   (   R*   t   tp(    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   update_stats_21060    s    " c          C   s   d t  d ƒ }  t i d ƒ x[ t i i d t d d d d ƒ i ƒ  D]2 } | i d	 t	 ƒ | i
 d
 t	 d	 t	 d t ƒ qE W|  S(   Ns   
    <p>%s</p>
    s   Reparsing Qt ts files...s   reparsing qt tst	   state__gtt+   translation_project__project__localfiletypet   tst   file__iendswiths   .tst   update_translationt   update_structuret   conservative(   R(   R   R.   R   R   R   R   R   t   syncR   t   updateR/   (   R*   R!   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   update_ts_tt_12008©   s      c          C   s   d t  d ƒ }  |  S(   Nu   
    <p>%s</p>
    <ul>
    sY   Pootle will now import all the translations into the database. It could take a long time.(   R(   (   R*   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   parse_startµ   s    c         C   sŒ   yh t  i d |  i ƒ |  i ƒ  |  i ƒ  } | o. d t d d | h | d 6|  i d 6ƒ } n d } Wn d t d	 |  i ƒ } n X| S(
   Nu$   Importing suggestions for %s if any.u%   
            <li>%s</li>
            s,   Imported %(count)d suggestion from %(store)ss-   Imported %(count)d suggestions from %(store)sR   R!   t    u+   
        <li class="error">%s</li>
        s$   Failed to import suggestions from %s(   R   R.   t	   real_patht   import_pendingRb   R   R   R(   (   R!   R   R*   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   import_suggestions¼   s    
	"
c         C   s   y[ t  i d |  i ƒ |  i ƒ  |  i ƒ  d } d t d d | h | d 6|  i d 6ƒ } Wn d t d	 |  i ƒ } n X| S(
   Nu   Importing units from %st   totalu   
        <li>%s</li>
        s&   Imported %(count)d unit from %(store)ss'   Imported %(count)d units from %(store)sR   R!   u+   
        <li class="error">%s</li>
        s   Failed to import units from %s(   R   R.   Rr   t   require_unitsR_   R   R   R(   (   R!   R   R*   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   parse_storeÏ   s    
	"c          C   s   d t  d ƒ }  |  S(   Nu   
    </ul>
    <p>%s</p>
    s"   All translations are now imported.(   R(   (   R*   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt	   parse_endß   s    c          C   s   d h t  d ƒ d 6}  |  S(   Nsu   
    <p>%(endmsg)s</p>
    <div><script>setTimeout("location.reload()", 10000)</script></div>
    </body></html>
    sX   Pootle initialized the database. You will be redirected to the front page in 10 seconds.t   endmsg(   R(   (   R*   (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   footeræ   s    c         c   sÔ  t  i } t  i t  _ t |  ƒ V|  d j  o t ƒ  Vn |  d j  o y t ƒ  VWn% t j
 o } t i d | ƒ n Xt i	 d ƒ t
 i i i d ƒ xP t i i ƒ  D]? } y | i ƒ  Wqª t j
 o } t i d | | ƒ qª Xqª Wt i	 d ƒ xi t i i ƒ  D]T } y  | i i ƒ  | _ | i ƒ  Wq
t j
 o } t i d | i | ƒ q
Xq
Wn y t ƒ  VWn% t j
 o } t i d | ƒ n X|  d j  os t ƒ  Vx\ t i i ƒ  D]K } y t | ƒ Vt | ƒ VWq¿t j
 o } t i d	 | | ƒ q¿Xq¿Wt ƒ  Vn |  d
 j  o t ƒ  Vn |  d j  o t ƒ  Vn | d j  o t ƒ  Vn t ƒ  Vx" t i i ƒ  D] } t  | ƒ Vq}Wx" t i i ƒ  D] } t! | ƒ Vq¢Wt" ƒ  Vt# ƒ  V| t  _ d S(   sF   Update pootle database, while displaying progress report for each stepi>N  iR  u3   something broke while upgrading database tables:
%ss   creating project directoriest   projectsu&   something broke while upgrading %s:
%ss,   associating stores with translation projectsu6   something broke while creating new database tables:
%su$   something broke while parsing %s:
%si0R  iDR  iè.  N($   t   syst   stdoutt   stderrR+   R@   R\   t	   ExceptionR   t   warningR.   R   R   RU   RV   R   R   R    R   t   parentt   get_translationprojectRB   R   R,   Rp   Rw   Rt   Rx   R]   Re   Ro   R   R
   R   R   R   Rz   (   R)   t   tt_buildversionR}   t   et   projectR!   t   language(    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   staggered_updateî   sr    	  #   	(,   R|   R   t   django.core.managementR    t   pootle.i18n.gettextR   R(   R   t   pootle_app.modelsR   t   pootle_store.modelsR   R   R   R   t   pootle_store.utilR   t   pootle_misc.utilR	   t   pootle_language.modelsR
   t   pootle_project.modelsR   t    pootle_translationproject.modelsR   t   pootle_misc.dbinitR   R   R   R   R%   R+   R,   R@   R\   R]   Re   Ro   Rp   Rt   Rw   Rx   Rz   R‡   (    (    (    s2   /var/www/Pootle/local_apps/pootle_misc/dbupdate.pyt   <module>   s4   ""		(			#									