a  ze#@sddlZddlZddlZddlmZddlmZmZmZddl m Z ddl m Z m Z ddlmZmZmZmZddlmZddlmZdd lmZmZeeZGd d d e ZdS) N)Values)AnyListOptional)Command)ERRORSUCCESS) ConfigurationKindget_configuration_fileskinds)PipError) indent_log)get_prog write_outputc@s*eZdZdZdZdZddddZeee e dd d Z ee e ed d d Zeee ddddZeee ddddZeee ddddZeee ddddZeee ddddZeddddZddddZeee ddddZee e e edd d!Zddd"d#Zee d$d%d&ZdS)'ConfigurationCommandah 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 - debug: List the configuration files and values defined under them 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. Ta %prog [] list %prog [] [--editor ] edit %prog [] get name %prog [] set name value %prog [] unset name %prog [] debug N)returncCsl|jjdddddd|jjdddd d d|jjd d dd d d|jjdddd dd|jd|jdS)Nz--editoreditorstorez\Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.)destactiondefaulthelpz--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)cmd_opts add_optionparserinsert_option_groupselfr#f/opt/bitninja-python-dojo/embedded/lib/python3.9/site-packages/pip/_internal/commands/configuration.py add_options4s: z ConfigurationCommand.add_options)optionsargsrc Cs|j|j|j|j|j|jd}|r.|d|vrHtddt |t S|d}z|j ||dvd}Wn8t y}z t|j dt WYd}~Sd}~00t|j|d|_|jz||||ddWn:t y}z t|j dt WYd}~Sd}~00tS) N)listeditgetsetunsetdebugrzNeed an action (%s) to perform.z, )r*r+r,r)) need_value)isolated load_only) list_valuesopen_in_editorget_nameset_name_value unset_namelist_config_valuesloggererrorjoinsortedr_determine_filer r'r isolated_mode configurationloadr)r"r&r'handlersrr0er#r#r$runZs>    zConfigurationCommand.run)r&r.rcCsddtj|jftj|jftj|jffD}|s`|s8dStddttjDrXtjStjSnt |dkrt|dSt ddS)NcSsg|]\}}|r|qSr#r#).0keyvaluer#r#r$ s z8ConfigurationCommand._determine_file..css|]}tj|VqdS)N)ospathexists)rCsite_config_filer#r#r$ sz7ConfigurationCommand._determine_file..r1rzLNeed exactly one file to operate upon (--user, --site, --global) to perform.) r USERrGLOBALrSITEranyr lenr )r"r&r.Z file_optionsr#r#r$r<s$     z$ConfigurationCommand._determine_filecCs8|j|dddt|jD]\}}td||qdS)Nr(rn%s=%r) _get_n_argsr;r>itemsrr"r&r'rDrEr#r#r$r2sz ConfigurationCommand.list_valuescCs*|j|ddd}|j|}td|dS)Nz get [name]r1rQz%s)rTr> get_valuerrVr#r#r$r4s zConfigurationCommand.get_namecCs.|j|ddd\}}|j|||dS)Nzset [name] [value]rQ)rTr> set_value_save_configurationrVr#r#r$r5sz#ConfigurationCommand.set_name_valuecCs(|j|ddd}|j||dS)Nz unset [name]r1rQ)rTr> unset_valuerZ)r"r&r'rDr#r#r$r6s zConfigurationCommand.unset_namec Cs|j|ddd|t|jD]h\}}td||D]P}t6tj |}td|||rn| |Wdq<1s0Yqiter_config_filesrrrGrHrIprint_config_file_values)r"r&r'variantfilesfnameZ file_existsr#r#r$r7s  z'ConfigurationCommand.list_config_values)r`rc CsP|j|D]:\}}ttd||Wdq1s@0YqdS)z.Get key-value pairs from the file of a variantz%s: %sN)r>get_values_in_configrUrr)r"r`namerEr#r#r$r_s z-ConfigurationCommand.print_config_file_valuescCsftddtBt|jD]"\}}d|}td||q Wdn1sX0YdS)z5Get key-values pairs present as environment variablesr\env_varPIP_rSN)rrr;r>get_environ_varsupper)r"rDrErer#r#r$r]s  z)ConfigurationCommand.print_env_var_valuesc Csr||}|j}|dur$tdzt||gWn6tjyl}ztd|jWYd}~n d}~00dS)Nz%Could not determine appropriate file.z*Editor Subprocess exited with exit code {}) _determine_editorr>get_file_to_editr subprocess check_callCalledProcessErrorformat returncode)r"r&r'rrbrAr#r#r$r3s  z#ConfigurationCommand.open_in_editor)r'examplerRrcCs<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 {}")r1rN)rPrnrr )r"r'rprRmsgr#r#r$rTs z ConfigurationCommand._get_n_argscCs8z|jWn$ty2tdtdYn0dS)Nz:Unable to save configuration. Please report this as a bug.zInternal Error.)r>save Exceptionr8 exceptionr r!r#r#r$rZs z(ConfigurationCommand._save_configuration)r&rcCsD|jdur|jSdtjvr$tjdSdtjvr8tjdStddS)NZVISUALZEDITORz"Could not determine editor to use.)rrGenvironr )r"r&r#r#r$ris     z&ConfigurationCommand._determine_editor)__name__ __module__ __qualname____doc__ignore_require_venvusager%rrstrintrBboolrr r<r2r4r5r6r7r_r]r3rrTrZrir#r#r#r$rs" &- r)loggingrGrkoptparsertypingrrrpip._internal.cli.base_commandrpip._internal.cli.status_codesrrpip._internal.configurationr r r r pip._internal.exceptionsr pip._internal.utils.loggingrpip._internal.utils.miscrr getLoggerrvr8rr#r#r#r$s