File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/thin.cpython-310.pyc
o
�N�gb � @ s d Z ddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlm mZ ddlZddlZddlZddlZddlZddlZdZ zddl!Z!dZ W n e"y� Y nw zddl#Z#W n e"y� dZ#Y nw zddl$Z$W n e"y� dZ$Y nw zddl%Z%W n e"y� dZ%Y nw zddl&Z&W n e"y� dZ&Y nw zddl'Z'W n e"y� ddl(m m'Z' Y nw zddl)Z)W n e"y� dZ)Y nw zddl*m+Z+ W n e"�y! zddl,m+Z+ W n e"�y dZ+Y nw Y nw dZ-e�.e/�Z0dd� Z1dd � Z2d
d� Z3dd
� Z4dd� Z5dd� Z6dd� Z7dd� Z8d/dd�Z9dd� Z:dd� Z;d0dd�Z<dd � Z=d!d"� Z>d#d$� Z? % d1d&d'�Z@d2d)d*�ZA d3d+d,�ZBd2d-d.�ZCdS )4z@
Generate the salt thin tarball from the installed python files
� NFT)�ssl_match_hostnamec C sj z t j�| |�}W n ty d}Y nw |dur3t j�|�}z |j�|� W |S ty2 Y dS w dS )z�
Import a module from a specific path. Path can be a full or relative path
to a .py file.
:name: The name of the module to import
:path: The path of the module to import
N)� importlib�util�spec_from_file_location�
ValueError�module_from_spec�loader�exec_module�OSError)�name�path�spec�lib� r �C/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/thin.py�
import_module^ s ����r c C sP t td�r t�� S tjD ]} tdtj�| d��}t |d�r#|�� S qtd��)a�
Some versions of Virtualenv ship a site.py without getsitepackages. This
method will first try and return sitepackages from the default site module
if no method exists we will try importing the site module from every other
path in sys.paths until we find a getsitepackages method to return the
results from. If for some reason no gesitepackages method can be found a
RuntimeError will be raised
:return: A list containing all global site-packages directories.
�getsitepackages�sitezsite.pyz)Unable to locate a getsitepackages method) �hasattrr r �sysr r �os�join�RuntimeError)r r r r r r t s
�r c C s� g }g }zt � }W n ty t�d� Y nw |D ],}tj�|| � d��}t| |�}|r2|�|� tj�|| d�}t| |�}|rF|�|� q|S )z�
Finds and imports a module from site packages directories.
:name: The name of the module to import
:return: A list of imported modules, if no modules are imported an empty
list is returned.
z!No site package directories found�.py�__init__.py) r r �log�debugr r r r �append)r ZlibsZ
site_pathsZ site_pathr r r r r �find_site_modules� s$
�
�r c O sB d}d| fd|ffD ]\}}|� |tjj�|��}q
tjj�|�S )a%
Return salt-call source, based on configuration.
This will include additional namespaces for another versions of Salt,
if needed (e.g. older interpreters etc).
:dirs: List of directories to include in the system path
:namespaces: Dictionary of namespace
:return:
a� # -*- coding: utf-8 -*-
import os
import sys
# Namespaces is a map: {namespace: major/minor version}, like {'2016.11.4': [2, 6]}
# Appears only when configured in Master configuration.
namespaces = %namespaces%
# Default system paths alongside the namespaces
syspaths = %dirs%
syspaths.append('py{0}'.format(sys.version_info[0]))
curr_ver = (sys.version_info[0], sys.version_info[1],)
namespace = ''
for ns in namespaces:
if curr_ver == tuple(namespaces[ns]):
namespace = ns
break
for base in syspaths:
sys.path.insert(0, os.path.join(os.path.dirname(__file__),
namespace and os.path.join(namespace, base) or base))
if __name__ == '__main__':
from salt.scripts import salt_call
salt_call()
z%dirs%z%namespaces%)�replace�salt�utils�json�dumps�stringutils�to_bytes)�dirs�
namespaces�templateZtgtZcntr r r �_get_salt_call� s
r) c C s t j�| dd�S )z-
Return the path to the thin tarball
�thinzthin.tgz)r r r )�cachedirr r r � thin_path� s r, c C s g d�}t j�| �|v S )zj
Return True if module is share-able between major Python versions.
:param mod:
:return:
)r �jinja2�msgpack�certifi)r r �basename)�modZ shareabler r r �
_is_shareable� s r2 c C sL t j�|j��d�d dkr| �t j�|j�� dS | �|j�dd�� dS )z]
Add a dependency to the top list.
:param obj:
:param is_file:
:return:
�.r �__init__�.pycr N)r r r0 �__file__�splitr �dirnamer )� container�objr r r �_add_dependency� s r; c C s4 t jj�tjd �} tdi | ��}t jjj|dd�S )z�
This function is called externally from the alternative
Python interpreter from within _get_tops function.
:param extra_mods:
:param so_mods:
:return:
� F)�ensure_asciiNr )r r! r"