ó
b]c           @   sÏ   d  d l  Z  d  d l Z d  d l Z d  d l m Z d  d l m Z m Z d  d l m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z e  j e ƒ Z d	 e f d
 „  ƒ  YZ d S(   iÿÿÿÿN(   t   Command(   t   ERRORt   SUCCESS(   t   Configurationt   get_configuration_filest   kinds(   t   PipError(   t
   deprecated(   t   get_prog(   t   running_under_virtualenvt   ConfigurationCommandc           B   sƒ   e  Z d  Z d Z d Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s9  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.
    t   configsâ   
        %prog [<file-option>] list
        %prog [<file-option>] [--editor <editor-path>] edit

        %prog [<file-option>] get name
        %prog [<file-option>] set name value
        %prog [<file-option>] unset name
    s&   Manage local and global configuration.c      
   O   s  t  t |  ƒ j | | Ž  d  |  _ |  j j d d d d d d d  d d ƒ|  j j d	 d d
 d d d t d d ƒ|  j j d d d d d d t d d ƒ|  j j d d d d d d t d d ƒ|  j j d d d d d d t d d ƒ|  j j	 d |  j ƒ d  S(   Ns   --editort   destt   editort   actiont   storet   defaultt   helps\   Editor to use to edit the file. Uses VISUAL or EDITOR environment variables if not provided.s   --globalt   global_filet
   store_trues+   Use the system-wide configuration file onlys   --usert	   user_files$   Use the user configuration file onlys   --sitet	   site_files3   Use the current environment configuration file onlys   --venvt	   venv_filesY   [Deprecated] Use the current environment configuration file in a virtual environment onlyi    (
   t   superR
   t   __init__t   Nonet   configurationt   cmd_optst
   add_optiont   Falset   parsert   insert_option_group(   t   selft   argst   kwargs(    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR   /   sB    						c         C   s<  i |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6} | sO | d | k rx t j d j d j t	 | ƒ ƒ ƒ ƒ t
 S| d } y |  j | d	 | d k ƒ} Wn( t k
 rË } t j | j d ƒ t
 SXt d
 | j d | ƒ |  _ |  j j ƒ  y | | | | d ƒ Wn( t k
 r7} t j | j d ƒ t
 SXt S(   Nt   listt   editt   gett   sett   unseti    s   Need an action ({}) to perform.s   , t
   need_valuet   isolatedt	   load_onlyi   (   R%   R&   R'   R$   (   t   list_valuest   open_in_editort   get_namet   set_name_valuet
   unset_namet   loggert   errort   formatt   joint   sortedR   t   _determine_fileR   R!   R   t   isolated_modeR   t   loadR   (   R    t   optionsR!   t   handlersR   R*   t   e(    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyt   rund   s4    




c         C   s
  | j  rM | j rM t ƒ  r> t | _ t d d d d d ƒqM t d ƒ ‚ n  g  t j | j f t j	 | j
 f t j | j f f D] \ } } | r | ^ q } | sà | s¯ d  St d „  t ƒ  t j Dƒ ƒ rÖ t j St j Sn t | ƒ d k rú | d	 St d
 ƒ ‚ d  S(   Ns&   The --venv option has been deprecated.t   replacements   --sitet   gone_ins   19.3sH   Legacy --venv option requires a virtual environment. Use --site instead.c         s   s!   |  ] } t  j j | ƒ Vq d  S(   N(   t   ost   patht   exists(   t   .0t   site_config_file(    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pys	   <genexpr>ª   s   i   i    sL   Need exactly one file to operate upon (--user, --site, --global) to perform.(   R   R   R	   t   TrueR   R   R   t   USERR   t   GLOBALR   t   SITER   t   anyR   t   len(   R    R8   R(   t   keyt   valuet   file_options(    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR5      s4    		

c         C   sS   |  j  | d d d ƒx6 t |  j j ƒ  ƒ D] \ } } t j d | | ƒ q, Wd  S(   NR#   t   ni    s   %s=%r(   t   _get_n_argsR4   R   t   itemsR0   t   info(   R    R8   R!   RI   RJ   (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR+   ¸   s    "c         C   s>   |  j  | d d d ƒ} |  j j | ƒ } t j d | ƒ d  S(   Ns
   get [name]RL   i   s   %s(   RM   R   t	   get_valueR0   RO   (   R    R8   R!   RI   RJ   (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR-   ¾   s    c         C   s?   |  j  | d d d ƒ\ } } |  j j | | ƒ |  j ƒ  d  S(   Ns   set [name] [value]RL   i   (   RM   R   t	   set_valuet   _save_configuration(   R    R8   R!   RI   RJ   (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR.   Ä   s    c         C   s6   |  j  | d d d ƒ} |  j j | ƒ |  j ƒ  d  S(   Ns   unset [name]RL   i   (   RM   R   t   unset_valueRR   (   R    R8   R!   RI   (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR/   Ê   s    c         C   s…   |  j  | ƒ } |  j j ƒ  } | d  k r9 t d ƒ ‚ n  y t j | | g ƒ Wn. t j k
 r€ } t d j | j	 ƒ ƒ ‚ n Xd  S(   Ns%   Could not determine appropriate file.s*   Editor Subprocess exited with exit code {}(
   t   _determine_editorR   t   get_file_to_editR   R   t
   subprocesst
   check_callt   CalledProcessErrorR2   t
   returncode(   R    R8   R!   R   t   fnameR:   (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR,   Ð   s    c         C   sU   t  | ƒ | k r9 d j | t ƒ  | ƒ } t | ƒ ‚ n  | d k rM | d S| Sd S(   sJ   Helper to make sure the command got the right number of arguments
        sJ   Got unexpected number of arguments, expected {}. (example: "{} config {}")i   i    N(   RH   R2   R   R   (   R    R!   t   exampleRL   t   msg(    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyRM   ß   s    c         C   sH   y |  j  j ƒ  Wn0 t k
 rC t j d d d ƒt d ƒ ‚ n Xd  S(   Ns:   Unable to save configuration. Please report this as a bug.t   exc_infoi   s   Internal Error.(   R   t   savet	   ExceptionR0   R1   R   (   R    (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyRR   î   s    c         C   sZ   | j  d  k	 r | j  Sd t j k r0 t j d Sd t j k rJ t j d St d ƒ ‚ d  S(   Nt   VISUALt   EDITORs"   Could not determine editor to use.(   R   R   R>   t   environR   (   R    R8   (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyRT   ú   s    (   t   __name__t
   __module__t   __doc__t   namet   usaget   summaryR   R;   R5   R+   R-   R.   R/   R,   RM   RR   RT   (    (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyR
      s   	5	+	)							(   t   loggingR>   RV   t   pip._internal.cli.base_commandR    t   pip._internal.cli.status_codesR   R   t   pip._internal.configurationR   R   R   t   pip._internal.exceptionsR   t   pip._internal.utils.deprecationR   t   pip._internal.utils.miscR   t   pip._internal.utils.virtualenvR	   t	   getLoggerRc   R0   R
   (    (    (    sC   lib/python2.7/site-packages/pip/_internal/commands/configuration.pyt   <module>   s   