o
    年f-                     @   s   d dl Z d dlmZ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environ)abspathisfilejoin)PopenPIPE)PUBLIC_DIR_REz.pyc                 c   s    t |}t| tt fr| D ]}t|D ]}|V  qqdS t| r+| |r+| V  dS tt| D ]\}}}|D ]}||rEt||V  q8q1dS )z6Generate *.py file names available in given directory.N)	tuple
isinstancelistfrom_directoryr   endswithr   r   r   )dname
extensionsitemfnrootdirs
file_names r   %/usr/share/python3/debpython/files.pyr      s"   

r   c                 c   s    t |}t }d|d< tdd| ftt|d}| \}}|jdkr)td|  |jdd	d
}|	 D ]
}|
|r>|V  q4dS )z4Generate *.py file names available in given package.zC.UTF-8LC_ALLz/usr/bin/dpkgz-L)stdoutstderrenvr   zcannot get content of %szutf-8replace)errorsN)r   r   copyr   r   communicate
returncode	Exceptiondecode
splitlinesr   )package_namer   r   processr   r   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   sb    t dd |D }t dd |D }| D ]}t|}|r.|d}||v s+||v 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>G   s    z filter_public.<locals>.<genexpr>c                 s   s    | ]	}t |d  V  qdS )r   N)strr,   r   r   r   r/   H   s       N)setr	   matchgroup)r*   versionsvstrshared_vstrr   
public_dirversr   r   r   filter_publicE   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_extQ   s   
r;   )r
   )loggingosr   r   os.pathr   r   r   
subprocessr   r   	debpythonr	   	getLogger__name__logr   r(   r+   r:   r;   r   r   r   r   <module>   s   


