%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceWSL.cpython-312.pyc

�

�f� ��@�dZddlZddlZddlmZddlmZmZddlm	Z	m
Z
mZeje
�ZdZdedefd	�Zdefd
�Zdeefd�Zdedefd�Zdefd
�Zdefd�Zdeefd�ZdZdededefd�ZGd�de	j6�Zee	j:ffgZd�Zy)zA Datasource to support the Windows Subsystem for Linux platform. �N)�PurePath)�List�cast)�sources�subp�utilz/usr/bin/wslpath�path�returnc�r�tjtd|g�\}}t|j��S)a@
    Translates a path inside the current WSL instance's filesystem to a
    Windows accessible path.

    Example:
    # Running under an instance named "CoolInstance"
    root = wslpath2win("/") # root == "//wsl.localhost/CoolInstance/"

    :param path: string representing a Linux path, whether existing or not.
    z-am�r�WSLPATH_CMDr�rstrip�r	�out�_s   �A/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceWSL.py�wsl_path_2_winrs.���Y�Y��U�D�1�
2�F�C���C�J�J�L�!�!�c�0�td�}|jS)zL
    Returns the name of the current WSL instance as seen from outside.
    �/)r�name)�
root_net_paths r�
instance_namer#s��#�3�'�M����rc��d}d}g}tj�j�D]'}|d|k(s�||dvs�|j|d��)|S)z�
    Return a list of mount points of the Windows drives inside the current
    WSL instance, if drives are mounted, or an empty list otherwise
    �9pzaname=drvfs�fstype�opts�
mountpoint)r�mounts�values�append)�FS_TYPE�OPTIONS_CONTAIN�mounted�mnts    r�mounted_win_drivesr&+s`��
�G�#�O��G��{�{�}�#�#�%�.���x�=�G�#��3�v�;�(F��N�N�3�|�,�-�.��Nrc�r�tjtd|g�\}}t|j��S)a_
    Returns a translation of a Windows path to a Linux path that can be
    accessed inside the current instance filesystem.

    It requires the Windows drive mounting feature to be enabled and the
    disk drive must be muonted for this to succeed.

    Example:
    # Assuming Windows drives are mounted under /mnt/ and "S:" doesn't exist:
    p = winpath2wsl("C:\ProgramData") # p == "/mnt/c/ProgramData/"
    n = winpath2wsl("S:\CoolFolder") # Exception! S: is not mounted.

    :param path: string representing a Windows path. The root drive must exist,
    although the path is not required to.
    z-aurrs   r�win_path_2_wslr(;s.�� �Y�Y��U�D�1�
2�F�C���C�J�J�L�!�!rc��t�}|std��d}|D]N}||z}tj|tj�s�-t
j
d|�t|�cStddj|�z��)z?
    Returns the Linux path to the Windows host's cmd.exe.
    zWindows drives are not mounted.z%s/Windows/System32/cmd.exezFound cmd.exe at <%s>z,Couldn't find cmd.exe in any mount point: %sz, )	r&�IOError�os�access�X_OK�LOG�debugr�join)r�	candidater%�cmds    r�cmd_executabler3Os���
 �
!�F���7�8�8�.�I�����#�o���y�y��b�g�g�&���	�	�)�3�/���}��
��6����6�9J�J��rc�~�t�}tjd|j�ddg�\}}|j�}|stjd��t|�}tjj|d�}tjj|�std|z��t|�S)z
    Returns the Windows user profile directory translated as a Linux path
    accessible inside the current WSL instance.
    z/initz/Czecho %USERPROFILE%z4No output from cmd.exe to show the user profile dir.z.cloud-initz%s directory doesn't exist.)r3r�as_posixr�ProcessExecutionErrorr(r+r	r0�isdir�FileNotFoundErrorr)r2�homer�win_profile_dir�seed_dirs     r�cloud_init_data_dirr<gs���
�
�C��i�i��#�,�,�.�$�8L�M�N�G�D�!��;�;�=�D���(�(�B�
�	
�%�T�*�O��w�w�|�|�O�]�;�H�
�7�7�=�=��"�� =�� H�I�I��H��rc�b�tj�\}}}|r|n|}d|z|�d|�d�d|zdgS)z
    Return a list of candidate file names that may contain user-data
    in some supported format, ordered by precedence.
    z%s.user-data�-z
.user-dataz%s-all.user-datazdefault.user-data)r�get_linux_distro)r�distribution_id�
version_id�version_codename�versions     r�candidate_user_data_file_namesrD�sK��
59�4I�4I�4K�1�O�Z�!1�&�j�,<�G�	��&�,�g�6��_�,��	�	rziid-datasource-wsl�cloudinitdirrc�p�dti}tjj|j	�d|z�}	tjtj|��}|rd|vr(d|�d|��}tj|�t|��|S#t$rtjd|�Y�QwxYw)z`
    Returns the relevant metadata loaded from cloudinit dir based on the
    instance name
    �instance-idz%s.meta-dataz<No instance metadata found at %s. Using default instance-id.z
 Metadata at z5 does not contain instance-id key. Instead received: )
