
NwV                 @   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  j 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.pyc             c   s   t  |  } t |  t t  f  rQ x |  D]" } x t |  D] } | Vq; Wq( Wnw t |   rt |  j |  rt |  VnT xQ t t |    D]= \ } } } x+ | D]# } | j |  r t | |  Vq Wq Wd 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   s   t  |  } t d |  d d d t } | j   \ } } | j d k rY t d |    t | d  } x( | j   D] } | j |  ru | Vqu Wd S)	z4Generate *.py file names available in given package.z/usr/bin/dpkg -L %sshellTstdoutr   zcannot get content of %szutf-8N)	r
   r   r   communicate
returncode	Exceptionstr
splitlinesr   )Zpackage_namer   processr   stderrliner   r   r   from_package.   s    r!   c             c   s)   x" |  D] } | j  |  r | Vq Wd 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  } xO |  D]G } t j |  } | r9 | j d  } | | k s{ | | k r9 | Vq9 Wd 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   r'   F   s       N)setr   matchgroup)r#   versionsZvstrZshared_vstrr   
public_dirversr   r   r   filter_publicC   s    r/   c             c   s5   t  |  } x" |  D] } | j |  s | Vq Wd S)z<Removes files with matching extensions from given generator.N)r
   r   )r#   r   r   r   r   r   filter_out_extO   s    r0   )r	   )r	   )loggingosr   os.pathr   r   r   
subprocessr   r   	debpythonr   	getLogger__name__logr   r!   r$   r/   r0   r   r   r   r   <module>   s   