Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/Tools/scripts/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/Tools/scripts/__pycache__/patchcheck.cpython-35.pyc



��Yfo%�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ej
d�Zdd�Zdddd�Z
d	d
�Zdd�Zd
d�Ze
dddd��dd��Ze
dddd��ddd��Zdd�Ze
dde�dd��Ze
dde�dd ��Zejd!�Ze
d"de�d#d$��Ze
d%d&d'�d(d)��Ze
d*d&d'�d+d,��Ze
d-d&d'�d.d/��Ze
d0d&d'de�d1d2��Ze
d3d&d'de�d4d5��Zd6d7�Zd8d9�Z e!d:kr�ddl"Z"e"j#d;e�Z$e$j%d<d=d>�e$j&�Z'e'jr�ee'j�ne �dS)?z)Check proposed changes for common issues.�N�srcdircCs"dj||dkrdnd�S)z7Return 'N file(s)' with the proper plurality on 'file'.z	{} file{}��s�)�format)�count�r�=/opt/alt/python35/lib64/python3.5/Tools/scripts/patchcheck.py�n_files_strsr
Fcs���fdd�}|S)z*Decorator to output status info to stdout.cs����fdd�}|S)Ncs~tjj�d�tjj��||�}�rK�rKtd�n/�rdt�|��nt|rsdnd�|S)Nz ... �done�yesZNO)�sys�stdout�write�flush�print)�args�kwargs�result)�fxn�info�message�modalrr	�call_fxns

