o
    Nis                     @   s~   d dl mZ d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 ejdd Zdd Zd	d
 Zdd ZdS )    )absolute_import)print_functionN)ConfigParserc                 c   sR    t  }||  |V  t| d}|| W d    d S 1 s"w   Y  d S )Nw)r   readopenwrite)filenamecfgfp r   B/home/ubuntu/.local/lib/python3.10/site-packages/pbr/tests/util.pyopen_config6   s   
"r   c                 C   s.   dd }t jdkrtj| |dS tj| |dS )zkshutil.rmtree() with error handler.

    Handle 'access denied' from trying to delete read-only files.
    c                 S   s*   t |t jst |tj | | d S  )N)osaccessW_OKchmodstatS_IWUSR)funcpathexc_infor   r   r   onexcE   s   zrmtree.<locals>.onexc)      )r   )onerror)sysversion_infoshutilrmtree)r   r   r   r   r   r   ?   s   
r   c                 C   s   t j }d|d< tdd|   tj| tjtjtj||d}tdd |	 D }td t|d	  td
 t|d  ||j
f S )aH  Run the command args in cwd.

    :param args: The command to run e.g. ['git', 'status']
    :param cwd: The directory to run the command in.
    :param env: The environment variables to set. If unset, fallback to the
        default of inheriting those from the current process.
    :return: ((stdout, stderr), returncode)
    ignorePYTHONWARNINGSz
Running %s )stdinstdoutstderrcwdenvc                 s   s    | ]
}| d  V  qdS )latin1N)decodestrip).0sr   r   r   	<genexpr>g   s    zrun_cmd.<locals>.<genexpr>zSTDOUT:r   zSTDERR:   )r   environcopyprintjoin
subprocessPopenPIPEtuplecommunicate
returncode)argsr&   r'   pstreamsr   r   r   run_cmdR   s"   
	r<   c                   C   s.   t g dd  t g dd  t g dd  d S )N)gitconfig--globalz
user.emailexample@example.com)r=   r>   r?   z	user.namezOpenStack Developer)r=   r>   r?   zuser.signingkeyr@   )r<   r   r   r   r   
config_gito   s   rA   )
__future__r   r   
contextlibr   r   r   r3   r   pbr._compat.fiver   contextmanagerr   r   r<   rA   r   r   r   r   <module>   s   (
