MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: erhabenn (1009)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //lib/mysqlsh/python-packages/mysqlsh/plugin_manager/__pycache__/repositories.cpython-39.pyc
a

��kfk6�@s�ddlZddlZddlZddlmZmZddlmZddddd	�gZ	d
d�Z
dd
d�Zddd�Zed�dd��Z
ed�ddd��Zdd�Zed�dd��ZdS)�N)�plugin�plugin_function�)�generalz&Official MySQL Shell Plugin RepositoryzRThe official MySQL Shell Plugin Repository maintained by the MySQL Team at Oracle.z6https://cdn.mysql.com/mysql_shell/plugins_manifest.zipz*manifest/mysql-shell-plugins-manifest.json)�name�description�urlZmanifestPathcCsXd}d}|D]F}||d�d|�dd��d|�dd	��d|�d
d��d�7}|d7}q|S)z�Returns a formatted list of repositories.

    Args:
        repositories (list): A list of repositories.

    Returns:
        The formated list as string
    �rz>4� rz??z
     r�-rz

��get)�repositories�out�i�r�r�G/usr/lib/mysqlsh/python-packages/mysqlsh/plugin_manager/repositories.py�format_repository_listing.s	
�
�

rFcCstj�t��d�}tj�|��r�z@t|d�� }t�|��	d�}Wd�n1sR0Y|WStj
y�}z>td|�dt|j
��d|j�d|j���|r��WYd}~dSd}~0t�y�}z*td	|�dt|����|r�WYd}~n
d}~00ngSdS)
z�Fetches the registered user repositories

    Args:
        raise_exceptions (bool): Whether exceptions are raised

    Returns:
        The registered repositories as list
    �plugin-repositories.jsonrrNz"ERROR: Could not parse JSON file '�'.
�, line: �, col: zERROR: Error reading file ')�os�path�joinr�get_shell_user_dir�isfile�open�json�loadr
�JSONDecodeError�print�str�msg�lineno�colno�OSError)�raise_exceptions�user_repo_file_path�user_repo_file�
user_repos�errr�get_user_repositoriesBs8	�.����
�r-c
Cs�dd|d�}tj�t��d�}z@t|d�� }tj||dd�Wd�n1sP0YWd	Sty�}z,t	d
|�dt
|����|r��WYd}~dSd}~00dS)
z�Stores the registered user repositories

    Args:
        user_repos (list): The list of
        raise_exceptions (bool): Whether exceptions are raised

    Returns:
        True on success
    zMySQL Shell Plugin Repositoriesz0.0.1)ZfileType�versionrr�w�)�indentNTzERROR: Error writing to file 'rF)rrrrrrr�dumpr'r"r#)r+r(Zuser_repo_file_contentr)r*r,rrr�set_user_repositoriescs$��.
�r3zplugins.repositories.listcKsz|�dd�}|�dd�}t��}t|d�}|r8|�|�|s@|Stdt|d��dt|��d	t|�d
krjdnd�d
��dS)a�Lists all registered plugin repositories

    This function will list all registered MySQL Shell plugin repositories.
    To add a repository use the plugins.repositories.add() function.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        return_formatted (bool): If set to true, a list object is returned.
        raise_exceptions (bool): Whether exceptions are raised

    Returns:
        None or a list of dicts representing the plugins
    �return_formattedTr(F�r(z-Registered MySQL Shell Plugin Repositories.

)rz	Total of z
 repositorr�yZiesz.
N)r
�DEFAULT_PLUGIN_REPOSITORIES�copyr-�extendr"r�len)�kwargsr4r(Zreposr+rrr�get_plugin_repositories�s

