U
ÀÒ.e: ã @ s‚ d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm Z m
Z
mZ d dlm
Z
d dlmZmZ e e¡ZG dd„ deƒZdS ) é N)ÚCommand)ÚERRORÚSUCCESS)Ú
ConfigurationÚget_configuration_filesÚkinds)ÚPipError)Úget_progÚwrite_outputc sx e Zd ZdZdZdZ‡ fdd„Zdd„ Zdd „ Zd
d„ Z dd
„ Z
dd„ Zdd„ Zdd„ Z
dd„ Zdd„ Zdd„ Z‡ ZS )ÚConfigurationCommanda9 Manage 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
c s„ t t| ƒj||Ž d | _| jjdddd dd� | jjdddd d
d� | jjdddd d
d� | jjdddd dd� | j d| j¡ d S )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.pyr 0 s> úûûûzConfigurationCommand.__init__c
C s | j | j| j| j| jdœ}|r*|d |krHt d d t |ƒ¡¡¡ t
S |d }z| j||dkd�}W n: tk
r } zt |j
d ¡ t
W Y ¢S d }~X Y nX t|j|d�| _| j ¡ z|| ||dd … ƒ W n< tk
�r } zt |j
d ¡ t
W Y ¢S d }~X Y nX tS ) N)ÚlistÚeditÚgetÚsetÚunsetr zNeed 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_filer r r Z
isolated_moder Úloadr )r Úoptionsr Zhandlersr r' Úer r r ÚrunZ s> û ÿ ÿ
ÿ
zConfigurationCommand.runc C s€ dd„ t j|jft j|jft j|jffD ƒ}|s`|s8d S tdd„ tƒ t j D ƒƒrXt jS t jS nt |ƒdkrt|d S t
dƒ‚d S )Nc S s g | ]\}}|r|‘qS r r )Ú.0ÚkeyÚvaluer r r Ú
† s üz8ConfigurationCommand._determine_file..c s s | ]}t j |¡V qd S )N)ÚosÚpathÚexists)r8 Zsite_config_filer r r Ú � s ÿz7ConfigurationCommand._determine_file..r( r zLNeed exactly one file to operate upon (--user, --site, --global) to perform.)r ZUSERr ZGLOBALr ZSITEr Úanyr Úlenr )r r5 r% Zfile_optionsr r r r3 … s$
ý
þÿz$ConfigurationCommand._determine_filec C s8 | j |ddd� t| j ¡ ƒD ]\}}td||ƒ qd S )Nr r ©Únz%s=%r)Ú_get_n_argsr2 r Úitemsr
©r r5 r r9 r: r r r r) Ÿ s z ConfigurationCommand.list_valuesc C s* | j |ddd�}| j |¡}td|ƒ d S )Nz
get [name]r( rB z%s)rD r Z get_valuer
rF r r r r+ ¥ s zConfigurationCommand.get_namec C s. | j |ddd�\}}| j ||¡ | ¡ d S )Nzset [name] [value]é rB )rD r Z set_valueÚ_save_configurationrF r r r r, « s z#ConfigurationCommand.set_name_valuec C s( | j |ddd�}| j |¡ | ¡ d S )Nzunset [name]r( rB )rD r Zunset_valuerH )r r5 r r9 r r r r- ± s zConfigurationCommand.unset_namec
C sp | |¡}| j ¡ }|d kr$tdƒ‚zt ||g¡ W n4 tjk
rj } ztd |j¡ƒ‚W 5 d }~X Y nX d S )Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) Ú_determine_editorr Zget_file_to_editr Ú
subprocessZ
check_callZCalledProcessErrorr0 Ú
returncode)r r5 r r Zfnamer6 r r r r* · s
ÿÿz#ConfigurationCommand.open_in_editorc C s<