
v,Mc           @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k 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 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% l& Z& d  d k' l( Z( l) Z) d  d k* l+ Z+ d  d k, l- Z- l. Z. l/ Z/ d  d k0 l1 Z1 l2 Z2 d  d k0 l3 Z3 l4 Z4 l5 Z5 l6 Z6 d  d k7 l8 Z8 l9 Z9 d  Z: d Z; d Z< d Z= d e i> f d     YZ? d e# f d     YZ@ d e i> e iA f d     YZB eC d  ZD d    ZE d!   ZF d" e# f d#     YZG d$ e i> e iA f d%     YZH d& e! ZI e d' e
 iJ  ZK e iL d(  ZM d) e# f d*     YZN d+ e i> e iO f d,     YZP d S(-   iN(   t   modelst   IntegrityError(   t   cache(   t   settings(   t   ugettext_lazy(   t   FileSystemStorage(   t   ObjectDoesNotExist(   t   commit_on_success(   t
   iri_to_uri(   t   baset   statsdbt   pot   poheader(   t   md5_f(   t   match(   t   sver(   t   RelatedManager(   t   getfromcachet   deletefromcache(   t   group_by_countt
   max_column(   t   l(   t   TranslationStoreFieldt   MultiStringFieldt   PLURAL_PLACEHOLDER(   t   calculate_statst   empty_quickstats(   t   OBSOLETEt   UNTRANSLATEDt   FUZZYt
   TRANSLATED(   t   factory_classest   is_monolinguali    i   i   t   QualityCheckc           B   sq   e  Z d  Z e   Z e i d d d e  Z e i	 d d e Z
 e i   Z e i d e d e  Z d   Z RS(   s2   database cache of results of qualitychecks on unitt
   max_lengthi@   t   db_indexs   pootle_store.Unitt   defaultc         C   s   |  i  S(   N(   t   name(   t   self(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   __unicode__G   s    (   t   __name__t
   __module__t   __doc__R   t   objectsR    t	   CharFieldt   TrueR%   t
   ForeignKeyt   unitt	   TextFieldt   messaget   BooleanFieldt   Falset   false_positiveR'   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR!   ?   s   	t   SuggestionManagerc           B   s   e  Z d    Z RS(   c         C   s   |  i  d | d | d |  S(   Nt   target_hasht   unit__unitid_hasht   unit__store__pootle_path(   t   get(   R&   R6   t   unitid_hasht   pootle_path(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   get_by_natural_keyM   s    (   R(   R)   R<   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR5   L   s   t
   Suggestionc           B   s   e  Z d  Z e   Z d d d     YZ e   Z e i	 d d d e
  Z e i d  Z e i d d e
 Z d	   Z d d
 g e _ d   Z d   Z d   Z e e e  Z e d    Z RS(   s^   suggested translation for unit, provided by users or
    automatically generated after a merget   Metac           B   s   e  Z d Z RS(   R/   R6   (   s   units   target_hash(   R(   R)   t   unique_together(    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR>   U   s   R"   i    R#   s   pootle_store.Units   pootle_profile.PootleProfilet   nullc         C   s   |  i  |  i i |  i i i f S(   N(   R6   R/   R:   t   storeR;   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   natural_key]   s    s   pootle_store.Storec         C   s   t  |  i  S(   N(   t   unicodet   target(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR'   a   s    c         C   s   |  i  S(   N(   t   target_f(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   _get_targetd   s    c         C   s.   | |  _  t |  i  i d   i   |  _ d  S(   Ns   utf-8(   RE   R   t   encodet	   hexdigestR6   (   R&   t   value(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   _set_targetg   s    	c         C   s
   |  i  i S(    (   R/   t   _source(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   <lambda>l   s    (    (   R(   R)   R*   R5   R+   R>   R   RE   R    R,   R-   R6   R.   R/   t   userRB   t   dependenciesR'   RF   RJ   t   propertyt   _targetRK   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR=   Q   s   						c         C   s`   | d j o t t | i   } n | o/ | i |  i j o | i | _ |  i | _ n d S(   s   hackish workaround for monolingual files always having only source and no target.

    we compare monolingual unit with corresponding bilingual unit, if
    sources differ assume monolingual source is actually a translationN(   t   NoneR    t   typet   _storet   sourceRD   (   t   oldunitt   newunitt   monolingual(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   fix_monolingualp   s
    c         C   s.   d } x! |  D] } | t  i |  7} q W| S(   Ni    (   R
   t	   wordcount(   t   stringsRY   t   string(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   count_words|   s
     c         C   s,   y t  |  i  SWn t j
 o d SXd  S(   Ni   (   t   lenRZ   t   AttributeError(   R[   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   stringcount   s    t   UnitManagerc           B   s   e  Z d    Z RS(   c         C   s   |  i  d | d |  S(   NR:   t   store__pootle_path(   R9   (   R&   R:   R;   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR<      s    (   R(   R)   R<   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR`      s   t   Unitc        	   B   s  e  Z e   Z d  d9 d     YZ e i d d e Z e i	 d e  Z
 e i d e  Z e i d d d e d e  Z e d e  Z e i d d d e d e  Z e i d d	 d e  Z e i d e d d	 d e  Z e d e d
 e  Z e i d d	 d e  Z e i d e d d	 d e  Z e i d e d
 e  Z e i d e d
 e  Z e i d e d e  Z e i d e d e  Z e i	 d e d e d e  Z e i d e d e d e d e  Z  d   Z! d g e! _" d   Z# d   Z$ d   Z% d   Z& d   Z' e( e& e'  Z) d   Z* d   Z+ e( e* e+  Z, d   Z- d   Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 e e d  Z4 d   Z5 d: d  Z7 d: d d   Z8 d!   Z9 d"   Z: d#   Z; d$   Z< d%   Z= d&   Z> d'   Z? e d(  Z@ d)   ZA d*   ZB d+   ZC d,   ZD d-   ZE eF d.    ZG d: d/  ZH d0   ZI d1   ZJ d2   ZK e e e d3  ZL d4   ZM d: e d5  ZN d6   ZO d7   ZP d8   ZQ RS(;   R>   c           B   s   e  Z d  d g Z d Z RS(   RA   t   indexR:   (   s   stores   unitid_hash(   R(   R)   t   orderingR?   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR>      s   s   pootle_store.StoreR#   t   editableR"   i    R@   R$   i    t   blankt   auto_nowt   auto_now_addc         C   s   |  i  |  i i f S(   N(   R:   RA   R;   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRB      s    c         C   s   |  i  S(   N(   t   mtime(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt	   get_mtime   s    c         O   sJ   t  t |   i | |   d  |  _ t |  _ d  |  _ t |  _ d |  _	 d  S(   Ns   UTF-8(
   t   superRb   t   __init__RQ   t   _rich_sourceR3   t   _source_updatedt   _rich_targett   _target_updatedt	   _encoding(   R&   t   argst   kwargs(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRl      s    				c         O   s  |  i  oL t |  i i d   i   |  _ t |  i i  |  _ t	 |  i  |  _
 n |  i o t |  i i  |  _ t	 |  i  |  _ t d  |  i i  o! |  i t j o t |  _ q q |  i t j o t |  _ q n t t |   i | |   t i oh |  i i o[ |  i i t j oH |  i p
 |  i  o4 |  i |  i    |  i i   |  i i i    n |  i i t! j o" |  i  p
 |  i o |  i"   n t# |  _  t# |  _ |  i i t j o& |  i } t$ | d d d d g  n d  S(   Ns   utf-8t   getquickstatst   getcompletestatsRj   t   has_suggestions(%   Rn   R   t   source_fRG   RH   t   source_hashR\   RZ   t   source_wordcountR]   t   source_lengthRp   RE   t   target_wordcountt   target_lengtht   filterRQ   t   stateR   R   R   Rk   Rb   t   saveR   t   AUTOSYNCRA   t   filet   PARSEDt   synct   getorigt   update_store_headert	   savestoret   CHECKEDt   update_qualitychecksR3   R   (   R&   Rr   Rs   RA   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR      s4    
!
*'			c         C   s   |  i  S(   N(   Rw   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   _get_source   s    c         C   s   | |  _  t |  _ d  S(   N(   Rw   R-   Rn   (   R&   RI   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   _set_source   s    	c         C   s   |  i  S(   N(   RE   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRF      s    c         C   s   | |  _  t |  _ d  S(   N(   RE   R-   Rp   (   R&   RI   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRJ      s    	c         C   sG  | |  i   } |  i | _ | i |  i    |  i   } | o | i |  n |  i d d  } | o | i | d d n |  i d d  } | o | i | d d n | i |  i	    | i
 |  i    t | d  o@ x= |  i   i   D]% } | i | i d t | i  q Wn |  i   o | i   n | S(   s|   convert to a unit of type unitclass retaining as much
        information from the database as the target format can supportt   origint	   developert
   translatort   addalttrans(   RT   RD   t	   markfuzzyt   isfuzzyt   getlocationst   addlocationst   getnotest   addnotet   setidt   getidt
   setcontextt
   getcontextt   hasattrt   get_suggestionst   iteratorR   RC   RM   t
   isobsoletet   makeobsolete(   R&   t	   unitclassRV   t	   locationst   notest
   suggestion(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   convert   s*     'c         C   s2   y |  i  i   i SWn t j
 o t i SXd  S(   N(   RA   t   get_file_classt	   UnitClassR   R   t   pounit(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   get_unit_class  s    c         C   s   t  |  i  S(   N(   RC   RT   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR'     s    c         C   s   |  i    } t |  i |   S(   N(   R   t   strR   (   R&   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   __str__  s    c         C   s   |  i  i i  i |  i } |  i   | i   j o | St i d | i | | i  i  |  i  i i  i   |  i  i i  i |  i    } | S(   Nu)   incorrect unit index %d for %s in file %s(	   RA   R   t   unitsRc   R   t   loggingt   debugt   require_indext   findid(   R&   R/   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c   
      C   sY  t  } |  i   o! | i   o | i   t } n | i |  i j o | i   o |  i i i i	 } t
 |  i i  } |  i i } | | j  o | i d g | |  n | i i | j o | | _ t } q q |  i | _ t } n | i d d  |  i d d  j p d o/ | i |  i d d  d d d d t } n | i   |  i   j o | i |  i    t } n t | d  o |  i   i   o g  } | i   D] } | | i q~ } xW |  i   i   D]? }	 |	 i | j o qn | i |	 i t |	 i   t } qWn |  i   o" | i   o | i   t } n | S(   s+   sync in file unit with translations from dbu    R   R   t    t   positiont   replaceR   (   R3   R   t	   resurrectR-   RD   t	   haspluralRA   t   translation_projectt   languaget   npluralsR]   RZ   t   extendR   R   R   R   R   R   t   countt   getalttransR   R   RC   RM   R   (
   R&   R/   t   changedR   t   target_pluralsRZ   t   _[1]t   alttranst   alttranslistR   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR   '  sF    

	
,

#* 

c         C   s  t  } |  i | i j p; t |  i i  t | i  j p |  i   | i   j oR | i   o/ t | i i  d j o | i t g |  _ n | i |  _ t } n |  i | i j p" t |  i i  t | i  j oL t	 d	 |  i i  } | i |  _ t	 d	 |  i i  p | o
 t } q'n | i d d  } |  i | j o+ |  i p | o | p d	 |  _ t } n | i d d  } |  i | j o+ |  i p | o | p d	 |  _ t } n d i | i    } |  i | j o+ |  i p | o | p d	 |  _ t } n | i   } |  i | i   j o+ |  i p | o | p d	 |  _ t } n |  i   | i   j o |  i | i    t } n |  i   | i   j o/ | i   o |  i   n |  i   t } n |  i | i   j oP t | i    p t | i  |  _ t |  i i d   i   |  _ t } n t  | d  oN xK | i!   D]9 } | i |  i j o |  i" | i d t  n t } q_Wn | S(
   s!   update indb translation from filei   R   R   R   s   
s   utf-8R   t   touchN(#   R3   RT   R]   RZ   R_   R   R   R-   RD   R}   RQ   RE   R   t   developer_commentt   translator_commentt   joinR   R   R   t   contextR   R   R   R   R   t   unitidR   RC   R   RG   RH   R:   R   R   t   add_suggestion(   R&   R/   R   t   notemptyR   R   R   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   updateU  s^    5&
5!
!
!
'



%!
 c         C   s   g  } | pa |  i  i   } | o= t | i d t  i d d t  } | i d t  } n | i   n |  i p d Sxf |  i	 i
 i i |   i   D]F \ } } | d j p | | j o q n |  i  i d | d |  q Wd S(   s/   run quality checks and store result in databaseR4   R%   t   flatNR   R1   (   t   qualitycheck_sett   allt   setR}   R-   t   values_listR3   t   deleteRD   RA   R   t   checkert   run_filterst   itemst   create(   R&   t   createdt   keep_false_positivest   existingt   checksR%   R1   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    '
 c         C   s   |  i  i d t  S(   NR4   (   R   R}   R3   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   get_qualitychecks  s    c         C   s   | d  j oM d } |  i d  j	 o | |  i 7} n |  i d  j	 o | |  i 7} n | S| d j o |  i p d S| d j o |  i p d St d   d  S(   NR   R   t
   programmerR   s   source codes   Comment type not valid(   R   s	   developers   source code(   RQ   R   R   t
   ValueError(   R&   R   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    t   appendc         C   s@   | o
 | i    p d  S| d j o | |  _ n
 | |  _ d  S(   NR   R   s   source code(   s
   programmers	   developers   source code(   t   stripR   R   (   R&   t   textR   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s
    c         C   s   |  i  S(   N(   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s.   | |  _  t |  i  i d   i   |  _ d  S(   Ns   utf-8(   R   R   RG   RH   R:   (   R&   RI   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    	c         C   s.   |  i  d  j o g  St d  |  i  i d   S(   Ns   
(   R   RQ   R}   t   split(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s4   |  i  d  j o d |  _  n |  i  | d 7_  d  S(   NR   s   
(   R   RQ   (   R&   t   location(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   addlocation  s    c         C   s   |  i  S(   N(   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s   | |  _  d  S(   N(   R   (   R&   RI   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s   |  i  t j S(   N(   R~   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   sm   |  i  t j o d  S| o t |  _  nA |  i  t j o0 t d  |  i i  o t |  _  qi t |  _  n d  S(   N(	   R~   R   R   R}   RQ   RE   RZ   R   R   (   R&   RI   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   sF   |  i  d  j	 o6 t |  i  i  d j p t |  i  d  o
 |  i  i S(   Ni   t   plural(   RT   RQ   R]   RZ   R   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s   |  i  t j S(   N(   R~   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s!   |  i  t j o t |  _  n d  S(   N(   R~   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   sE   |  i  t j o d  St d  |  i i  o t |  _  n
 t |  _  d  S(   N(   R~   R   R}   RQ   RE   RZ   R   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s
    c         C   s?   |  i  o( |  i   o t t d  |  i i   S|  i t j S(   N(	   Rp   R   t   boolR}   RQ   RE   RZ   R~   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   istranslated  s    c         C   s   |    } | i  |  | S(   N(   R   (   t   clsR/   RV   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   buildfromunit  s    	c         C   s   |  i  | d | d  S(   NRM   (   R   (   R&   t   txtR   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s
   |  i    S(   N(   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s   | i    d  S(   N(   R   (   R&   t   alternative(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   delalttrans   s    c         C   sL   | i  |  i  } | o/ | d } |  i | d t } | o | Sn d  S(   Ni    t   authoritative(   t   matchesRT   t   mergeR-   (   R&   t   matchert
   candidatest
   match_unitR   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   fuzzy_translate  s    
c         C   s   t  } | o@ | i d d  } | o# |  i | j o | |  _ t } qM n t | i  p | St |  i  o | o | S|  i   o | i   o | S| i |  _ |  i | i j o |  i   n |  i | i	    t } | S(   NR   R   (
   R3   R   R   R-   R   RD   R   RT   R   R   (   R&   R/   t	   overwritet   commentsR   R   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s$    	c         C   s   |  i  i d  i   S(   NRM   (   t   suggestion_sett   select_relatedR   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR   +  s    c         C   sz   t  d  |  p d  S| |  i j o d  St d |  d |  } | | _ y# | i   | o |  i   n Wn d  SX| S(   NR/   RM   (   R}   RQ   RD   R=   R   (   R&   t   translationRM   R   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR   .  s    	
c         C   s   y |  i  i d |  } Wn t i j
 o t SX| i |  _ |  i   | i   t i	 oD |  i
 o: |  i |  i    |  i i d | i  |  i
 i   n t S(   Nt   idt   profile(   R   R9   R=   t   DoesNotExistR3   RD   R   R   R   R   R   R   R   RA   R   RM   R   R-   (   R&   t   suggidR   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   accept_suggestion@  s    

c         C   sK   y |  i  i d |  } Wn t i j
 o t SX| i   |  i   t S(   NR   (   R   R9   R=   R   R3   R   R   R-   (   R&   R   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   reject_suggestionP  s    

c         C   s?   |  i  i i   } | d j	 o | i |  i  } n g  } | S(   s   get terminology suggestionsN(   RA   R   t   gettermmatcherRQ   R   RT   (   R&   R   t   result(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   get_terminologyZ  s
    (    N(R   R(   R)   R`   R+   R>   R    R.   R-   RA   t   IntegerFieldRc   R0   R3   R   R,   R:   R   Rw   Rx   t   SmallIntegerFieldRy   Rz   RE   R{   R|   R   R   R   R   R   R~   t   DateTimeFieldRi   RB   RN   Rj   Rl   R   R   R   RO   RK   RF   RJ   RP   R   R   R'   R   R   R   R   R   R   RQ   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   classmethodR   R   R   R   R   R   R   R   R   R   R   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRb      s   	$				*									
	.	4																					
s	   Pootle %sR   s   suggested by (.*) \[[-0-9]+\]t   StoreManagerc           B   s   e  Z d    Z RS(   c         C   s   |  i  d |  S(   NR;   (   R9   (   R&   R;   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR<   o  s    (   R(   R)   R<   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR   n  s   t   Storec           B   s{  e  Z d  Z e   Z e Z d Z e Z	 d dA d     YZ
 e d d d d d e d	 e d
 e d e  Z e d d d d d d d e d e  Z e d d d d d d d e d e  Z e i d d d d	 e d e Z e i d d d d	 e d e Z e i d d d
 e d e d	 e d e d   Z e i d d d
 e d e  Z e i d
 e d e d e d	 e  Z d   Z d g e _ d   Z d   Z e  d    Z! d   Z" e# e"  Z$ d   Z% e# e%  Z& d   Z' d    Z( e e d!  Z) d"   Z* d#   Z+ d$   Z, e- dB d%   Z/ dB d&  Z0 e- e e e dB e d'   Z1 d(   Z2 e- d)    Z3 e e e e dB d*  Z4 d+   Z5 d,   Z6 d-   Z7 d.   Z8 e Z9 d/   Z: d0   Z; e# e: e;  Z< d1   Z= dB d2  Z> e d3  Z? e d4  Z@ d5   ZA dB d6  ZB d7   ZC e  d8    ZD e  d9    ZE e  d:    ZF d;   ZG e- d<    ZH dB d=  ZI d>   ZJ e- d?    ZK d@   ZL RS(C   sC   A model representing a translation store (i.e. a PO or XLIFF file).s   Model StoreR>   c           B   s   e  Z d  g Z d Z RS(   R;   t   parentR%   (   s   parents   name(   R(   R)   Rd   R?   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR>   y  s   	t	   upload_tot   fishR"   i   t   storageR#   R@   Re   t   ignores   .pendings   .tms   pootle_app.Directoryt   related_namet   child_storess,   pootle_translationproject.TranslationProjectt   storest   uniquet   verbose_namet   Pathi   R$   c         C   s
   |  i  f S(   N(   R;   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRB     s    c         O   s   |  i  i |  i |  _ t t |   i | |   t |  d  oT |  i   d } xA t |  i	  D], \ } } |  | _
 | | | _ | i   q_ Wn |  i t j o t |  d d d d g  n d  S(   Nt   _unitsi   Rt   Ru   Rj   Rv   (   R  R;   R%   Rk   R   R   R   t	   max_indext	   enumerateR  RA   Rc   R~   R   R   (   R&   Rr   Rs   Rc   t   iR/   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s     	c         O   s6   t  t |   i | |   t |  d d d d g  d  S(   NRt   Ru   Rj   Rv   (   Rk   R   R   R   (   R&   Rr   Rs   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   s   t  |  i i   d d   S(   NRi   (   R   t   unit_setR   RQ   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRj     s    c         C   s   |  i  o |  i  i Sd  S(   N(   R   t   path(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   _get_abs_real_path  s    
c         C   s
   |  i  i S(   N(   R   R%   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   _get_real_path  s    c         C   s   t  |  i d  S(   Ns   /translate/(   R   R;   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   get_absolute_url  s    c         C   s   |  i  t j  oo |  i i   d j oY |  i oA t t |  i i   o( |  i i	 o |  i i
 d |  i  q |  i   n d S(   s.   make sure file is parsed and units are createdi    R;   N(   R~   R   R  R   R   R    RR   RA   R   t   is_template_projectt   update_from_templatesR;   t   parse(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   require_units  s
    &#c         C   sg   | p t  |  d  oK |  i i   } | p | i d t  } n t | i d d   |  _ n d S(   s=   build a quick mapping index between unit ids and database idst
   dbid_indext	   state__gtR   R   N(   R   R  R   R}   R   t   dictR   R  (   R&   R   t   obsoleteR   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   require_dbid_index  s
    c         c   si   d } x\ t  d t |  |  D]B } |  i i d | | | | ! } x | i   D] } | VqR Wq Wd  S(   Ni   i    t   id__in(   t   xrangeR]   R  R}   R   (   R&   t   idst   chunksR  R   R/   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   findid_bulk  s       c         C   s;   t  i |  d d d t } | i |  i i d t   | S(   s@   builds a TM matcher from current translations and obsolete unitst   max_candidatesi   t   usefuzzyR~   (   R   R   R-   t   extendtmR  R}   R   (   R&   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   get_matcher  s    c         C   s   |  i  t j o d  St |  i i   d d   } | d  j o d  S| i   | } | i p | i d j oJ t	 i
 d |  i  t i i d |   i   o t |  _  n
 t |  _  t St S(   NRi   i   i<   sS   found stale lock in %s, something went wrong with a previous operation on the storet   unit__storeix   i   (   R~   t   LOCKEDR   R  R   RQ   t   nowt   dayst   secondsR   t   warningR;   R!   R+   R}   t   existsR   R   R-   R3   (   R&   Ri   t   delta(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   clean_stale_lock  s    	c      
   C   s  |  i    |  i t j o t i d |  i  d  S| d  j o |  i i } n t	 d |  i  } |  i t
 j  ot i d |  i  |  i } t |  _ |  i   yz xs t | i  D]b \ } } | i   oI y |  i | |  Wqt j
 o" } t i d | i   |  qXq q WWn0 |  i i   i   | |  _ |  i     n Xt
 |  _ |  i   t i | |  i   t i  d  Sd  S(   Nu"   attemped to update %s while lockeds   %s:syncu
   Parsing %su0   Data integrity error while importing unit %s:
%s(   R/  R~   R(  R   t   infoR;   RQ   R   RA   R   R   R   R   R  R   t   istranslatablet   addunitR   R,  R   R  R   R   R   R   Rj   R   t   OBJECT_CACHE_TIMEOUT(   R&   RA   t   keyt   oldstateRc   R/   t   e(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR    s:    
		
 *	
	
c         C   s4   t  } |  i | d t } | o | i   n | S(   s   
        removes an obsolete unit. from both database and filesystem store
        this will usually be used after fuzzy matching
        R  (   R3   t   findunitR-   R   (   R&   RT   RA   R   t   obsolete_unit(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   _remove_obsolete  s
    c            sF  |  i    |  i t j o t i d |  i  d S|  i t j  o( t i d |  i  |  i d    d S  d j o |  i
 i   n t d |  i  } t i d |  i  |  i } t |  _ |  i   z,| o |  i   } n t t     }	 |  i d t d t  t |  i i    }
 t   i    } | oFg  } |
 | D] } | |  i i |  qH~ } xQ |  i |  D]@ } | i   p | i   qz| p | i   | i   qzqzW  f d	   | |
 D } x | D] } |  i | | i  } | oU t d | i i   o> | i! |  } | o$ | i   |  i" | i# d   qVn | t$ j o | i% d
 t  qqWn | ong  } |
 | @D] } | |  i i |  q~ } x:|  i |  D]%}   i& | i'    } |	 o" |  i( i) o t* | | |	  n | i+ |  } | o) | i | i j o | i | _ t } n | oQ t d | i i   o: | i! |  } | o  t } |  i" | i# d   qn | oC | i, p | i- } | i   | o | t$ j o | i%   qqqWn Wd | |  _ |  i   | o/ | o( | o  t. i | |  i/   t0 i1  n Xd S(   s   update db with units from fileu#   attempted to update %s while lockedNu$   attempted to update unparsed file %sRA   s   %s:syncu   Updating %sR   R  c         3   s"   x |  ] }   i  |  Vq Wd  S(   N(   R   (   t   .0t   uid(   RA   (    s1   /var/www/Pootle/local_apps/pootle_store/models.pys	   <genexpr>L  s   	 R   (2   R/  R~   R(  R   R0  R;   R   R   R  RQ   R   RA   R   R   R&  R    RR   R  R-   R   R  t   keyst   getidsR9   R"  R   R   R   R2  Rc   R}   RD   RZ   R   R9  RT   R   R   R   R   R   R  RX   R   Rn   Rp   R   Rj   R   R3  (   R&   t   update_structuret   update_translationt   conservativeRA   t   fuzzyR4  R5  R   RW   t   old_idst   new_idsR   R;  t   obsolete_dbidsR/   t	   new_unitsRV   R   t   _[2]t   shared_dbidsR   t	   do_checks(    (   RA   s1   /var/www/Pootle/local_apps/pootle_store/models.pyR      s    
		
1 
 
1 

	
c         C   s2   |  i  t j  o |  i   t |  d g  n d S(   s    make sure quality checks are runRu   N(   R~   R   R   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   require_qualitycheckst  s    
c         C   sb   t  i d |  i  x! |  i i   D] } | i   q# W|  i t j  o t |  _ |  i   n d  S(   Nu   Updating quality checks for %s(	   R   R   R;   R   R   R   R~   R   R   (   R&   R/   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR   {  s     	c            s  t  d   i  } t i |  } | o | o |   i   j o d S  i p | o t i d   i    i   } t	 i
 i   i i   i  }	   i |  }
 |
 i |	  |	   _   i     i d |    i i   t i |   i   t i  n d S| o   i i o d St i d   i    i d t  t   i i i    } t   i i    } t } | o   f d   | | D } xQ | D]I } | i   p ~ n* | p" | i    | i!   p ~ qn t } qWg  } | | D] } |   i i |  q~ } xL   i" |  D]7 } | i   i i i#  }   i i i$ |  t } q,Wn t% t&   i i   } | o g  } | | @D] } |   i i |  q~ } x   i" |  D]n } | o | i   o qn   i i i' | i(    } | d j	 o$ | i* |  } | o
 t } q9qqWn | o!   i d |    i i   n t i |   i   t i  d S(   s#   sync file with translations from dbs   %s:syncNu   Creating file %sR   u
   Syncing %sR   c         3   s(   x! |  ] }   i  i i |  Vq Wd  S(   N(   R   RA   R   (   R:  R;  (   R&   (    s1   /var/www/Pootle/local_apps/pootle_store/models.pys	   <genexpr>  s   	 (+   R   R;   R   R9   Rj   R   R   R   R   t   osR  R   R   t   abs_real_pathR%   R   t   savefileR   R   R   R   R   R3  R  R  R-   RA   R=  R  R<  R3   R   R   R   R"  R   R2  R    RR   R   R   RQ   R   (   R&   R>  R?  R@  R   R   R4  t	   last_synct
   storeclasst
   store_pathRA   RB  RC  t   file_changedt   obsolete_unitsR/   R   R;  t	   new_dbidsRV   RW   RF  RG  R   R   (    (   R&   s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     sr    !
	
  

1 1 c         C   s`   y |  i  i i   SWnA t j
 o5 |  i o$ t i i |  i  \ } } t | Sn Xt d S(   NR   (	   R   t   projectR   R   R%   RJ  R  t   splitextR   (   R&   R%   t   ext(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    
c         C   s   t  i d |  i |  |   } y | i |  i i i  Wn t j
 o n Xx0 |  i i	   D] } | i
 | i | i   q_ W| S(   s   export to fileclassu   Converting %s to %s(   R   R   R;   t   settargetlanguageR   R   t   codeR   R   R   R2  R   R   (   R&   t	   fileclasst   outputR/   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    	 c         C   s   t  |  i  S(   N(   RC   R;   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR'     s    c         C   s%   |  i    } |  i |  } t |  S(   N(   R   R   R   (   R&   RN  RA   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    c         C   sG   t  |  d  o |  i S|  i   |  i i d t  i d  i d  S(   NR  R  Rc   t   store__translation_project(   R   R  R  R  R}   R   t   order_byR   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt
   _get_units  s    
c         C   s   d S(   sF   null setter to avoid tracebacks if TranslationStore.__init__ is calledN(    (   R&   RI   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt
   _set_units  s    c         C   s   t  |  i i   d d  S(   s   Largest unit indexRc   i(   R   R  R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR    s    c         C   s   | d  j o |  i   d } n t d |  d |  } | i |  |  i o | i   nG t |  d  p& d t f d     Y} |   |  _ n |  i i	 |  | S(   Ni   RA   Rc   R  t   FakeQuerySetc           B   s   e  Z d    Z RS(   c         S   s
   |  i    S(   N(   t   __iter__(   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s    (   R(   R)   R   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR^  
  s   (
   RQ   R  Rb   R   R   R   R   t   listR  R   (   R&   R/   Rc   RV   R^  (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR2    s    
c         C   s   | o' t  |  d  o t t |   i |  St | i d   i   } |  i i d |  } | o | i d t	  } n | i d t	  } | i
   o | Sd  S(   Nt   sourceindexs   utf-8Rx   R~   R  (   R   Rk   R   t	   findunitsR   RG   RH   R  R}   R   R   (   R&   RT   R  Rx   R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRb    s    c         C   s&   |  i  | |  } | o	 | d Sd  S(   Ni    (   Rb  (   R&   RT   R  R   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR7    s    c         C   st   t  |  d  o |  i i | d   St | i d   i   } y |  i i d |  SWn t i	 j
 o d  SXd  S(   Nt   id_indexs   utf-8R:   (
   R   Rc  R9   RQ   R   RG   RH   R   Rb   R   (   R&   R   R:   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR   $  s    c         C   st   t  |  d  o |  i   n t  |  d  o |  i i   St  |  d  o |  i i   S|  i i d d t Sd  S(   NR  Rc  R  R   R   (	   R   t	   makeindexRc  R<  R  t   valuesR   R   R-   (   R&   t   filename(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR=  .  s    c         C   s/   |  i  o! t |  i  d  o |  i  i   Sd  S(   Nt   header(   R   R   Rg  (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRg  8  s    c         C   s   y t  |  i  SWn t j
 o t i d |  i  n_ t i j
 o } t i d |  i |  n2 t t	 f j
 o } t i d |  i |  n Xh  } | i
 t  | d c d 7<| S(   s    calculate translation statisticsu   Duplicate IDs in %su   Failed to parse %s
%su   Can't access %s
%st   errorsi   (   R   R   R   R   R0  RK  R	   t
   ParseErrort   IOErrort   OSErrorR   R   (   R&   R6  t   stats(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRt   ?  s    c         C   s8   |  i    t i i d |  d t d t  } t | d  S(   s   report result of quality checksR'  t   unit__state__gtR4   R%   (   RI  R!   R+   R}   R   R3   R   (   R&   t   queryset(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRu   O  s    
!c         C   s   t  i i d |  d t  i   S(   s*   check if any unit in store has suggestionsR'  Rm  (   R=   R+   R}   R   R   (   R&   (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyRv   V  s    c         C   s   |  i  | S(   s/   Returns a single unit based on the item number.(   R   (   R&   t   item(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   getitem]  s    c            s    i  p d St t     } |  i   |  i t j o t i d |  i  d S|  i	   t i
 d |  i  |  i } t |  _ |  i   z|  i d t d t  t |  i i    }	 t |  i i i     i  o t   i    }
 n t   i |  i   }
 | p |  i i of | o_   f d   |
 |	 D } xB | D]6 } |  i |  } | t j o | i d t  qDqDWn | o~ g  } |	 |
 D] } | |  i i |  q~ } xJ |  i |  D]5 } | i   o | i   | i   q| i    qWn g  } |	 |
 @D] } | |  i i |  q~ } x |  i |  D] }   i! | i"    } | o" |  i i o t# | | |  n | p | i   o/ | o( | i   o | i$ | i% |  q(qH| i& |  } | oC | i' p | i( } | i   | o | t j o | i   q(qHqHW| p | o, |  i) d t d	 t d
 t* d t* d |  n Wd | |  _ |  i   Xd S(   sY   make sure each msgid is unique ; merge comments etc from
        duplicates into originalNu!   attemped to merge %s while lockedu
   merging %sR   R  c         3   s"   x |  ] }   i  |  Vq Wd  S(   N(   R   (   R:  R;  (   t   newfile(    s1   /var/www/Pootle/local_apps/pootle_store/models.pys	   <genexpr>  s   	 R   R>  R?  R@  R   R   (+   R   R    RR   R/  R~   R(  R   R0  R;   R  R   R   R  R-   R   R  R<  t
   issubclassR   RS  R   t	   __class__R=  R%   R  R2  R   R   R9   R"  R   R   R   R   R   RX   R   RD   R   Rn   Rp   R   R3   (   R&   Rq  R   t   allownewstringst   suggestionst   notranslatet   obsoletemissingRW   R5  RB  RC  RE  R/   RV   R   R;  RD  RF  RG  RU   R   RH  (    (   Rq  s1   /var/www/Pootle/local_apps/pootle_store/models.pyt	   mergefilea  sh    


		
 1 
1 
0	c   	      C   s-  |  i  i } |  i  i i } |  i i i | i  |  i i i | i  t	 |  i i t
 i
  o|  i   } | d  j o t i i   } n | d  j o yE |  i  i i d |  i   } | i i i d j o | i } n WqYt j
 oh yK |  i  i i   } | i i i d j o | i } n t | i |  } WqUt j
 o qUXqYXn | i d  t
 i   } h | d 6t d 6} | oA | i i   o1 d | i i p
 | i i | i i f | d <n d | d <|  i i i d	 t |  | i  o* | i! o  |  i i i" | i  | i!  q)n d  S(
   Nt   creation_timet   nobodys   %Y-%m-%d %H:%Mt   PO_Revision_Datet   X_Generators   %s <%s>t   Last_Translators   Anonymous Pootle Usert   add(#   R   R   RS  t   source_languageR   RA   RV  RW  t   setsourcelanguaget
   isinstanceR   Rj   RQ   t   datetimeR)  t   submission_setR}   t   latestt	   submitterRM   t   usernameR   t   minRy  t   strftimet   tzstringt   x_generatort   is_authenticatedt
   first_namet   emailt   updateheaderR-   R   t   pluralequationt   updateheaderplural(	   R&   R   R   R  Ri   t   submitt
   lastsubmitt   po_revision_datet   headerupdates(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR     s<    

1
c         C   s   |  i  o5 t i i |  i  i  o d Sd |  _  |  i   n t i i |  i i	 i
 t i  d  d d g  } t i i t i |  } t i i |  o | |  _  |  i   n d S(   s.   initialize pending translations file if neededNiR   t   pending(   R  RJ  R  R-  RQ   R   t   extsepR   R   R%   R   R   t   PODIRECTORY(   R&   t   pending_namet   pending_path(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   init_pending  s    
	2	c         C   s;  |  i    |  i p d Sx g  } |  i i i D]+ } | i   o | i   o | | q0 q0 ~ D] } | i   p | i   o qb n |  i | i  } | oB |  i |  } | i	 | i
 | d t |  i i i i |  qb qb Wt |  i i i  d j o |  i i   n! |  i i   d |  _ |  i   d S(   s<   import suggestions from legacy .pending files, into databaseNR   i   (   R  R  RA   R   R1  R   R7  RT   t   getsuggester_from_pendingR   RD   R3   t   removeR]   R   R   RQ   R   (   R&   R   t   suggR/   t	   suggester(    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   import_pending  s"    

I 	c         C   sp   t  i | i  } | oS | i d  } d d k l } y | i i d |  SWql | i j
 o ql Xn d S(   sN   returns who suggested the given item's suggitem if
        recorded, else Nonei   i(   t   PootleProfilet   user__usernameN(
   t   suggester_regexpt   searcht   msgidcommentt   groupt   pootle_profile.modelsR  R+   R9   R   RQ   (   R&   R/   t   suggestedbyR  R  (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR    s    	(    N(M   R(   R)   R*   R   R+   Rb   R   t   NameR3   t   is_dirR>   R   t   fsR-   R   R  t   tmR    R.   R  R   R,   t   _R;   R%   R   t   NEWR~   RB   RN   R   R   R   Rj   R  RO   RK  R  t	   real_pathR  R  R  R"  R&  R/  R   RQ   R  R9  R   RI  R   R   R   R   R'   R   t   suggestions_in_formatR\  R]  R   R  R2  Rb  R7  R   R=  Rg  Rt   Ru   Rv   Rp  Rx  R   R  R  R  (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyR   r  sz   	-''!!0$											'S	
F									

		I(	(Q   RJ  R   t   reR  t	   django.dbR    R   t   django.core.cacheR   t   django.confR   t   django.utils.translationR   R  t   django.core.files.storageR   t   django.core.exceptionsR   t   django.db.transactionR   t   django.utils.encodingR   t   translate.storageR	   R
   R   R   t   translate.misc.hashR   t   translate.searchR   t   pootle.__version__R   t   pootle_versiont   pootle_app.lib.utilR   t   pootle_misc.utilR   R   t   pootle_misc.aggregateR   R   t   pootle_misc.baseurlR   t   pootle_store.fieldsR   R   R   t   pootle_store.utilR   R   R   R   R   R   t   pootle_store.filetypesR   R    R(  R  R   R   t   ModelR!   R5   t   TranslationUnitR=   RQ   RX   R\   R_   R`   Rb   R  R  R  t   compileR  R   t   TranslationStoreR   (    (    (    s1   /var/www/Pootle/local_apps/pootle_store/models.pyt   <module>   sR   ""		 
