U
    ÇZj<-  ã                   @   s  d dl mZ d dl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Zd dlmZ d dlmZ d,dd	„Zd
d„ Zdd„ Zdd„ Zdd„ Zd-dd„Zdd„ Zdd„ Zdd„ Zd.dd„Zdd„ Zdd „ Zd/d!d"„Zd#d$„ Zd%d&„ Zdejjddfd'd(„Z dd)e!ƒ fd*d+„Z"dS )0é    )Úunicode_literalsN)Úlog)Úoptions)ÚversionFTc           	      C   s¤   |rt j}t j}nd }d }tj ¡ }|r2| |¡ t j| |||d�}| ¡ }|jrl|rlt	j
 d| |jf ¡‚t|ƒdksŒ|d rŒ|d  ¡ s�dS |d  ¡  dd¡S )N)ÚstdoutÚstderrÚenvz%s returned %dr   Ú úutf-8Úreplace)Ú
subprocessÚPIPEÚosÚenvironÚcopyÚupdateÚPopenÚcommunicateÚ
returncodeÚ	distutilsÚerrorsÚDistutilsErrorÚlenÚstripÚdecode)	ÚcmdZthrow_on_errorÚbufferr   Zout_locationZerr_locationZnewenvÚoutputÚout© r   úJ/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/pbr/git.pyÚ_run_shell_command"   s*    

ý
ÿ r!   c                 K   s,   t | ttfƒs| g} tdd| g|  f|ŽS )NÚgitz--git-dir=%s)Ú
isinstanceÚlistÚtupler!   )r   Úgit_dirÚkwargsr   r   r    Ú_run_git_command=   s    ÿÿr(   c               
   C   sP   zt dddgƒW S  tk
rJ }  z| jtjkr8W Y ¢
dS ‚ W 5 d } ~ X Y nX d S )Nr"   z	rev-parsez	--git-dirr	   )r!   ÚOSErrorÚerrnoÚENOENT)Úer   r   r    Ú_get_git_directoryD   s    
r-   c                   C   s,   zt ddgƒ W n tk
r&   Y dS X dS )Nr"   z	--versionFT)r!   r)   r   r   r   r    Ú_git_is_installedN   s
    r.   c                 C   s   t | tjd�S )z¦Find the highest tag from a list.

    Pass in a list of tag strings and this will return the highest
    (latest) as sorted by the pkg_resources version parser.
    )Úkey)ÚmaxÚpkg_resourcesÚparse_version)Útagsr   r   r    Ú_get_highest_tagY   s    r4   r	   c                 C   sL   g }|dkrt ƒ }|r>t d¡ tddg|ƒ}| d d¡¡}dd„ |D ƒS )	zÈBehave like a file finder entrypoint plugin.

    We don't actually use the entrypoints system for this because it runs
    at absurd times. We only want to do this when we are building an sdist.
    Nz2[pbr] In git context, generating filelist from gitzls-filesz-zó    r
   c                 S   s   g | ]}|r|‘qS r   r   )Ú.0Úfr   r   r    Ú
