
    Zf2                         d dl Z d dlZd dlZd dlmZ d dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlmZ  G d d          ZdS )    N)Dexis)Recon)Rixerc                   L    e Zd ZddZd Z	 	 ddZddZd ZddZdd	Z	d
 Z
dS )AsembFc                 d   || _         || _        t          | j                   | _        |j        d         |j        d         d| _        d|j        d         i| _        d|j        d         i| _        t          | j                   | _        t          | j                   | _
        i | _        d | _        d S )Namfernad)aer   r   )r   
do_verboser   dexisnsnsanser   rixerr   recondocachecol_ele)selferimpr   s      !/home/ernad/ernad/python/asemb.py__init__zAsemb.__init__   s    $46]]
)+ +%)'*+46]]
46]]
t    c                 Z    | j         }|j        |         j        d         }|dz   |z   dz   }|S )z---> called by class to see if out_fufi existsmocla/.amf.xml.gz)r   reportdirs)r   repcode	issuedater   	mocla_dirout_fufis         r   fufiz
Asemb.fufi"   s5    FHW%*73	s?Y.>r   Nc                    | j         }i | _        i | _        || j         j        }|t	          d           dS ||                     |          | _        n|                     |          | _        |t          j        |          }||j	        }|t	          d           dS |j
        |         j        d         }|+t          |d          r|j        |j        }nb|dz   |z   dz   }nV|j
        |         j        d         }|d|z   dz   z  }t          j                            |          st	          d|            dS |dz   |z   d	z   }t          j        |           |t%          d
          t          j        ||g          st	          d|z              |S t	          d| d|            | j                            ||          }	|	t	          dt,          j                   |>|dz   |z   dz   }t          j                            |          st	          d|z              dS || _        |                     |           | j                            |d          }
| j                            |
          }
| j                            |
          }
t?          | j                  }|}d}|
                     d| j         j!        j"                  }t?          |          dk    ri|d         j#        }|}|$                    d          rtK          |dd                   }	 tK          |          }n3# tL          $ r |j'        d         }Y nw xY wd|j'        v r|j'        d         }|Q|$                    d          r-tK          |dd                   dz  }tQ          ||z            }ntQ          |          }| j                            |d          }
| j                            |
          }
| j                            |
          }
| j         j)        *                    |
          | _+        tY          j-        tY          j.        |j/        d         d                    }||_#        tY          j-        tY          j.        |j/        d         d                    }| j0        |_#        tY          j-        tY          j.        |j/        d         d                    }| j1        |_#        tY          j-        tY          j.        |j/        d         d                    }te          |          |_#        | j+        3                    |           | j+        3                    |           | j+        3                    |           | j+        3                    |           | 4                    |           |
5                    |dd !           t	          d"|z              |S )#z*build the amf file, use doc_fufi for brownNzasemb needs a repcode.zasemb needs an issuedate.r   
given_fufir   z.sidezasemb needs r   zasemb needs a side fufizasemb does not renew asemb: dexis.set_issuedate(, doc_fufi=doc_fufi%asemb can not continue without dexis.filezasemb can't start without 	add_statez//e:truncate
namespacesr   %truncated   r
   r"   entropyaverent
issue_size   Tcompressionpretty_printasemb wrote )6r   papnuspapwesgiven_repcodeprintlast_sigsigfilerget_issuedategiven_issuedater   r    hasattrr'   ospathisfileprepare	Exceptiondonerer   set_issuedatesysstderr	side_fufiparse_side_fufir   amf_docr   flattenremove_historylenxpathabovonsmaptextendswithfloat
ValueErrorconfintxget_colr   etElementQNamer   r7   r8   strappendcompose_docswrite)r   r!   r"   r+   parentr   r#   rR   r$   outrepdocr9   max_docsr5   	truncatesnumber_truncateissuedate_eleentropy_eleaverent_eleissue_size_eles                       r   buildzAsemb.build)   s    F?f*G.///t>}}W--DHH}}V,,DH+H55I)I 1222tHW%*73	>q,'' BAL,DL		%Oi7'A		(-g6Iy722I7>>),, 0Y00111ts?Y.>h5666|Hyk22 	)H4555OLILL(LLMMMj&&y8&DD;9
KKKK!C)3g=I7>>),, 2Y>???t"Y'''##Gt#<<##F++**622%%
LL,0FL,> ! @ @	y>>A })H&O  %% 8"'2"7"7."'"8"8 . . .6*-. 16!!vj)H  %% ) !B$0036x*455x== ##Gt#<<##F++**622vx''//
28ADM;#G#GHH&j!$w-!C!CDD<j!$w-!C!CDD<BHQT']L$I$IJJ!*ooM***N+++K(((K((((###XADAAAnx'(((s   L, ,MMc                    | j         }i | _        i | _        d| _        ||j        }|t          d           d S ||j        }|t          d           d S t          d| d|            | j                            ||          }|t          dt          j
                   |j                            |j        d	                   }||vrt          d
           d S ||         }t          j        |          }|                    d| j         j        j                  }	d}
