
 X                 @   sU  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d l m Z m Z m Z m Z m Z d d l m Z d d	 l m Z m Z d d
 l m Z m Z m Z m Z m Z d d l  m! Z! d g Z" Gd d   d e#  Z$ d d d  Z% d d d  Z& d S)z(Base Command class, and related routines    N)
cmdoptions)running_under_virtualenv)logger)
PipSession)
BadCommandInstallationErrorUninstallationErrorCommandErrorPreviousBuildDirError)StringIO)ConfigOptionParserUpdatingDefaultsHelpFormatter)SUCCESSERRORUNKNOWN_ERRORVIRTUALENV_NOT_FOUNDPREVIOUS_BUILD_DIR_ERROR)get_progCommandc               @   s^   e  Z d  Z d Z d Z d Z d d   Z d d   Z d d   Z d	 d
   Z	 d d   Z
 d S)r   NFc             C   s   i |  j  d 6d t   |  j f d 6t   d 6d d 6|  j d 6|  j d 6} t |   |  _ d	 |  j j   } t j	 |  j |  |  _
 t j t j |  j  } |  j j |  d  S)
Nusagez%s %sprog	formatterFadd_help_optionnamedescriptionz
%s Options)r   r   r   r   __doc__r   parser
capitalizeoptparseOptionGroupcmd_optsr   make_option_groupgeneral_groupadd_option_group)self	parser_kwoptgroup_namegen_opts r(   :/home/ubuntu/projects/ifolica/build/pip/pip/basecommand.py__init__   s    


zCommand.__init__c             C   sv   t    } | j r! | j | _ n  | j r9 | j | _ n  | j rb i | j d 6| j d 6| _ n  | j | j _ | S)Nhttphttps)	r   certverifytimeoutproxyproxiesno_inputauth	prompting)r$   optionssessionr(   r(   r)   _build_session3   s    				
zCommand._build_sessionc             C   s   d  S)Nr(   )r$   r(   r(   r)   setup_loggingJ   s    zCommand.setup_loggingc             C   s   |  j  j |  S)N)r   
parse_args)r$   argsr(   r(   r)   r9   M   s    zCommand.parse_argsc             C   s  |  j  |  \ } } d } | | j 7} | | j 8} t j d |  } g  } t j | t j f t j | j	 f  | j
 r d t _ n  |  j   | j r d t j d <n  | j r d j | j  t j d <n  | j rt   st j d  t j t  qn  | j r6t | j d	  } t j t j | f  n d  } t } d
 } y. |  j | |  } t | t  ru| } n  Wnt k
 rt j   d }	 t j t |	   t j  d t!    d } t" } Yn`t# t$ f k
 r't j   d }	 t j t |	   t j  d t!    d } t% } Ynt& k
 r{t j   d }	 t j t |	   t j  d t!    d } t% } Yn t' k
 rt j   d }	 t j d |	  t j  d t!    t% } Ynf t( k
 rt j d  t j  d t!    d } t% } Yn( t j d t!    d } t) } Yn X| r| j* }
 d j |  } y t |
 d  } Wn< t+ k
 rt, j- d d
  } | j. }
 t |
 d  } Yn Xt j d |
  | j/ |  | j0   n  | d  k	 r| j0   n  | S)N      T1PIP_NO_INPUT PIP_EXISTS_ACTIONz2Could not find an activated virtualenv (required).aFzException information:
%sz	ERROR: %szOperation cancelled by userzException:
%s
wdeletez#Storing debug log for failure in %s)1r9   verbosequietr   level_for_integeradd_consumerssysstdoutDEBUGappendlog_explicit_levelsexplicit_levelsr8   r2   osenvironexists_actionjoinrequire_venvr   fatalexitr   logopen_logfiler   run
isinstanceintr
   exc_infostrinfo
format_excr   r   r   r   r   r	   KeyboardInterruptr   log_fileIOErrortempfileNamedTemporaryFiler   writeclose)r$   r:   r5   levelcomplete_loglog_fprU   	store_logstatuselog_file_fntextlog_file_fptempr(   r(   r)   mainQ   s    	
					




		zCommand.main)__name__
__module____qualname__r   r   hiddenr*   r7   r8   r9   rp   r(   r(   r(   r)   r      s   c             C   sG   |  d  k r t  j   }  n  t   } t j |  t d |    | j   S)Nfile)rI   r[   r   	tracebackprint_exceptiondictgetvalue)r[   outr(   r(   r)   r^      s
    	r^   rA   c             C   s   t  j j |   }  t  j j |   }  t  j j |   } t  j j |  sX t  j |  n  t  j j |   } t |  |  } | r | j d d d  | j d t	 j
 d t j d  f  n  | S)zOpen the named log file in append mode.

    If the file already exists, a separator will also be printed to
    the file to separate past activity from current activity.
    z%s
-<   z%s run on %s
r   z%c)rO   path
expanduserabspathdirnameexistsmakedirsopenrd   rI   argvtimestrftime)filenamemoder   r   rh   r(   r(   r)   rW      s    *rW   )'r   rO   rI   rb   rv   r   r   pipr   pip.locationsr   pip.logr   pip.downloadr   pip.exceptionsr   r   r   r	   r
   Zpip.backwardcompatr   pip.baseparserr   r   pip.status_codesr   r   r   r   r   pip.utilr   __all__objectr   r^   rW   r(   r(   r(   r)   <module>   s&   ((	