3 \X � @ s� d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm Z d dl mZmZ d dlm Z d dlZejd�ZG d d � d e�ZG dd� dee�ZdS ) � N)�ST_MODE)� sysconfig)�Command)�newer)�convert_path� Mixin2to3)�logs ^#!.*python[0-9.]*([ ].*)?$c @ sH e Zd ZdZdddgZdgZdd� Zd d� Zdd� Zdd� Z dd� Z dS )� build_scriptsz("build" scripts (copy and fixup #! line)� build-dir=�d�directory to "build" (copy) to�force�f�1forcibly build everything (ignore file timestamps�executable=�e�*specify final destination interpreter pathc C s" d | _ d | _d | _d | _d | _d S )N)� build_dir�scriptsr � executable�outfiles)�self� r �7/usr/lib64/python3.6/distutils/command/build_scripts.py�initialize_options s z build_scripts.initialize_optionsc C s | j dddd� | jj| _d S ) NZbuildr r r r )r r )r r )r r )Zset_undefined_optionsZdistributionr )r r r r �finalize_options% s zbuild_scripts.finalize_optionsc C s | j S )N)r )r r r r �get_source_files, s zbuild_scripts.get_source_filesc C s | j s d S | j� d S )N)r �copy_scripts)r r r r �run/ s zbuild_scripts.runc " C s� | j | j� g }g }�x,| jD �] }d}t|�}tjj| jtjj|��}|j|� | j rtt ||� rttjd|� qyt |d�}W n tk r� | js�� d }Y nXX tj|j�\}}|jd� |j� } | s�| jd| � qtj| �} | r�d}| jd�p�d}|�rtjd || j� |j|� | j�stj�s2| j}n(tjjtjd �dtjd�tjd �f �}tj|�}d| | d } y| jd� W n$ tk �r� t dj!| ���Y nX y| j|� W n& tk �r� t dj!| |���Y nX t |d��}|j"| � |j#|j$� � W d Q R X |�r@|j%� q|�r*|j%� |j|� | j&||� qW tj'dk�r�xh|D ]`}| j�rptjd|� nDtj(|�t) d@ }|dB d@ }||k�rVtjd|||� tj*||� �qVW ||fS )NFznot copying %s (up-to-date)�rbr z%s is an empty file (skipping)T� � zcopying and adjusting %s -> %s�BINDIRz python%s%s�VERSION�EXEs #!� zutf-8z.The shebang ({!r}) is not decodable from utf-8zAThe shebang ({!r}) is not decodable from the script encoding ({})�wb�posixzchanging mode of %si� im z!changing mode of %s from %o to %o)+Zmkpathr r r �os�path�join�basename�appendr r r �debug�open�OSError�dry_run�tokenize�detect_encoding�readline�seek�warn� first_line_re�match�group�infor Zpython_buildr �get_config_var�fsencode�decode�UnicodeDecodeError� ValueError�format�write� writelines� readlines�closeZ copy_file�name�statr �chmod)r r � updated_filesZscriptZadjustZoutfiler �encoding�linesZ first_liner7 Zpost_interpr ZshebangZoutf�fileZoldmodeZnewmoder r r r 5 s� zbuild_scripts.copy_scriptsN)r r r )r r r )r r r )�__name__� __module__�__qualname__ZdescriptionZuser_optionsZboolean_optionsr r r r r r r r r r s r c @ s e Zd Zdd� ZdS )�build_scripts_2to3c C s&