�DEFAULT_INSTANCE_IDr+r	r0r5r�	load_yaml�load_binary_filer8r.r/�error�
ValueError)rEr�metadata�
metadata_path�msgs     r�load_instance_metadatarP�s���
�2�3�H��G�G�L�L������-�!?��M�
��>�>�$�"7�"7�
�"F�G���}�H�4��M�?�+"�"*��
-�	�	�	�	�#����o���O���
��	�	�J��	
�
�s�(B�B5�4B5c�8�eZdZdZdedefd�Zdefd�Zdefd�Zy)�
DataSourceWSL�WSLr;r
c��tj|�D�cic]'}|jj�|j��)}}|std|z��t
|j�D�cgc]}|j���}}|D]$}||j�vs�t||�cStd|z��cc}wcc}w)z�
        Finds the most precendent of the candidate files that may contain
        user-data, if any, or None otherwise.
        z%s directory is emptyz6%s doesn't contain any of the expected user-data files)
r+�scandirr�casefoldr	r*rDr�keysr)�selfr;�ef�existing_files�f�folded_names�filenames       r�find_user_data_filez!DataSourceWSL.find_user_data_file�s���35�*�*�X�2F�
�,.�B�G�G�������'�
��
���1�H�<�=�=�4�D�4F�4F�G�
��
�J�J�L�
��
�%�	:�H��>�.�.�0�0���x� 8�9�9�	:��D�x�O�
�	
��
��
s�,B=�-Cc��|j�}|sy	tt�|j�}||j	d�k(S#t
tf$r)}tjdt|��Yd}~yd}~wwxYw)NFrGz2Unable to check_instance_id from metadata file: %s)
�get_instance_idrPr<r�getr*rLr.�warning�str)rX�sys_cfg�currentrM�errs     r�check_instance_idzDataSourceWSL.check_instance_id�s{���&�&�(����	�-�#�%�t�'9�'9��H��h�l�l�=�9�9�9����$�	��K�K�D��C��
���	�s�1A�A?�A:�:A?c��d|_t�}t�|_	t||j�|_|j|�}t
ttj|j���|_y#ttf$r)}tjdt|��Yd}~yd}~wwxYw)NTz"Unable to setup WSL datasource: %sF)�vendordata_rawr<rrPrMr^rrcrrJr5�userdata_rawrLr*r.rK)rXr;�filerfs    r�	_get_datazDataSourceWSL._get_data�s���"���&�(��*�_���	�2��$�,�,��D�M��+�+�H�5�D� $��T�*�*�4�=�=�?�;�!�D�����G�$�	��I�I�:�C��H�E���	�s�A"B�B=�B8�8B=N)	�__name__�
__module__�__qualname__�dsnamerr^�boolrgrl�rrrRrR�s2��
�F�
�H�
��
�<�D��(�4�rrRc�6�tj|t�S)N)r�list_from_depends�datasources)�dependss r�get_datasource_listrws���$�$�W�k�:�:r) �__doc__�loggingr+�pathlibr�typingrr�	cloudinitrrr�	getLoggerrmr.r
rcrrr&r(r3r<rDrH�dictrP�
DataSourcerR�DEP_FILESYSTEMrurwrrrr�<module>r�s���H��	���)�)��g����!�� ��"��"��"��s��
�D��I�
� "��"��"�(���0�X��4�T�#�Y��(+�����#��$��8F�G�&�&�F�V�W�+�+�-�.���;r

Zerion Mini Shell 1.0