a
    	`i                     @   sR   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ G dd dZ	dS )    N)Alfit)Fitlic                   @   s8   e Zd Zdd Zdd ZdddZdd	d
Zdd ZdS )Dofrec                 C   sN   || _ t| j | _d| _| jd | _d | _d | _i | _d| _d| _	| 
  d S )Nz.dofre.json.gzr   )er   alfit	ext_no_gzext	last_fufiZlast_sigfZ
count_keyscount_timesimport_from_fitli)selferimp r   !/home/ernad/ernad/python/dofre.py__init__   s    zDofre.__init__c                 C   sN   t | jd| _| jj| _| jj| _| jj| _| jj| _| jj| _| jj| _dS )z,fitli has common routines of dofre and ranfidofreN)	r   r   fitlifufigetZ	list_sigsZsigs_availablesigis_up_to_date)r   r   r   r   r      s    




zDofre.import_from_fitliFNc                 C   s  | j }|du r"|  r"td dS | j j}| jjdd}d}d| _d| _d| _|D ]:}td|  | j	||d |d	7 }|durR||krR qqRt
| j}t
| j}	| j}
| d
| d
|	 |
 }|jd d | }t|d}|d d}| jD ]R}t|}tt| j| j|  }|d	7 }|| jk r|d| d| d q|d| d| d  |  d| }tj|dd |d }td|  t|d dS )z#-> makes update for all alfit filesNzThe dofre is up to date.Frandom)orderr   zdofre loads )
do_verbose   _r   /w{
z: ,z
}z/bin/gzip -f T)shellr   zdofre wrote z.dofre.json.gz)r   r   printmax_issuedater   Z	out_fufis
count_docs
count_fitsr   update_for_fufitinnusmaker   dirsopenwriter   jsondumpsstrmathlogclose
subprocessrunfilerclear_by_extension)r   r   	max_filesr   	issuedateZalfit_fufisZcount_files
alfit_fufir'   r   r	   finaout_fufiZout_fileZ	count_fitfitZfit_keyvalueZcommandr   r   r   update&   sJ    




zDofre.updatec                 C   s&   t || _| jD ]}| | qd S )N)r6   loadd
feed_papid)r   r:   r   papidr   r   r   r(   N   s    
zDofre.update_for_fufic                 C   sj   | j }|  jd7  _|| D ]H}|| jvrDd| j|< |  jd7  _n| j|  d7  < |  jd7  _qd S )Nr   )rA   r&   r   r'   r   )r   rC   rA   r=   r   r   r   rB   T   s    

zDofre.feed_papid)FN)F)__name__
__module____qualname__r   r   r?   r(   rB   r   r   r   r   r      s
   

(
r   )
r.   r1   r4   r6   r)   r   r   r   r   r   r   r   r   r   <module>   s   