<listcomp>q   s      z#_find_git_files.<locals>.<listcomp>)Ú_run_git_functionsr   Úinfor(   Úsplitr   )Údirnamer&   Ú	file_listr   r   r    Ú_find_git_filesb   s    
r>   c                 C   s6   t ddg| ƒ}d|kr&| dd¡d S d|kr2dS d S )NÚdescribez--alwaysú-é   éþÿÿÿÚ.r   )r(   Úrsplit)r&   r?   r   r   r    Ú_get_raw_tag_infot   s    rE   c                 C   s   t | ƒdkS )Nr   )rE   ©r&   r   r   r    Úget_is_release}   s    rG   c                  C   s   d } t ƒ rtƒ } | pd S )N)r.   r-   rF   r   r   r    r9   �   s    r9   c                 C   s"   | s
t ƒ } | rtdddg| ƒS dS )z1Return the short sha for this repo, if it exists.r   z-n1z--pretty=format:%hN)r9   r(   rF   r   r   r    Úget_git_short_shaˆ   s     ÿrH   c                 C   s(   |   dd¡} |   dd¡} |   dd¡} | S )a®  Cleans any instances of invalid sphinx wording.

    This escapes/removes any instances of invalid characters
    that can be interpreted by sphinx as a warning or error
    when translating the Changelog into an HTML file for
    documentation building within projects.

    * Escapes '_' which is interpreted as a link
    * Escapes '*' which is interpreted as a new line
    * Escapes '`' which is interpreted as a literal
    Ú*z\*Ú_z\_ú`z\`)r   ©Úmsgr   r   r    Ú_clean_changelog_message’   s    rN   c                 c   s¢   d}d}|dfV  | D ]†\}}}|r\t |ƒ}t|ƒd }|sF|dfV  |dt||d� fV  | d¡s˜| d	¡r||dd
… }t|ƒ}|dt|d� fV  d}qdS )zçConvert a oneline log iterator to formatted strings.

    :param changelog: An iterator of one line log entries like
        that given by _iter_log_oneline.
    :return: An iterator over (release, formatted changelog) tuples.
    TNzCHANGES
=======

r@   Ú
z%(tag)s
%(underline)s

)ÚtagÚ	underlinezMerge rC   éÿÿÿÿz
* %(msg)s
rL   F)r4   r   ÚdictÚ
startswithÚendswithrN   )Ú	changelogÚ
first_lineZcurrent_releaseÚhashr3   rM   rQ   r   r   r    Ú_iter_changelog¦   s(    


ÿÿ

rY   c                 C   s   | dkrt ƒ } | sg S t| ƒS )aQ  Iterate over --oneline log entries if possible.

    This parses the output into a structured form but does not apply
    presentation logic to the output - making it suitable for different
    uses.

    :return: An iterator of (hash, tags_set, 1st_line) tuples, or None if
        changelog generation is disabled / not available.
    N)r-   Ú_iter_log_innerrF   r   r   r    Ú_iter_log_onelineÂ   s
    
r[   c                 C   s.   zt j | ¡ W dS  tk
r(   Y dS X d S )NTF)r   ZSemanticVersionZfrom_pip_stringÚ
ValueError)Ú	candidater   r   r    Ú_is_valid_versionÓ   s
    r^   c                 c   s¾   t  d¡ dddg}t|| ƒ}| d¡D ]�}| d¡}t|ƒdkrDq(|\}}}tƒ }d|kr¬| ¡ d	d
… }| d¡d	d… D ],}	|	 d¡d  dd¡}
t|
ƒr~| 	|
¡ q~|||fV  q(dS )a  Iterate over --oneline log entries.

    This parses the output intro a structured form but does not apply
    presentation logic to the output - making it suitable for different
    uses.

    .. caution:: this function risk to return a tag that doesn't exist really
                 inside the git objects list due to replacement made
                 to tag name to also list pre-release suffix.
                 Compliant with the SemVer specification (e.g 1.2.3-rc1)

    :return: An iterator of (hash, tags_set, 1st_line) tuples.
    z[pbr] Generating ChangeLogr   z--decorate=fullz--format=%h%x00%s%x00%drO   ú é   z
refs/tags/é   rR   Nz, r   r@   rC   )
r   r:   r(   r;   r   Úsetr   r   r^   Úadd)r&   Zlog_cmdrV   ÚlineZ
line_partsÚsharM   Zrefnamer3   Z
tag_stringr]   r   r   r    rZ   Û   s     




rZ   c              	   C   sÚ   t   ¡ }|si }t |dd¡}|r&dS |s@t| d�}|r@t|ƒ}|sHdS tj |d¡}tj |¡r~t 	|tj
¡s~t d¡ dS t d¡ tj|dd	d
��}|D ]\}}	| |	¡ qžW 5 Q R X t   ¡ }
t d|
|  ¡ dS )z-Write a changelog based on the git changelog.Zskip_changelogZSKIP_WRITE_GIT_CHANGELOGNrF   Z	ChangeLogzI[pbr] ChangeLog not written (file already exists and it is not writeable)z[pbr] Writing ChangeLogÚwr
   )Úencodingz![pbr] ChangeLog complete (%0.1fs))Útimer   Úget_boolean_optionr[   rY   r   ÚpathÚjoinÚexistsÚaccessÚW_OKr   r:   ÚioÚopenÚwrite)r&   Údest_dirÚoption_dictrV   ÚstartÚshould_skipZnew_changelogZchangelog_fileÚreleaseÚcontentÚstopr   r   r    Úwrite_git_changelog  s0    ÿ


ry   rC   c              
      sh  t  |dd¡}|rdS t ¡ }tj |d¡}tj |d¡}tj |¡rXt |tj¡sXdS t	 
d¡ d‰ | dkrttƒ } | �rJg }dd	g}|t|| ƒ d
¡7 }‡ fdd„|D ƒ}td| ƒ}	t d|	tj¡}
dd„ |
D ƒ}
||
7 }tt|ƒƒ}t|dƒ�R}tj |¡�r&t|dƒ�}| | ¡ ¡ W 5 Q R X | d
 |¡d
  d¡¡ W 5 Q R X t ¡ }t	 
d||  ¡ dS )z&Create AUTHORS file using git commits.Zskip_authorsZSKIP_GENERATE_AUTHORSNz
AUTHORS.inZAUTHORSz[pbr] Generating AUTHORSz5((jenkins|zuul)@review|infra@lists|jenkins@openstack)r   z--format=%aN <%aE>rO   c                    s   g | ]}t  ˆ |¡s|‘qS r   )ÚreÚsearch)r6   Úa©Zignore_emailsr   r    r8   ?  s      z$generate_authors.<locals>.<listcomp>zCo-authored-by:.+c                 S   s$   g | ]}|r|  d d¡d  ¡ ‘qS )ú:ra   )r;   r   )r6   Úsignedr   r   r    r8   E  s    ÿÚwbÚrbr
   z[pbr] AUTHORS complete (%0.1fs))r   ri   rh   r   rj   rk   rl   rm   rn   r   r:   r-   r(   r;   rz   ÚfindallÚ	MULTILINEÚsortedrb   rp   rq   ÚreadÚencode)r&   rr   rs   ru   rt   Zold_authorsZnew_authorsZauthorsZgit_log_cmdZco_authors_outZ
co_authorsZnew_authors_fhZold_authors_fhrx   r   r}   r    Úgenerate_authors'  sJ    ÿ

ÿÿÿr‡   )FTN)r	   N)N)N)#Ú
__future__r   Údistutils.errorsr   r   r*   ro   r   rz   r   rh   r1   Zpbrr   r   r!   r(   r-   r.   r4   r>   rE   rG   r9   rH   rN   rY   r[   r^   rZ   rj   Úcurdirry   rS   r‡   r   r   r   r    Ú<module>   s>   

	
	


, ÿ
 