File: //lib/mysqlsh/python-packages/mysqlsh/plugin_manager/__pycache__/general.cpython-39.pyc
a
��kf� � @ sz d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlm Z dZ
dZdd� Zdd� Z
d d
� Zddd
�Zdd� ZdS )� N��Pathz0.0.1�
c G s� dt jv rt jd }nHt�� }|s*td��t�� }|dkrPt j�|dddd�}nt j�|d�}zt|�j d d
� W n t
y� Y n0 | D ]}t j�||�}q�|S )z�Returns the MySQL Shell's user directory
The directory will be created if it does not exist yet
Args:
*argv: The list of directories to be added to the path
Returns:
The plugin directory path as string
ZMYSQLSH_USER_CONFIG_HOMEzNo home directory setZWindowsZAppDataZRoamingZMySQL�mysqlshz.mysqlshT��parents)�os�environr �home� Exception�platform�system�path�join�mkdir�FileExistsError)�argvZ shell_dirZhome_dir�os_name�arg� r �B/usr/lib/mysqlsh/python-packages/mysqlsh/plugin_manager/general.py�get_shell_user_dir( s$
�r c G sL t d�}zt|�jdd� W n ty. Y n0 | D ]}tj�||�}q4|S )z�Returns the MySQL Shell's temp directory
The directory will be created if it does not exist yet
Args:
*argv: The list of directories to be added to the path
Returns:
The temp directory path as string
ZtempTr )r r r r r r r )r Ztemp_dirr r r r �get_shell_temp_dirM s r c G s` ddl m} ddl}td�}z||�jdd� W n tyB Y n0 | D ]}|j�||�}qH|S )z�Returns the MySQL Shell's plugin directory
The directory will be created if it does not exist yet
Args:
*argv: The list of directories to be added to the path
Returns:
The plugin directory path as string
r r NZpluginsTr )�pathlibr Zos.pathr r r r r )r r r Zplugins_dirr r r r �get_plugins_dirf s r Fc
C s� z�t �� }|du r4|dkr4t| |dtjdd�d�W S tjj| t|d��}|� � }W d � n1 sd0 Y |s~|�
d�W S t|d ��}|�|� W d � n1 s�0 Y W dS W n� tj
j�y } zF|rւ |jd
k�rtd| � dt|�� �� W Y d}~dS � W Y d}~n�d}~0 tj
j�y� } ztt|j�} d
| v �rz|du �rzt� }
t| ||tj|
d�d�W Y d}~S td| � dt|�� �� |�r�� W Y d}~n
d}~0 0 dS )aj Downloads a file from a given URL
Args:
url (str): The URL to the text file to download
file_path (str): The file to store the downloaded file
raise_exceptions (bool): Whether exceptions are raised
Returns:
The contents of the file decoded to utf-8 if no file is given or True
on success or None on failure
NZDarwinTz/private/etc/ssl/cert.pem)�cafile)� file_path�raise_exceptions�ctx)Ztimeout�contextzutf-8�wbi� zCould not download file from z
ERROR: ZCERTIFICATE_VERIFY_FAILED)r r
�
download_file�sslZcreate_default_context�urllibZrequestZurlopen�URL_OPEN_TIMEOUT_SECONDS�read�decode�open�write�errorZ HTTPError�code�print�strZURLError�reason�install_ssl_certificates)Zurlr r r r Zresponse�dataZout_file�er- r r r r r! � sF
�&(
�r! c C s� t jt jB t jB t jB t jB t jB t jB t jB } t j
�t� d�}t
d� t j
�t�� �}t
d� zt �|� W n ty� Y n0 t
d� t �||� t
d� t �|| � t
d� |S )Nzcertifi-ca.pemzInstalling SSL certificate...z& -- removing any existing file or linkz2 -- creating symlink to certifi certificate bundlez -- setting permissionsz -- update complete)�stat�S_IRUSR�S_IWUSR�S_IXUSR�S_IRGRP�S_IWGRP�S_IXGRP�S_IROTH�S_IXOTHr r r r r+ �relpath�certifi�where�remove�FileNotFoundError�symlink�chmod)Z
STAT_0o775Zshell_cafileZrelpath_to_certifi_cafiler r r r. � s<