z/status.<locals>.decorated_fxn.<locals>.call_fxnr)rr)rrr)rr	�
decorated_fxnszstatus.<locals>.decorated_fxnr)rrrrr)rrrr	�statuss
rc	Cs`d}tj|j�dtjdtj��,}|j�\}}|jdkoT|SWdQRXdS)z*Check if there are any applied MQ patches.zhg qappliedr�stderrrN)�
subprocess�Popen�split�PIPEZcommunicate�
returncode)�cmd�stZbstdout�_rrr	�mq_patches_applied's	r%cCsFdj�}ytj|dtj�SWntjk
rAdSYnXdS)z0Get the symbolic name for the current git branchzgit rev-parse --abbrev-ref HEADrN)rr�check_output�DEVNULL�CalledProcessError)r"rrr	�get_git_branch1s
r)cCsFdj�}ytj|dtj�Wntjk
rAdSYnXdS)zkGet the remote name to use for upstream branches

    Uses "upstream" if it exists, "origin" otherwise
    zgit remote get-url upstreamr�originZupstream)rrr&r'r()r"rrr	�get_git_upstream_remote:s	r+zGetting base branch for PRrcCs|dk	r|SdS)Nznot a PR branchr)�xrrr	�<lambda>Hsr-cCs�tjjtjjtd��s%dStj}|jdkrFd}ndj|�}t	�}|dksv||krzdSt
�}|d|S)Nz.gitZalphaZmasterz{0.major}.{0.minor}�/)�os�path�exists�join�SRCDIRr
�version_info�releaselevelrr)r+)�version�base_branchZthis_branchZupstream_remoterrr	�get_base_branchGs!				r8z6Getting the list of files that have been added/changedcCstt|��S)N)r
�len)r,rrr	r-[scCs�tjjtjjtd��r�|dk	r:tjd�d}t�rS|d7}tj	|j
�dtj��}dd�|jD�SWdQRXn
tjj
tjjtd	��r�|r�d
|}nd}g}tj	|j
�dtj���}x�|jD]�}|j�j�}|j
dd
�\}}t|�}|jd�sKq�d|krs|j
dd�d
j�}|j|�q�WWdQRX|Stjd�dS)z=Get the list of changed or added files from Mercurial or git.z.hgNz&need a git checkout to check PR statusz(hg status --added --modified --no-statusz --rev qparentrcSs"g|]}|j�j��qSr)�decode�rstrip)�.0r,rrr	�
<listcomp>es	z!changed_files.<locals>.<listcomp>z.gitzgit diff --name-status zgit status --porcelain�maxsplitrZMAUz -> �z6need a Mercurial or git checkout to get modified files)r/r0�isdirr2r3r
�exitr%rrrr rr1r:r;�set�intersection�strip�append)r7r"r#�	filenames�lineZstatus_text�filenamerrrr	�
changed_filesZs2!
	
!!
!rIcCsrt|�}|dkr"t|�Sdjt|��g}x$|D]}|jdj|��qAWdj|�SdS)Nrz{}:z  {}�
)r9r
rrEr2)�
file_pathsr�linesr0rrr	�report_modified_files�s

rMzFixing Python file whitespacecCs dt_dd�|D�}|S)zAMake sure that the whitespace for .py files have been normalized.FcSsCg|]9}|jd�rtjtjjt|��r|�qS)z.py)�endswith�reindentZcheckr/r0r2r3)r<r0rrr	r=�s	z(normalize_whitespace.<locals>.<listcomp>)rOZ
makebackup)rK�fixedrrr	�normalize_whitespace�s	rQzFixing C file whitespacec
Cs�g}xt|D]l}tjjt|�}t|d��}d|j�krOw
WdQRXtj|ddd�|j|�q
W|S)zReport if any C files �r�	N��verboseF)	r/r0r2r3�open�read�untabifyZprocessrE)rKrPr0�abspath�frrr	�normalize_c_whitespace�s

r[s\s+(\r?\n)$zFixing docs whitespacecCs�g}x�|D]�}tjjt|�}y�t|d��}|j�}WdQRXdd�|D�}||kr�tj||d�t|d��}|j|�WdQRX|j	|�Wq
t
k
r�}ztd||f�WYdd}~Xq
Xq
W|S)N�rbcSs"g|]}tjd|��qS)s\1)�ws_re�sub)r<rGrrr	r=�s	z-normalize_docs_whitespace.<locals>.<listcomp>z.bak�wbzCannot fix %s: %s)r/r0r2r3rV�	readlines�shutilZcopyfile�
writelinesrE�	Exceptionr)rKrPr0rYrZrLZ	new_lines�errrrr	�normalize_docs_whitespace�s
+rez
Docs modifiedrTcCs
t|�S)z9Report if any file in the Doc directory has been changed.)�bool)rKrrr	�
docs_modified�srgzMisc/ACKS updatedcCstjjdd�|kS)z$Check if Misc/ACKS has been changed.�Misc�ACKS)r/r0r2)rKrrr	�credit_given�srjzMisc/NEWS updatedcCstjjdd�|kS)z$Check if Misc/NEWS has been changed.rh�NEWS)r/r0r2)rKrrr	�
reported_news�srlzconfigure regeneratedcCs(d|kr d|krdSdSdSdS)z(Check if configure has been regenerated.zconfigure.acZ	configurer�noz
not neededNr)rKrrr	�regenerated_configure�srnzpyconfig.h.in regeneratedcCs(d|kr d|krdSdSdSdS)z,Check if pyconfig.h.in has been regenerated.zconfigure.acz
pyconfig.h.inrrmz
not neededNr)rKrrr	�regenerated_pyconfig_h_in�srocCs�|dkrtd�dSt�}t|�}dd�|D�}dd�|D�}dd�|D�}g}|jt|��|jt|��|jt|��|s�td�n!td�td	�tjd
�dS)N�falsezNot a pull request; skippingcSs%g|]}|jd�r|�qS)z.py)rN)r<�fnrrr	r=�s	ztravis.<locals>.<listcomp>cSs%g|]}|jd�r|�qS)�.c�.h)rrrs)rN)r<rqrrr	r=�s	cSs4g|]*}|jd�r|jd�r|�qS)�Doc�.rst�.inc)rurv)�
startswithrN)r<rqrrr	r=�s	zNo whitespace issues foundz-Please fix the file(s) with whitespace issuesz9(on UNIX you can run `make patchcheck` to make the fixes)r)	rr8rI�extendrQr[rer
rA)Zpull_requestr7rK�python_files�c_files�	doc_filesrPrrr	�travis�s"
	


r|cCs	t�}t|�}dd�|D�}dd�|D�}dd�|D�}tjjdd�tjjdd�ht|�@}t|�t|�t|�t	|�t
|�t|�t|�t
|�|s�|r|r�dnd	}t�td
|�dS)NcSs%g|]}|jd�r|�qS)z.py)rN)r<rqrrr	r=�s	zmain.<locals>.<listcomp>cSs%g|]}|jd�r|�qS)�.c�.h)r}r~)rN)r<rqrrr	r=�s	cSs4g|]*}|jd�r|jd�r|�qS)rt�.rst�.inc)rr�)rwrN)r<rqrrr	r=�s	rhrirkz and check for refleaks?�?zDid you run the test suite)r8rIr/r0r2rBrQr[rergrjrlrnror)r7rKryrzr{Z
misc_files�endrrr	�main�s&	'








r��__main__Zdescriptionz--travis�helpzPerform pass/fail checks)(�__doc__�rer
raZos.pathr/r�	sysconfigrOrX�get_config_varr3r
rr%r)r+r8rIrMrQr[�compiler]rergrjrl�strrnror|r��__name__�argparse�ArgumentParser�parser�add_argument�
parse_argsrrrrr	�<module>sP
	
		$	$$!