U V&@sddlmZddlZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z d'ddZd d Zd d Zd dZddZd(ddZddZddZddZd)ddZddZd*ddZd d!Zdejjddfd"d#Zdd$efd%d&ZdS)+)unicode_literalsN)log)optionsFTc Cs|rtj}tj}nd}d}tj}|r2||tj||||d}|}|jrl|rlt j d||jft |dks|dr|d sdS|d ddS)N)stdoutstderrenvz%s returned %drutf-8replace) subprocessPIPEosenvironcopyupdatePopenZ communicate returncode distutilserrorsZDistutilsErrorlenstripdecode) cmdZthrow_on_errorbufferrZ out_locationZ err_locationZnewenvoutputoutr/git.py_run_shell_command!s*     rcKs,t|ttfs|g}tdd|g|f|S)Ngitz --git-dir=%s) isinstancelisttupler)rgit_dirkwargsrrr_run_git_command<sr%c CsPztdddgWStk rJ}z|jtjkr8WY dSW5d}~XYnXdS)Nrz rev-parsez --git-dirr)rOSErrorerrnoZENOENT)errr_get_git_directoryCs   r)cCs,ztddgWntk r&YdSXdS)Nrz --versionFT)rr&rrrr_git_is_installedMs r*cCst|tjdS)zFind 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_resourcesZ parse_version)tagsrrr_get_highest_tagXsr/rcCsLg}|dkrt}|r>tdtddg|}|dd}dd|DS) zBehave 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 gitzls-filesz-zr cSsg|] }|r|qSrr).0frrr psz#_find_git_files..)_run_git_functionsrinfor%splitr)dirnamer#Z file_listrrr_find_git_filesas r8cCs6tddg|}d|kr&|dddSd|kr2dSdS)Ndescribez--always-.r)r%rsplit)r#r9rrr_get_raw_tag_infoss r?cCs t|dkS)Nr)r?r#rrrget_is_release|srAcCsd}trt}|pdS)N)r*r)r@rrrr4sr4cCs"|s t}|rtdddg|SdS)z1Return the short sha for this repo, if it exists.rz-n1z--pretty=format:%hN)r4r%r@rrrget_git_short_shasrBccsd}d}|dfV|D]~\}}}|r\t|}t|d}|sF|dfV|dt||dfV|ds|d r||dd }|d t|d fVd }qdS)zConvert 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. TNzCHANGES ======= r: z%(tag)s %(underline)s )tag underlinezMerge r=z * %(msg)s )msgF)r/rdict startswithendswith) changelogZ first_lineZcurrent_releasehashr.rGrErrr_iter_changelogs&       rMcCs|dkrt}|sgSt|S)aQIterate 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_innerr@rrr_iter_log_onelines rOccstddddg}t||}|dD]}|}t|dkrBq(|ddrld |krl|d d}nd |dd }d |krtd d|d dddd D}nt}|d||fVq(d S)aIterate 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. :return: An iterator of (hash, tags_set, 1st_line) tuples. z[pbr] Generating ChangeLogrz --onelinez --decoraterCr;() Nztag:cSsg|]}|ddqS),r)r6)r1rDrrrr3sz#_iter_log_inner..rztag: ) rr5r%r6rrIrjoinset)r#Zlog_cmdrKlineZ line_partsrGr.rrrrNs     rNc Cst}|si}t|dd}|r&dS|s@t|d}|r@t|}|sHdStdtj |d}tj |r~t |tj s~dSt j|ddd }|D]\}} || qW5QRXt} td | |dS) z-Write a changelog based on the git changelog.Zskip_changelogZSKIP_WRITE_GIT_CHANGELOGNr@z[pbr] Writing ChangeLogZ ChangeLogwr )encodingz![pbr] ChangeLog complete (%0.1fs))timerget_boolean_optionrOrMrr5r pathrUexistsaccessW_OKioopenwrite) r#dest_dir option_dictrKstart should_skipZ new_changelogZchangelog_filereleaseZcontentstoprrrwrite_git_changelogs2     rir=c sht|dd}|rdSt}tj|d}tj|d}tj|rXt|tjsXdSt dd|dkrtt }|rJg}dd g}|t || d 7}fd d |D}t d|} td | tj} dd | D} || 7}tt|}t|dR} tj|r&t|d} | | W5QRX| d |d dW5QRXt} t d| |dS)z&Create AUTHORS file using git commits.Z skip_authorsZSKIP_GENERATE_AUTHORSNz AUTHORS.inZAUTHORSz[pbr] Generating AUTHORSz.(jenkins@review|infra@lists|jenkins@openstack)rz--format=%aN <%aE>rCcsg|]}t|s|qSr)research)r1aZ ignore_emailsrrr3s z$generate_authors..zCo-authored-by:.+cSs$g|]}|r|dddqS):rP)r6r)r1Zsignedrrrr3swbrbr z[pbr] AUTHORS complete (%0.1fs))rr[rZr r\rUr]r^r_rr5r)r%r6rjfindall MULTILINEsortedrVrarbreadencode)r#rcrdrfreZ old_authorsZ new_authorsZauthorsZ git_log_cmdZco_authors_outZ co_authorsZnew_authors_fhZold_authors_fhrhrrmrgenerate_authorssN       rv)FTN)rN)N)N) Z __future__rZdistutils.errorsrrr'r`r rjr rZr-Zpbrrrr%r)r*r/r8r?rAr4rBrMrOrNr\curdirrirHrvrrrrs8          "