o
    Xc                     @   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_fufilast_sigf
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get	list_sigs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rF||krF nq)t
| j}t
| j}	| j}
| d
| d
|	 |
 }|jd d | }t|d}|d d}| jD ])}t|}tt| j| j|  }|d	7 }|| jk r|d| d| d qz|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   	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   	issuedatealfit_fufiscount_files
alfit_fufir,   r   r	   finaout_fufiout_file	count_fitfitfit_keyvaluecommandr   r   r   update&   sN   




zDofre.updatec                 C   s&   t || _| jD ]}| | q	d S )N)r;   loadd
feed_papid)r   rA   r   papidr   r   r   r-   P   s   
zDofre.update_for_fufic                 C   sf   |  j d7  _ | j| D ]$}|| jvr d| j|< |  jd7  _n	| j|  d7  < |  jd7  _qd S )Nr    )r+   rL   r   r,   r   )r   rN   rF   r   r   r   rM   V   s   

zDofre.feed_papid)FN)F)__name__
__module____qualname__r   r   rJ   r-   rM   r   r   r   r   r      s    


*r   )
r3   r6   r9   r;   r.   r   r   r   r   r   r   r   r   r   <module>   s    