h fW@sdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z m Z ddlmZddlZejd ZGd d d eZGd d d ee ZdS)zRdistutils.command.build_scripts Implements the Distutils 'build_scripts' command.N)ST_MODE) sysconfig)Command)newer) convert_path Mixin2to3)logs^#!.*python[0-9.]*([ ].*)?$c@sjeZdZdZdddgZdgZd d Zd dZddZddZ ddZ dS) build_scriptsz("build" scripts (copy and fixup #! line) build-dir=ddirectory to "build" (copy) toforcef1forcibly build everything (ignore file timestamps executable=e*specify final destination interpreter pathcCs1d|_d|_d|_d|_d|_dS)N) build_dirscriptsr executableoutfiles)selfrD/opt/alt/python34/lib64/python3.4/distutils/command/build_scripts.pyinitialize_optionss     z build_scripts.initialize_optionscCs)|jdddd|jj|_dS) NZbuildr rr r)z build_scriptsz build_dir)forcer) executabler)Zset_undefined_optionsZ distributionr)rrrrfinalize_options%s  zbuild_scripts.finalize_optionscCs|jS)N)r)rrrrget_source_files,szbuild_scripts.get_source_filescCs|js dS|jdS)N)r copy_scripts)rrrrrun/s zbuild_scripts.runc"Cs|j|jg}g}x|jD]}d}t|}tjj|jtjj|}|j||j rt || rt j d|q&nyt |d}Wn'tk r|jsnd}YnXtj|j\}}|jd|j} | s*|jd|q&ntj| } | r]d}| jdpWd } n|rt jd ||j|j||jstjs|j} n:tjjtjd d tjd tjdf} tj| } d| | d} y| jdWn'tk r9t dj!| YnXy| j|Wn*tk rwt dj!| |YnXt |d'}|j"| |j#|j$WdQXn|r|j%qq&|r|j%n|j||j&||q&Wtj'dkrx|D]|}|jr5t jd|qtj(|t)d@}|dBd@}||krt jd|||tj*||qqWn||fS)a"Copy each script listed in 'self.scripts'; if it's marked as a Python script in the Unix way (first line matches 'first_line_re', ie. starts with "\#!" and contains "python"), then adjust the first line to refer to the current Python interpreter as we copy. Fznot copying %s (up-to-date)rbNrz%s is an empty file (skipping)Tzcopying and adjusting %s -> %sBINDIRz python%s%sVERSIONEXEs#!s zutf-8z.The shebang ({!r}) is not decodable from utf-8zAThe shebang ({!r}) is not decodable from the script encoding ({})wbposixzchanging mode of %siimz!changing mode of %s from %o to %o)+Zmkpathrrrospathjoinbasenameappendr rrdebugopenOSErrordry_runtokenizedetect_encodingreadlineseekwarn first_line_rematchgroupinforZ python_buildrget_config_varfsencodedecodeUnicodeDecodeError ValueErrorformatwrite writelines readlinescloseZ copy_filenamestatrchmod)rr updated_filesZscriptZadjustZoutfilerencodinglinesZ first_liner8Z post_interprZshebangZoutffileZoldmodeZnewmoderrrr5s $                        zbuild_scripts.copy_scriptsN)r r r )zforcerr)rrr) __name__ __module__ __qualname__Z descriptionZ user_optionsZboolean_optionsrrrr rrrrrr s       r c@seZdZddZdS)build_scripts_2to3cCs8tj|\}}|js.|j|n||fS)N)r rr1Zrun_2to3)rrrHrrrrs zbuild_scripts_2to3.copy_scriptsN)rLrMrNrrrrrrOs rO)__doc__r)rerFrZ distutilsrZdistutils.corerZdistutils.dep_utilrZdistutils.utilrrrr2compiler7r rOrrrrs