���r<zplugins.repositories.addcKs|�dd�}|�dd�}|s@|r@td�tjj�dddi���}|sPtd�d	S|���d
�r�|�	d�}t
|�dkr�td
�d	S|d}t
|�dkr�d}n|d}d|�d|�d�}nH|�d�s�|�d�s�d|��}|�d�s�|�d�r�|�d�}n
|�d�}�z�t�
|�}|�sWd	St�|�}|�d�}	|	�d�}
|
�sJtd�Wd	S|	�d�}|
�shtd�Wd	S|�d�}|�r�t
|�dk�r�td�Wd	Std�td �d!|
�d"d#�d!|�d$|�d%�
�|D]}
td&|
�d'��d"���q�tjj�d(|
�d)�dd*i�����}|d+k�r td,�Wd	Std-�t|d.�}|d	u�rBWd	S|D]6}|�d/���|��k�rFtd0|
�d1��Wd	S�qFtd2|
�d3��|�|
||d4��t|��r�td5|
�d6��WnVtj�y}z:td7t|j��d8|j�d9|j���|�r��WYd	}~d	Sd	}~00d	S):aeAdds a new plugin repository

    By calling this function a new plugin repository can be added. The url
    parameter allows for shortcuts.

    'domain.com' expands to https://domain.com/mysql-shell-plugins-manifest.json
    'domain.com/plugins' expands to https://domain.com/plugins/mysql-shell-plugins-manifest.json
    'github/username' expands to https://raw.githubusercontent.com/username/mysql-shell-plugins/master/mysql-shell-plugins-manifest.json
    'github/username/repo' expands to https://raw.githubusercontent.com/username/repo/master/mysql-shell-plugins-manifest.json

    Args:
        url (str): The url of a MySQL Shell plugins repository.
        **kwargs: Optional parameters

    Keyword Args:
        interactive (bool): Whether user input is accepted
        raise_exceptions (bool): Whether exceptions are raised

    Returns:
        None
    �interactiveTr(z�To add a new MySQL Shell plugin repository the URL of the repository manifest file
needs to be specified.

Examples:
    domain.com
    domain.com/plugins
    github/username
    github/username/repository
z/Please enter the URL of the plugin repository: ZdefaultValuer	z"No URL given. Cancelling OperationNzgithub/�/rz#A github user needs to be specified�zmysql-shell-pluginsz"https://raw.githubusercontent.com/z)/master/mysql-shell-plugins-manifest.jsonzhttps://zhttp://z.jsonz!mysql-shell-plugins-manifest.jsonz"/mysql-shell-plugins-manifest.json�
repositoryrz0The given repository misses the 'name' property.rz7The given repository misses the 'description' property.�pluginsrzAThe repository does not contain any plugins. Operation cancelled.a�
WARNING:
You are about to add an external MySQL Shell plugin repository.
External plugin repositories and their plugins complement
the functionality of MySQL Shell and can contain system
level software that could be potentially harmful to your
system. Please review the description below and only proceed
if you have obtained the external plugin repository URL from
a trusted source.

Oracle and its affiliates cannot be held responsible for
any potential harm caused by using plugins from external sources.
zRepository :r
�
zDescription:z
URL: z1

The repository contains the following plugins:
z  - Zcaptionz-Are you sure you want to add the repository 'z' [yes/NO]: �no�yeszOperation cancelled.z%Fetching current user repositories...r5r�The repository 'z' has already been added.
zAdding repository '�'...)rrrzRepository 'z' successfully added.
z"ERROR: Could not parse JSON file. rr)r
r"�mysqlsh�globals�shell�prompt�strip�lower�
startswith�splitr:�endswithr�
download_filer�loadsr-�appendr3r!r#r$r%r&)rr;r=r(Z
github_strZgithub_userZgithub_repoZmanifestZmanifest_contentr@rrrArrJr+rr,rrr�add_plugin_repository�s���
�










���

��


�
��rScCs@d}d}|D]"}|�d�|kr&d}q0|d7}q|r8|SdSdS)NrFrTrr)rr+�nr�foundrrrr�search_user_repoDs
rVzplugins.repositories.removec	Ks�|�d�}|�dd�}|�dd�}t|d�}|s<td�dSd}|rft||�}|durftd	|�d
��|du�r<|�r<tdt|����|du�r<tjj�d��	�}|�r<z`z.t
|�}|d
kr�|t|�kr�|d}nt�Wn,t
�yt||�}|du�rt
�Yn0Wn(t
tf�y2td|�d��Yn0q��q<q�|du�rPtd�n8||�dd�}td|�d��||=t|��r�td�dS)a�Removes a registered plugin repository

    This function will remove a shell plugin repository previously registered.

    Args:
        **kwargs: Optional parameters

    Keyword Args:
        url (str): The url of a MySQL Shell plugins repository.
        interactive (bool): Whether user input is accepted
        raise_exceptions (bool): Whether exceptions are raised

    Returns:
        None
    rr=Tr(Fr5z6No custom MySQL Shell plugin repositories registered.
NzNo user repository matches '�'zRemoving a plugin repository.

z/Please enter the index or URL of a repository: rrrEzJ' was not found. Please try again or leave empty to cancel the operation.
z,No valid URL provided. Cancelling operation.r	z
Removing repository 'rFz!Repository successfully removed.
)r
r-r"rVrrGrHrIrJrK�intr:�
IndexError�
ValueErrorr3)r;rr=r(r+Z
repo_indexrJrTrrr�remove_plugin_repositoryTsR


�
�





r[)F)F)N)�os.pathrrrG�mysqlsh.plugin_managerrrr	rr7rr-r3r<rSrVr[rrrr�<module>s(�

!
 
%