|	D ]}|
dz  }
d| j        |<   |j        |         j        d         }|dz   |z   dz   }| j                            |d           }| j                            |          }| j                            |          }| j                            |d           }| j                            |          }| j                            |          }| j         j                            |          | _        t9          j        t9          j        |j        d         d                    }||_         t9          j        t9          j        |j        d         d                    }| j        !                    |           | j        !                    |           | "                    |
           |#                    |dd           t          d|z              |S )N z0asemb: build_unsorted can't do without a repcodez3asemb: build_unsorted can't do without an issuedater(   r)   r*   r,   r-   issuesz4asemb: build_unsorted can't do without an issue fufiz//a:text[@ref]/@refr1   r   r:   r   r   r   r/   r
   r"   r9   Tr;   r>   )$r   r@   r?   rD   rA   rB   rG   r   rO   rP   rQ   ddates_uniquer    rE   	parse_laxrX   rY   rZ   r   r   rT   r   rU   rV   ra   rb   r   rc   rd   re   r   r[   rg   rh   ri   )r   r!   r"   r+   r   rk   issue_fufis
issue_fufidocpapidsrm   papidr#   r$   rl   rp   rs   s                    r   build_unsortedzAsemb.build_unsorted   s   F?oGHIII4)I KLLL4LILL(LLMMMj&&y8&DD;9
KKKKc&&qvh'788K''HIII4 +
oj))0&*fl&8  : : 	# 	#EMH!"DKHW%*73	s?Y.>##Gt#<<##F++**622##Gt#<<##F++**622vx''//
28ADM;#G#GHH&BHQT']L$I$IJJM***N+++(###XADAAAnx'(((r   c           	         | j         }d}| j        }| j        D ]g}t          j        d|          }|                     |          }|| j        v r| j        |         }n|}t          j        t          j        |j        d         d          t          |          t          j        |                    }	|                    |	           |                    |           t          j        t          j        |j        d         d          t          | j        |                   | j        t          j        |                    }
|                    |
           | j                            |           |d	z  }||k    r d S id S )
Nr   haspart)rZ   r
   sausage)decimshonuitem)weight	criterionpoletr:   )r   r   r@   rc   rd   compose_docr?   re   r   rf   shonusmakerg   rD   letnusr   )r   rm   r   
count_docsr   r   haspart_eletext_elenumbersausage_eleitem_eles              r   rh   zAsemb.compose_docs   sz   h
F[ 	 	E*Yc:::K''..H##U+#*RXad7mY%G%G+.v;;+1;v+>+>@ @ @K OOK(((x(((z"(14=&"A"A),T[-?)@)@,0H(.J(?(?A A AH
 x(((L,,,!OJX%% &r   c                     || j         v r| j         |         S |rt          d|z   dz   dd           | j                            |                                          }|rt          dd           t          j        |          }|| j         |<   |S )Nzfetch z ... rv   T)endflushdone)r   )r   rB   r   fetchdecoderc   
fromstring)r   r   r   rk   r}   s        r   r   zAsemb.compose_doc   s    DL  <&& 	B(U"W,"DAAAAju%%,,.. 	&&%%%%mC  !U
r   c                    |i | _         i | _        |}|| _        | j        }t          |d          }i }d}d}|                                D ]}|dd         }|                    d          }t          |          dk     rt          d|z   dz              K|d         }	|	d	k    rd}	n|	                    d
          s|	                    d          rj|	j	        d
         }
|
d         }		 t          |	          }	n?# t          $ r2 t          |	          }t          d| t          j                   d}	Y nw xY w|	dz  }		 t          |	          }	n?# t          $ r2 t          |	          }t          d| t          j                   d}	Y nw xY w|	||d         <   |	dk    r||	t          j        |	d          z  z  }|dz  }|| j         |d         <   t          t#          |d                    | _        t          t#          d|z  |z  d                    }t          |          | _        t)          ||j        d          }|D ]}||         | j        |<   | j        S )z%stores in self.weight and self.numberNrr   r3   	   zbad parts with line ''rv   r   ze-zasemb can't parse weight r-   r6   r:   T)keyreverse)r?   r@   rR   open	readlinessplitrW   rB   r\   	partitionr]   r^   rf   rP   rQ   mathlogroundr7   r8   sortedget)r   r%   rR   	side_filepapwer   r7   linepartsr   weightsprint_weightr8   sorted_papidsr   s                  r   rS   zAsemb.parse_side_fufi   s    DKDKI!DNN	C((	
'')) $	/ $	/D":DJJt$$E5zzA~~-4s:;;;1XF|| %% &)>)> & *3/ "6]]FF!   #&v;;LDlDD"z+ + + + FFF  #v   "6{{@,@@:' ' ' '  %E%(Ozz6DHVQ$7$777!OJ$.DKa!!5!,,--eC'MJ6::;;7||u%)TBBB" 	. 	.E!&uDK{s$   'C779D32D3<E9FFc                 0   | j         }|j        |         j        d         }|j                            |d          }|dS || _        |j                            |d          }t          j                            |          	                    dd          }|S )zget model for a reportr   z*.model)searchNFz.modelrv   )
r   r   r    rx   last_by_mtime
model_fufirI   rJ   basenamereplace)r   r!   r   r#   
last_modellast_model_fufirD   s          r   rC   zAsemb.last_sig;  s    FHW%*73	S&&y&CC
5$#++Ii+HHg//77"EE
r   )F)NNNN)N)__name__
__module____qualname__r   r%   rt   r   rh   r   rS   rC    r   r   r   r      s               <@m m m m^3 3 3 3j  B   : : : :~
 
 
 
 
r   r   )r   rI   rP   
lxml.etreeetreerc   rE   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s     				 



                           u u u u u u u u u ur   