U
    zk^                     @   s~   d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	 d dl
mZ e eZdddZdd	d
Zdd Zdd Zdd ZdS )    N)walk)abspathisfilejoin)PopenPIPE)PUBLIC_DIR_REz.pyc                 c   s   t |}t| tt fr6| D ]}t|D ]
}|V  q&qnRt| rP| |rP| V  n8tt| D ]*\}}}|D ]}||rjt||V  qjq\dS )z6Generate *.py file names available in given directory.N)	tuple
isinstancelistfrom_directoryr   endswithr   r   r   )dname
extensionsitemfnrootdirsZ
file_names r   %/usr/share/python3/debpython/files.pyr      s    
r   c                 c   sh   t |}td|  dtd}| \}}|jdkr<td|  t|d}| D ]}||rN|V  qNdS )z4Generate *.py file names available in given package.z/usr/bin/dpkg -L %sT)shellstdoutr   zcannot get content of %szutf-8N)	r
   r   r   Zcommunicate
returncode	Exceptionstr
splitlinesr   )Zpackage_namer   Zprocessr   stderrliner   r   r   from_package.   s     


r   c                 c   s   | D ]}| |r|V  qdS )z4Generate *.py file names that match given directory.N)
startswith)filesr   r   r   r   r   filter_directory<   s    
r"   c                 c   s`   t dd |D }t dd |D }| D ]2}t|}|r(|d}||ksT||kr(|V  q(dS )z3Generate *.py file names that match given versions.c                 s   s   | ]}d | V  qdS )z%d.%dNr   .0ir   r   r   	<genexpr>E   s     z filter_public.<locals>.<genexpr>c                 s   s   | ]}t |d  V  qdS )r   N)r   r#   r   r   r   r&   F   s        N)setr   matchgroup)r!   ZversionsZvstrZshared_vstrr   Z
public_dirZversr   r   r   filter_publicC   s    

r+   c                 c   s&   t |}| D ]}||s|V  qdS )z<Removes files with matching extensions from given generator.N)r
   r   )r!   r   r   r   r   r   filter_out_extO   s    
r,   )r	   )r	   )Zloggingosr   os.pathr   r   r   
subprocessr   r   Z	debpythonr   Z	getLogger__name__logr   r   r"   r+   r,   r   r   r   r   <module>   s   


