HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/relenv/__pycache__/common.cpython-310.pyc
o

�N�gp;�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZdZe�e���jZdZdZdZdZdZed	ed
ediZe
jdkrcej��dd
dZn	ej��ddZe�ej�de����Ze� d�Z!e� d�Z"e
jdkr�e!Z#ne"Z#e�$e%�Z&Gdd�de'�Z(e#fdd�Z)dd�Z*d?dd�Z+d?dd�Z,Gdd�d�Z-d?dd �Z.d@d!d"�Z/d@d#d$�Z0d%d&�Z1d'd(�Z2d?d)d*�Z3d+d,�Z4d-d.�Z5dAd0d1�Z6dBd3d4�Z7dCd7d8�Z8d9d:�Z9d;d<�Z:d=d>�Z;dS)Dz/
Common classes and values used around relenv.
�Nz0.18.1�linux�win32�darwinz10.15)z5packages.broadcom.com/artifactory/saltproject-genericzrepo.saltproject.iozwoz.io)�x86_64Zaarch64)rZarm64)Zamd64Zx86ZAppDataZLocal�relenvz.localZRELENV_DATAzP#!/bin/sh
"true" ''''
"exec" "$(dirname "$(readlink -f "$0")"){}" "$0" "$@"
'''
a�#!/bin/sh
"true" ''''
TARGET_FILE=$0
cd "$(dirname "$TARGET_FILE")" || return
TARGET_FILE=$(basename "$TARGET_FILE")
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
    TARGET_FILE=$(readlink "$TARGET_FILE")
    cd "$(dirname "$TARGET_FILE")" || return
    TARGET_FILE=$(basename "$TARGET_FILE")
done
PHYS_DIR=$(pwd -P)
REALPATH=$PHYS_DIR/$TARGET_FILE
"exec" "$(dirname "$REALPATH")"{} "$REALPATH" "$@"
'''c@seZdZdZdS)�RelenvExceptionz9
    Base class for exeptions generated from relenv.
    N)�__name__�
__module__�__qualname__�__doc__�rr�A/opt/saltstack/salt/lib/python3.10/site-packages/relenv/common.pyr_srcCs|�|���S)z%
    Return a formatted shebang.
    )�format�strip)�pythonZtplrrr
�format_shebangesrcCst��}|��S)z%
    Return the current machine.
    )�platform�machine�lower)rrrr
�
build_archlsrcCs"|dur
t�|���}|St}|S)a
    Get the root directory that all other relenv working directories should be based on.

    :param root: An explicitly requested root directory
    :type root: str

    :return: An absolute path to the relenv root working directory
    :rtype: ``pathlib.Path``
    N)�pathlib�Path�resolve�
MODULE_DIR)�root�baserrr
�	work_rootts

