U ��.e:�@s�ddlZddlZddlZddlmZddlmZmZddlm Z m Z m Z ddl m Z ddlmZmZe�e�ZGdd�de�ZdS) �N)�Command)�ERROR�SUCCESS)� Configuration�get_configuration_files�kinds)�PipError)�get_prog� write_outputcsxeZdZdZdZdZ�fdd�Zdd�Zdd �Zd d �Z d d �Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�Z�ZS)�ConfigurationCommanda9Manage local and global configuration. Subcommands: list: List the active configuration (or from the file specified) edit: Edit the configuration file in an editor get: Get the value associated with name set: Set the name=value unset: Unset the value associated with name If none of --user, --global and --site are passed, a virtual environment configuration file is used if one is active and the file exists. Otherwise, all modifications happen on the to the user file by default. Tz� %prog [] list %prog [] [--editor ] edit %prog [] get name %prog [] set name value %prog [] unset name cs�tt|�j||�d|_|jjdddddd�|jjdddd d d�|jjd d dd d d�|jjdddd dd�|j�d|j�dS)Nz--editor�editorZstorez\Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.)�dest�action�default�helpz--global� global_file� store_trueFz+Use the system-wide configuration file onlyz--user� user_filez$Use the user configuration file onlyz--site� site_filez3Use the current environment configuration file onlyr)�superr �__init__� configurationZcmd_optsZ add_option�parserZinsert_option_group)�self�args�kwargs�� __class__��H/usr/lib/python3.8/site-packages/pip/_internal/commands/configuration.pyr0s>� ���zConfigurationCommand.__init__c Cs|j|j|j|j|jd�}|r*|d|krHt�d�d�t |����t S|d}z|j ||dkd�}Wn:t k r�}zt�|j d�t WY�Sd}~XYnXt|j|d�|_|j��z||||dd��Wn<t k �r}zt�|j d�t WY�Sd}~XYnXtS) N)�list�edit�get�set�unsetrzNeed an action ({}) to perform.z, )r"r#r$r!)� need_value)�isolated� load_only�)� list_values�open_in_editor�get_name�set_name_value� unset_name�logger�error�format�join�sortedr�_determine_filerrrZ isolated_moder�loadr)r�optionsrZhandlersrr'�errr�runZs>�  �� � zConfigurationCommand.runcCs�dd�tj|jftj|jftj|jffD�}|s`|s8dStdd�t�tjD��rXtjStjSnt |�dkrt|dSt d��dS)NcSsg|]\}}|r|�qSrr)�.0�key�valuerrr� �s�z8ConfigurationCommand._determine_file..css|]}tj�|�VqdS)N)�os�path�exists)r8Zsite_config_filerrr� �s�z7ConfigurationCommand._determine_file..r(rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) rZUSERrZGLOBALrZSITEr�anyr�lenr)rr5r%Z file_optionsrrrr3�s$   � � �z$ConfigurationCommand._determine_filecCs8|j|ddd�t|j���D]\}}td||�qdS)Nr r��nz%s=%r)� _get_n_argsr2r�itemsr �rr5rr9r:rrrr)�sz ConfigurationCommand.list_valuescCs*|j|ddd�}|j�|�}td|�dS)Nz get [name]r(rBz%s)rDrZ get_valuer rFrrrr+�s zConfigurationCommand.get_namecCs.|j|ddd�\}}|j�||�|��dS)Nzset [name] [value]�rB)rDrZ set_value�_save_configurationrFrrrr,�sz#ConfigurationCommand.set_name_valuecCs(|j|ddd�}|j�|�|��dS)Nz unset [name]r(rB)rDrZ unset_valuerH)rr5rr9rrrr-�s zConfigurationCommand.unset_namec Csp|�|�}|j��}|dkr$td��zt�||g�Wn4tjk rj}ztd�|j���W5d}~XYnXdS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) �_determine_editorrZget_file_to_editr� subprocessZ check_callZCalledProcessErrorr0� returncode)rr5rr Zfnamer6rrrr*�s  ��z#ConfigurationCommand.open_in_editorcCs<t|�|kr$d�|t�|�}t|��|dkr4|dS|SdS)zJHelper to make sure the command got the right number of arguments zJGot unexpected number of arguments, expected {}. (example: "{} config {}")r(rN)rAr0r r)rrZexamplerC�msgrrrrD�s ��z ConfigurationCommand._get_n_argscCs>z|j��Wn*tk r8tjddd�td��YnXdS)Nz:Unable to save configuration. Please report this as a bug.r()�exc_infozInternal Error.)rZsave� Exceptionr.r/r)rrrrrH�s�z(ConfigurationCommand._save_configurationcCsD|jdk r|jSdtjkr$tjdSdtjkr8tjdStd��dS)NZVISUALZEDITORz"Could not determine editor to use.)r r<�environr)rr5rrrrI�s     z&ConfigurationCommand._determine_editor)�__name__� __module__� __qualname__�__doc__Zignore_require_venvZusagerr7r3r)r+r,r-r*rDrHrI� __classcell__rrrrr s *+ r )Zloggingr<rJZpip._internal.cli.base_commandrZpip._internal.cli.status_codesrrZpip._internal.configurationrrrZpip._internal.exceptionsrZpip._internal.utils.miscr r Z getLoggerrPr.r rrrr�s