File: //usr/share/python3/debpython/__pycache__/files.cpython-39.pyc
a
    �j`�  �                   @   s~   d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	 d dl
mZ e �e
�Zddd�Zdd	d
�Zdd� Zd
d� Zdd� ZdS )�    N)�walk)�abspath�isfile�join)�Popen�PIPE)�
PUBLIC_DIR_RE�z.pyc                 c   s�   t |�}t| tt f�r6| D ]}t|�D ]
}|V  q&qnRt| �rP| �|�rP| V  n8tt| ��D ]*\}}}|D ]}|�|�rjt||�V  qjq\dS )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 |�}td|  dtd�}|�� \}}|jdkr<td|  ��t|d�}|�� D ]}|�|�rN|V  qNdS )z4Generate *.py file names available in given package.z/usr/bin/dpkg -L %sT)�shell�stdoutr   zcannot get content of %szutf-8N)	r
   r   r   Zcommunicate�
returncode�	Exception�str�
splitlinesr   )Zpackage_namer   Zprocessr   �stderr�liner   r   r   �from_package.   s    �
r   c                 c   s   | D ]}|� |�r|V  qdS )z4Generate *.py file names that match given directory.N)�
startswith)�filesr   r   r   r   r   �filter_directory<