î
½1kd²  ã               @   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(   ú>/var/www/pythonscrapper/code/venv/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)z¯Open 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&   ((	–