o ƚRe8E@sddlmZddlZddlZddlZddlZddlZddlmZm Z m Z ddl m Z ddl mZmZmZmZmZmZeeZdZedZd Zd d ZeZGd d d eZdS))BytesION) sysconfigdetect_encodingZipFile)finder) FileOperatorget_export_entry convert_pathget_executable get_platformin_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()) cCsZd|vr+|dr"|dd\}}d|vr |ds d||f}|S|ds+d|}|S)N z /usr/bin/env r"z%s "%s"z"%s") startswithsplit) executableenv _executabler/builddir/build/BUILDROOT/alt-python310-pip-21.3.1-3.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/distlib/scripts.pyenquote_executable3s   rc@seZdZdZeZdZ  d*ddZddZe j d r#d d Z d d Z ddZd+ddZddZeZddZddZdZddZd,ddZddZed d!Zejd"d!Zejd#kseejd kriejd#krid$d%Zd,d&d'Z d,d(d)Z!dS)- ScriptMakerz_ A class to copy or create scripts from source scripts or callable specifications. NTFcCs||_||_||_d|_d|_tjdkptjdkotjdk|_t d|_ |p)t ||_ tjdkp9tjdko9tjdk|_ tj|_dS)NFposixjava)X.Ynt) source_dir target_dir add_launchersforceclobberosname_nameset_modesetvariantsr_fileop_is_ntsys version_info)selfrrr dry_runfileoprrr__init__Ns   zScriptMaker.__init__cCs@|ddr|jrtj|\}}|dd}tj||}|S)NguiFpythonpythonw)getr*r#pathrreplacejoin)r-roptionsdnfnrrr_get_alternate_executable_s  z%ScriptMaker._get_alternate_executablerc Csdzt|}|ddkWdWS1swYWdSttfy1td|YdSw)zl Determine if the specified executable is a script (contains a #! line) z#!NzFailed to open %sF)openreadOSErrorIOErrorloggerwarning)r-rfprrr _is_shellgs  ( zScriptMaker._is_shellcCsJ||rddl}|jjddkr|Sd|S|dr!|Sd|S)Nrzos.nameLinuxz jython.exez/usr/bin/env %s)rDrlangSystem getPropertylowerendswith)r-rrrrr_fix_jython_executabless z"ScriptMaker._fix_jython_executablecCstjdkrd}nt|t|d}tjdkrd}nd}d|vo#||k}|r0d||d }|Sd }|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 #!/bin/sh s '''exec' s "$0" "$@" s' ''')r#r$lenr+platform)r-r post_interpsimple_shebangshebang_lengthmax_shebang_lengthresultrrr_build_shebangs  zScriptMaker._build_shebangcCsnd}|jr |j}d}nDtst}n %srspythonwrr|) r#r5r7rr rrwr!r)newerrArr=r@r.readlinerB FIRST_LINE_REmatchr6groupclose copy_filer&rrinforseekrkrr>)r-rradjustrf first_linerrSrhlinesrjrrrrr _copy_script?sV       zScriptMaker._copy_scriptcCs|jjSrvr)r.)r-rrrr.rszScriptMaker.dry_runcCs ||j_dSrvr)r-valuerrrr.vs rcCsttddkr d}nd}tdkrdnd}d|||f}td d d }t||}|s7d ||f}t||jS) NPZ64Z32z win-arm64z-armrz %s%s%s.exerlrrz(Unable to find resource %s in package %s) structcalcsizer __name__rsplitrfindrgbytes)r-kindbitsZplatform_suffixr$Zdistlib_packageresourcemsgrrrr~szScriptMaker._get_launchercCs8g}t|}|dur||||S|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. Nr)r rr)r- specificationr8rrtrrrmakes  zScriptMaker.makecCs$g}|D] }||||q|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-specificationsr8rrrrr make_multipleszScriptMaker.make_multiple)TFN)rYNrv)"r __module__ __qualname____doc__SCRIPT_TEMPLATErprr0r;r+rRrrDrKrXrkru_DEFAULT_MANIFESTrxr{rrrrrpropertyr.setterr#r$r%rrrrrrrrEs:    E4 3   r) iorloggingr#rerr+compatrrr resourcesrutilrr r r r r getLoggerrrAstriprcompilerrr_enquote_executableobjectrrrrrs$