�rcCs.t|�}|tkr|d�|�}|S||}|S)a`
    Get the absolute path to the relenv working directory of the given name.

    :param name: The name of the directory
    :type name: str
    :param root: The root directory that this working directory will be relative to
    :type root: str

    :return: An absolute path to the requested relenv working directory
    :rtype: ``pathlib.Path``
    z_{})rrr)�namerrrrr
�work_dir�s�rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�WorkDirsz�
    Simple class used to hold references to working directories relenv uses relative to a given root.

    :param root: The root of the working directories tree
    :type root: str
    cCsT||_td|j�|_tdt�|_tdt�|_tdt�|_tdt�|_tdt�|_dS)N�	toolchain�build�src�logs�download)	rr�toolchain_config�DATA_DIRr r!r"r#r$)�selfrrrr
�__init__�szWorkDirs.__init__cCs"|j|j|j|j|j|j|jd�S)z[
        Return an object used for pickling.

        :return: The picklable state
        �rr%r r!r"r#r$r))r'rrr
�__getstate__�s�zWorkDirs.__getstate__cCsJ|d|_|d|_|d|_|d|_|d|_|d|_|d|_dS)	z�
        Unwrap the object returned from unpickling.

        :param state: The state to unpickle
        :type state: dict
        rr%r r!r"r#r$Nr))r'�staterrr
�__setstate__�s





zWorkDirs.__setstate__N)rr	r
rr(r*r,rrrr
r�s
	rcCstt|��S)z�
    Returns a WorkDirs instance based on the given root.

    :param root: The desired root of relenv's working directories
    :type root: str

    :return: A WorkDirs instance based on the given root
    :rtype: ``relenv.common.WorkDirs``
    )rr)rrrr
�	work_dirs�s
r-cCs"t|�}|r|jd�|�S|jS)aF
    Get a the toolchain directory, specific to the arch if supplied.

    :param arch: The architecture to get the toolchain for
    :type arch: str
    :param root: The root of the relenv working directories to search in
    :type root: str

    :return: The directory holding the toolchain
    :rtype: ``pathlib.Path``
    z{}-linux-gnu)r-r r)�archr�dirsrrr
�
get_toolchain�sr0cCsX|stj}|s
t�}|dkr|�d�S|dkr|�d�S|dkr%|�d�Std|����)a�
    Get the target triplet for the specified machine and platform.

    If any of the args are None, it will try to deduce what they should be.

    :param machine: The machine for the triplet
    :type machine: str
    :param plat: The platform for the triplet
    :type plat: str

    :raises RelenvException: If the platform is unknown

    :return: The target triplet
    :rtype: str
    rz-macosrz-winrz
-linux-gnuzUnknown platform )�sysrrr)r�platrrr
�get_triplet�s


r3cCs2|dkrdS|dkrdS|dkrdStd|����)zC
    Convert platform from build to the value of sys.platform.
    z	linux-gnurZmacosr�winrzUnkown platform )r)r2rrr
�plat_from_tripletsr5c	Csxg}tt�}t�|j�D]-\}}}|D]%}|�d�r8|dd�}|�dd�\}}|�dd�\}}|�|||f�qq|S)zJ
    Return a list of version, architecture and platforms for builds.
    �.tar.xzNi�����-�)r-r&�os�walkr!�endswith�split�append)	Zbuildsr/r�files�file�version�tripletr.r2rrr
�list_archived_buildss
��rBcCs&|st�}tt�}|�d�}|j|S)z�
    Finds a the location of an archived build.

    :param triplet: The build triplet to find
    :type triplet: str

    :return: The location of the archived build
    :rtype: ``pathlib.Path``
    r6)r3r-r&r!)rAr/�archiverrr
�archived_build$s



rDcCsp|�d�rd}n|�d�rd}n
|�d�rd}nd}t�||��}|�|�Wd�dS1s1wYdS)	z�
    Extract an archive to a specific location.

    :param to_dir: The directory to extract to
    :type to_dir: str
    :param archive: The archive to extract
    :type archive: str
    Ztgzzr:gz�xzzr:xz�bz2zr:bz2�rN)r;�tarfile�open�
extractall)Zto_dirrCZ	read_type�trrr
�extract_archive5s
	

"�rLcCstj�|tj�|��S)a
    Get the full path to where the url will be downloaded to.

    :param url: The url to donwload
    :type url: str
    :param dest: Where to download the url to
    :type dest: str

    :return: The path to where the url will be downloaded to
    :rtype: str
    )r9�path�join�basename)�url�destrrr
�get_download_locationJsrR�cCslddl}d}z'z
|jj||d�}Wnty$YW|r"|��dSdSwW|r,|��dS|r5|��ww)z+
    Check that the url returns a 200.
    rN��timeoutFT)�urllib.request�request�urlopen�	Exception�close)rPrU�urllib�finrrr
�	check_urlYs"����
�r]�c
CsRddl}ddl}t��}|dkrd}d}||kra|d7}z
|jj||d�}Wn6|jj|jjtj	j
fy\}z!||krEtd|�d|����t�
d|�t�|d�WYd}~nd}~ww||kst�d	|�z4d}	d
}
|�|
�}|r�|	|
7}	t��|dkr�t�d||	�t��}|�|�|�d�}|ssW|��n|��wt�d
|�dS)zn
    Fetch the contents of a url.

    This method will store the contents in the given file like object.
    rNr8rTzError fetching url � zUnable to connect %s�
z
url opened %si�z%s > %di(zDownload complete %s)Zurllib.errorrV�timerWrX�errorZ	HTTPErrorZURLError�httpZclientZRemoteDisconnectedr�log�debug�sleep�info�read�writerZ)rP�fp�backoffrUr[�last�nr\�exc�total�size�blockrrr
�	fetch_urlksL����



��rrT�<cCs�t||�}|rtd|�d|���t|d�}z
t||||�W|StyM}z!|r8td|�d|��tjdd�zt�|�W�t	yHY�wd}~ww)	a�
    Download the url to the provided destination.

    This method assumes the last part of the url is a filename. (https://foo.com/bar/myfile.tar.xz)

    :param url: The url to download
    :type url: str
    :param dest: Where to download the url to
    :type dest: str
    :param verbose: Print download url and destination to stdout
    :type verbose: bool

    :raises urllib.error.HTTPError: If the url was unable to be downloaded

    :return: The path to the downloaded content
    :rtype: str
    zDownloading z -> �wbzUnable to download: r_T)r?�flushN)
rR�printrIrrrYr1�stderrr9�unlink�OSError)rPrQ�verboserkrU�localZfoutrnrrr
�download_url�s&

	�����r|cOst�dd�|d��tj|d<tj|d<d|vrd|d<tjdkrutj|i|��}t�	�}|�
|jtj�|�
|j
tj�d}|rt|��D]+\}}|j��}|sUd	}n|�d
�r`|dd�}|j|jurlt�|�qFt�|�qF|sBnyd
d�}dd�}	tj|i|��}t��}
tj||j|
dfd�}tj||j
|
dfd�}tj|	||
fd�}
|��|��|
��	|
��\}}|dkr�t�|dd��n|dkr�t�|dd��n
|dkr�t�d�nq�|
��|��|��|��|jdk�rtd�d�|d����|S)aV
    Run a command.

    Run the provided command, raising an Exception when the command finishes
    with a non zero exit code.  Arguments are passed through to ``subprocess.run``

    :return: The process result
    :rtype: ``subprocess.CompletedProcess``

    :raises RelenvException: If the command finishes with a non zero exit code
    zRunning command: %sr_r�stdoutrw�universal_newlinesTrF�
