ReC@sddlmZddlZddlZddlZddlZddlZddlmZm Z m Z ddl m Z ddl mZmZmZmZmZejeZdjZejdZd Zd d ZeZGd d d eZdS))BytesION) sysconfigdetect_encodingZipFile)finder) FileOperatorget_export_entry convert_pathget_executablein_venva s^#!.*pythonw?[0-9.]*([ ].*)?$z# -*- coding: utf-8 -*- import re import sys from %(module)s import %(import_name)s if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) sys.exit(%(func)s()) cCsd|kr{|jdrb|jdd\}}d|kr{|jd r{d||f}n|jds{d|}|S)N z /usr/bin/env r"z%s "%s"z"%s") startswithsplit) executableenv _executabler/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/distlib/scripts.pyenquote_executable3s  rc@sNeZdZdZeZdZdddddZddZe j j d rid d Z d d Z ddZddddZddZeZddZddZdddZddZeddZejddZejd ks ejd kr,ejd kr,d!d"Zdd#d$Zdd%d&ZdS)' ScriptMakerz_ A class to copy or create scripts from source scripts or callable specifications. NTFcCs||_||_||_d|_d|_tjdkpWtjdkoWtjdk|_t d|_ |p{t ||_ tjdkptjdkotjdk|_ tj|_dS)NFposixjavaX.Ynt)rr) source_dir target_dir add_launchersforceclobberosname_nameset_modesetvariantsr_fileop_is_ntsys version_info)selfrrrdry_runfileoprrr__init__Ns     !zScriptMaker.__init__cCs^|jddrZ|jrZtjj|\}}|jdd}tjj||}|S)NguiFpythonpythonw)getr)r"pathrreplacejoin)r,roptionsdnfnrrr_get_alternate_executable_s z%ScriptMaker._get_alternate_executablercCs`y-t|}|jddkSWdQRXWn,ttfk r[tjd|dSYnXdS)zl Determine if the specified executable is a script (contains a #! line) z#!NzFailed to open %sF)openreadOSErrorIOErrorloggerwarning)r,rfprrr _is_shellgs zScriptMaker._is_shellcCs^|j|r=ddl}|jjjddkrV|Sn|jjdrV|Sd|S)Nrzos.nameLinuxz jython.exez/usr/bin/env %s)rCrlangSystem getPropertylowerendswith)r,rrrrr_fix_jython_executabless z"ScriptMaker._fix_jython_executablecCstjdkrd}nPt|t|d}tjdkrJd}nd}d|koe||k}|rd||d }n&d }|d ||d 7}|d 7}|S)a Build a shebang line. In the simple case (on Windows, or a shebang line which is not too long or contains spaces) use a simple formulation for the shebang. Otherwise, use /bin/sh as the executable, with a contrived shebang which allows the script to run either under Python or sh, using suitable quoting. Thanks to Harald Nordgren for his input. See also: http://www.in-ulm.de/~mascheck/various/shebang/#length https://hg.mozilla.org/mozilla-central/file/tip/mach rTdarwini s#!s s #!/bin/sh s '''exec' s "$0" "$@" s' ''')r"r#lenr*platform)r,r post_interpsimple_shebangshebang_lengthmax_shebang_lengthresultrrr_build_shebangs      zScriptMaker._build_shebangcCsd}|jr!|j}d}ntjs9t}nqtrptjjtjddtj d}n:tjjtj ddtj dtj df}|r|j ||}t j j d r|j|}|rt|}|jd }t j d kr5d |kr5d |kr5|d7}|j||}y|jd Wn"tk r|td|YnX|d kry|j|Wn(tk rtd||fYnX|S)NTFscriptszpython%sEXEBINDIRz python%s%sVERSIONrzutf-8cliz -X:Framesz -X:FullFramess -X:Framesz,The shebang (%r) is not decodable from utf-8z?The shebang (%r) is not decodable from the script encoding (%r))rris_python_buildr r r"r4r6get_pathget_config_varr:r*rPrrJrencoderVdecodeUnicodeDecodeError ValueError)r,encodingrQr7enquotershebangrrr _get_shebangsJ               zScriptMaker._get_shebangcCs6|jtd|jd|jjddd|jS)Nmodule import_name.rfunc)script_templatedictprefixsuffixr)r,entryrrr_get_script_textszScriptMaker._get_script_textcCstjj|}|j|S)N)r"r4basenamemanifest)r,exenamebaserrr get_manifestszScriptMaker.get_manifestcCs|jo|j}tjjd}|j|s=||7}|sP||}ny|dkrn|jd}n|jd}t} t| d} | j d|WdQRX| j } ||| }x|D]} tj j |j | } |rtj j| \}}|jdr!|} d| } y|jj| |Wqqtk rtjdd | }tj j|rtj|tj| ||jj| |tjd ytj|Wntk rYnXYqqXn|jr| jd | rd | |f} tj j| rB|j rBtjd | q|jj| ||jrq|jj| g|j| qWdS)Nzutf-8pytwz __main__.pyz.pyz%s.exez:Failed to write executable - trying to use .deleteme logicz %s.deletemez0Able to replace executable using .deleteme logicrjz%s.%szSkipping existing file %s)rr)r"linesepr`rI _get_launcherrrwritestrgetvaluer4r6rsplitextrr(write_binary_file Exceptionr@rAexistsremoverenamedebugr!r%set_executable_modeappend)r,namesrf script_bytes filenamesext use_launcherrzlauncherstreamzfzip_datar#outnamenedfnamerrr _write_scriptsX               zScriptMaker._write_scriptc CsLd}|rF|jdg}|rFddj|}|jd}|jd|d|}|j|jd}|j}t} d|jkr| j|d|jkr| jd ||j d fd |jkr| jd ||j d |j d f|r)|jddr)d} nd} |j | |||| dS)NrWinterpreter_argsz %sr zutf-8r7rXz%s%srzX.Yz%s-%s.%srr0Fpywrw) r3r6r`rgrqr#r&r'addr+r) r,rprr7rQargsrfscriptr# scriptnamesrrrr _make_scripts*    zScriptMaker._make_scriptcCs/d}tjj|jt|}tjj|jtjj|}|j r||jj || r|t j d|dSyt |d}Wn$t k r|jsd}YnlX|j}|st jd|j|dStj|jdd}|r!d}|jdpd }|sv|r7|j|jj|||jrf|jj|g|j|nt jd ||j|jjst|j\} } |jd |j| |} d |krd } nd} tjj|} |j| g| |j || |r+|jdS)NFznot copying %s (up-to-date)rbz"%s: %s is an empty file (skipping)s s TrrWzcopying and adjusting %s -> %srspythonwrrw)!r"r4r6rr rrrr r(newerr@rr<r?r-readlinerAget_command_name FIRST_LINE_REmatchr5groupclose copy_filer%rrinforseekrgrr=)r,rradjustrf first_linerrQrdlinesrfrrrrr _copy_script5sR$              "zScriptMaker._copy_scriptcCs |jjS)N)r(r-)r,rrrr-iszScriptMaker.dry_runcCs||j_dS)N)r(r-)r,valuerrrr-msrcCstjddkrd}nd}d||f}tjddd}t|j|}|sd ||f}t||jS) NPZ64Z32z%s%s.exerjrrz(Unable to find resource %s in package %s)structcalcsize__name__rsplitrfindrcbytes)r,kindbitsr#Zdistlib_packageresourcemsgrrrr{us   zScriptMaker._get_launchercCsKg}t|}|dkr1|j||n|j||d||S)a Make a script. :param specification: The specification, which is either a valid export entry specification (to make a script from a callable) or a filename (to make a script by copying from a source location). :param options: A dictionary of options controlling script generation. :return: A list of all absolute pathnames written to. Nr7)r rr)r, specificationr7rrprrrmakes   zScriptMaker.makecCs4g}x'|D]}|j|j||q W|S)z Take a list of specifications and make scripts from them, :param specifications: A list of specifications. :return: A list of all absolute pathnames written to, )extendr)r,specificationsr7rrrrr make_multiples zScriptMaker.make_multiple) r __module__ __qualname____doc__SCRIPT_TEMPLATErlrr/r:r*rPrrCrJrVrgrq_DEFAULT_MANIFESTrsrvrrrpropertyr-setterr"r#r$r{rrrrrrrEs.   @   4 4- r)iorloggingr"rerr*compatrrr resourcesrutilrr r r r getLoggerrr@striprcompilerrr_enquote_executableobjectrrrrrs     (