o
    å¹´fU  ã                   @   s„   zd dl m Z  W n ey   dZ Y nw d dlZd dlZd dlmZmZ d dlmZ e 	e
¡Ze d¡ZG dd„ dƒZd
dd	„ZdS )é    )ÚdatetimeN)ÚPIPEÚPopen)Údumpsz4.*?/usr/lib/python(\d(?:.\d+)?)/(site|dist)-packagesc                   @   s   e Zd Zdd„ Zdd„ ZdS )Úmemoizec                 C   s   || _ i | _d S ©N)ÚfuncÚcache)Úselfr   © r   ú(/usr/share/python3/debpython/__init__.pyÚ__init__   s   
zmemoize.__init__c                 O   s6   t ||fƒ}|| jvr| j|i |¤Ž| j|< | j| S r   )r   r	   r   )r
   ÚargsÚkwargsÚkeyr   r   r   Ú__call__   s   

zmemoize.__call__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s    r   c           	      C   s  d||dœ}d}|du rn;|du r|j ttd� n/|rHt|tƒr'd}t|dƒ}tr5| d t ¡  	¡ ¡¡ | d | ¡¡ | 
¡  |j ||d� t d	| ¡ t| fi |¤Ž�&}| ¡ \}}|ob| ¡  t|j|olt|d
ƒ|ort|d
ƒd�W  d  ƒ S 1 sw   Y  dS )a<  Execute external shell commad.

    :param cdw: currennt working directory
    :param env: environment
    :param log_output:
        * opened log file or path to this file, or
        * None if output should be included in the returned dict, or
        * False if output should be redirectored to stdout/stderr
    T)ÚshellÚcwdÚenvFN)ÚstdoutÚstderrÚaz
# command executed on {}z
$ {}
zinvoking: %szutf-8)Ú
returncoder   r   )Úupdater   Ú
isinstanceÚstrÚopenr   ÚwriteÚformatÚnowÚ	isoformatÚflushÚlogÚdebugr   ÚcommunicateÚcloseÚdictr   )	Úcommandr   r   Ú
log_outputr   r(   Úprocessr   r   r   r   r   Úexecute   s2   



€þ$ýr-   )NNN)r   ÚImportErrorÚloggingÚreÚ
subprocessr   r   Úpickler   Ú	getLoggerr   r%   ÚcompileÚPUBLIC_DIR_REr   r-   r   r   r   r   Ú<module>   s    ÿ