N���cSsXt�}t|j|�D]}||us|dkrn
|r|�||f�q	t�d||�|��dS)N�zstream close %r %r)�object�iter�readline�putrdrerZ)�stream�queue�typeZNOOP�linerrr
�enqueue_stream�s�zruncmd.<locals>.enqueue_streamcSs|��|�d�dS)N)�xr�)�waitr�)�processr�rrr
�enqueue_process�szruncmd.<locals>.enqueue_processr8)�target�args�r�zprocess queue endzBuild cmd '{}' failed)rdrerN�
subprocess�PIPEr1r�Popen�	selectors�DefaultSelector�registerr}�
EVENT_READrw�select�fileobjr�r;rgrbr�ZQueue�	threading�Thread�start�getr��
returncoderr)r��kwargs�pZsel�ok�keyZval1r�r�r��q�toZte�tp�kindrrr
�runcmd�sf




��

�
r�cCs�t�|�}t�|�}t�|�}z|�|�}Wnty!td��wztjdd�|�|�jD��}W||Sty@td��w)zM
    Return a relativized path to the given scripts_dir and interpreter.
    z$interperter not relative to root_dircss�|]}dVqdS)z..Nr)�.0r�rrr
�	<genexpr>s�z'relative_interpreter.<locals>.<genexpr>z$scripts_dir not relative to root_dir)rr�relative_to�
ValueError�parts)�root_dirZscripts_dir�interpreter�scriptsZinterprZ	relinterpZ
relscriptsrrr
�relative_interpreters


���r�c
Cs�g}tt�tj���t�tj���h�}|D]%}|D] }zt�|���}|�|�|�t	|��Wqt
y:YqwqdtjvrRtjd�
tj�D]}|�|�qJ|S)zW
    Sanitize `sys.path` to only include paths relative to the onedir environment.
    Z
PYTHONPATH)�tuplerrr1�prefixr�base_prefixr�r=�strr�r9�environr<�pathsep)Zsys_path_entriesZ
__sys_pathZ__valid_path_prefixesZ__pathZ__valid_path_prefixZ__resolved_pathrrr
�sanitize_sys_path"s(��
��
r�)N)NN)rS)r^rS)Tr^rs)<rZhttp.clientrcZloggingr9rrr�r�r�r1rH�textwrapr�ra�__version__r�__file__r�parentrZLINUXZWIN32ZDARWINZMACOS_DEVELOPMENT_TARGETZCHECK_HOSTSZarches�homeZDEFAULT_DATA_DIRr�r�r&�dedentZSHEBANG_TPL_LINUXZSHEBANG_TPL_MACOSZSHEBANG_TPLZ	getLoggerrrdrYrrrrrrr-r0r3r5rBrDrLrRr]rrr|r�r�r�rrrr
�<module>sv�
��




1





-#U