ó
>ò†[c           @@ s  d  d l  m Z m Z m Z d  d l m Z m Z m Z m Z m	 Z	 m
 Z
 m Z d  d l m 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 y d  d l m Z Wn! e k
 rß d  d l m Z n Xd  d l m Z m Z d  d l m Z m Z d  d l m Z d	 d
 l  m! Z! m" Z" e j# d ƒ Z$ d „  Z% d „  Z& d e j' k re d d e j' d ƒ Z( e e( j) d ƒ Z* n e d d ƒ Z( e& d ƒ Z* i d d 6d d 6d d 6d d 6Z+ e( j, Z- e& d ƒ Z. e. Z/ d Z0 i i i e0 d 6d 6i e0 d 6d 6d 6e1 d 6d d  6e0 d 6e1 d! 6Z3 d d  d" d d d# d! g Z4 e( j5 d$ d% e( j) d& d' f Z6 d( „  Z7 d d d d d) „ Z8 d d d* „ Z9 e( j) e e e* ƒ d+ ƒ g Z: e: d, Z; d- „  Z< d. „  Z= d/ „  Z> d0 „  Z? d1 „  Z@ d d2 „ ZA d3 „  ZB e1 d4 „ ZC d S(5   i    (   t   print_functiont   absolute_importt   unicode_literals(   t   existst   joint   dirnamet   isfilet   isdirt   abspatht
   expanduser(   t   TemplateN(   t
   quote_plus(   t   CONDA_PREFIXt
   CONDA_ROOT(   t   AppDirst
   EnvAppDirs(   t   BinstarErrori   (   t	   yaml_loadt	   yaml_dumpu   binstarc         C@ s8   t  d t d t ƒ } | j t j ƒ t |  ƒ j |   S(   NR   R   (   t   dictR   R   t   updatet   ost   environR
   t   safe_substitute(   t   pathR   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt
   expandvars   s    c         C@ s   t  t t |  ƒ ƒ ƒ S(   N(   R   R	   R   (   R   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   expand"   s    u   BINSTAR_CONFIG_DIRu   ContinuumIOu   config.yamlu(   ~/.continuum/anaconda-client/config.yamlu   Environmentu   envu   Notebooku   ipynbu   Conda Packageu   condau   Python Packageu   pypiu+   $CONDA_ROOT/etc/anaconda-client/config.yamlu   https://api.anaconda.orgu   urlu   anacondau   sitesu   auto_registeru   default_siteu
   ssl_verifyu   upload_useru
   verify_sslu   /etc/anaconda-client/u    $CONDA_ROOT/etc/anaconda-client/u   ~/.continuum/anaconda-client/u"   $CONDA_PREFIX/etc/anaconda-client/c         C@ si   xb | j  ƒ  D]T \ } } t | t j ƒ rS t |  j | i  ƒ | ƒ } | |  | <q | | |  | <q W|  S(   N(   t   itemst
   isinstancet   collectionst   Mappingt   recursive_updatet   get(   t   configt   update_dictt
   update_keyt   updated_valuet   updated_value_dict(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyR   Z   s    c         K@ s  | s d d l  m } | } n  | d k	 r1 | n t d | ƒ } | j d t ƒ } t j d | ƒ |  rx t j d ƒ nd d t	 j
 k r¤ t j d ƒ t	 j
 d }  n8 d	 t	 j
 k rÐ t j d
 ƒ t	 j
 d	 }  n t | ƒ }  | j d | j d t ƒ ƒ } | |  d | d | | S(   u+   
    Get the anaconda server api class
    i    (   t   Binstart   siteu   urlu   Using Anaconda API: %su"   Using token from command line argsu   BINSTAR_API_TOKENu7   Using token from environment variable BINSTAR_API_TOKENu   ANACONDA_API_TOKENu8   Using token from environment variable ANACONDA_API_TOKENu
   ssl_verifyu
   verify_sslt   domaint   verifyN(   t   binstar_clientR&   t   Nonet
   get_configR    t   DEFAULT_URLt   loggert   infot   debugR   R   t
   load_tokent   True(   t   tokenR'   t   clsR!   t   kwargsR&   t   urlR)   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   get_server_apie   s"    	!c      	   C@ sn   t  j d t ƒ t |  d d	 ƒ } t |  d t j ƒ } t |  d d	 ƒ } t d | d | d | d | ƒ } | S(
   u6   
    DEPRECATED METHOD,

    use `get_server_api`
    u=   method get_binstar is deprecated, please use `get_server_api`u   tokenu	   log_levelu   siteR3   R'   t	   log_levelR4   N(   t   warningst   warnt   DeprecationWarningt   getattrR+   t   loggingt   INFOR7   (   t   argsR4   R3   R8   R'   t   aserver_api(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   get_binstarƒ   s    !u   tokensiÿÿÿÿc         C@ sÏ   t  d | o | j ƒ } x° t D]¨ } | j d t ƒ } t | ƒ sS t j | ƒ n  t | d t	 | ƒ ƒ } t
 | ƒ rˆ t j | ƒ n  t | d ƒ  } | j |  ƒ Wd  QXt j | t j t j Bƒ q Wd  S(   NR'   u   urlu   %s.tokenu   w(   R,   R'   t
   TOKEN_DIRSR    R-   R   R   t   makedirsR   R   R   t   unlinkt   opent   writet   chmodt   statt   S_IWRITEt   S_IREAD(   R3   R?   R!   t	   token_dirR6   t	   tokenfilet   fd(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   store_tokenž   s    c         C@ s½   x¶ t  D]® } t | d t |  ƒ ƒ } t | ƒ r t j d j | ƒ ƒ t | ƒ  } | j ƒ  j	 ƒ  } Wd  QX| ry | St j d j | ƒ ƒ t j d j | ƒ ƒ t
 j | ƒ q q Wd  S(   Nu   %s.tokenu   Found login token: {}u   Token file is empty: {}u   Removing file: {}(   RB   R   R   R   R.   R0   t   formatRE   t   readt   stripR   RD   (   R6   RK   RL   RM   R3   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyR1   ¯   s    c         C@ st   t  d |  o |  j ƒ } | j d t ƒ } xC t D]; } t | d t | ƒ ƒ } t | ƒ r1 t j	 | ƒ q1 q1 Wd  S(   NR'   u   urlu   %s.token(
   R,   R'   R    R-   RB   R   R   R   R   RD   (   R?   R!   R6   RK   RL   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   remove_tokenÀ   s    c         C@ s>   t  |  ƒ r: t |  ƒ  } t | ƒ } | r1 | SWd  QXn  i  S(   N(   R   RE   R   (   t   config_fileRM   t   data(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   load_configÊ   s    c         @ s²   d „  } d „  } i | t  j 6| t  j 6‰ d „  ‰  g  |  D] } t | ƒ ^ q< } ‡  f d †  | Dƒ } ‡ f d †  t | | ƒ Dƒ } t j d „  t j j	 | ƒ Dƒ ƒ } | S(   Nc         s@ sN   |  j  d ƒ s9 |  j  d ƒ s9 |  j  d ƒ s9 t |  ƒ ‚ |  t |  ƒ f Vd  S(   Nu   .ymlu   .yamlu
   anacondarc(   t   endswitht   AssertionErrorRU   (   t   fullpath(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   _file_yaml_loaderÕ   s    9c         s@ s_   xX t  j |  ƒ D]G } | j d ƒ s4 | j d ƒ r t |  | ƒ } | t | ƒ f Vq q Wd  S(   Nu   .ymlu   .yaml(   R   t   listdirRV   R   RU   (   RX   t   filenamet   filepath(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   _dir_yaml_loaderÙ   s    c         S@ s6   y t  j t j  |  ƒ j ƒ SWn t k
 r1 d  SXd  S(   N(   RH   t   S_IFMTR   t   st_modet   OSErrorR+   (   R   (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   _get_st_modeå   s    c         3@ s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   t   .0R   (   Ra   (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pys	   <genexpr>í   s    c         3@ s1   |  ]' \ } } | d  k	 r ˆ  | | ƒ Vq d  S(   N(   R+   (   Rb   R   R_   (   t   _loader(    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pys	   <genexpr>î   s   	c         s@ s   |  ] } | Vq d  S(   N(    (   Rb   t   kv(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pys	   <genexpr>ñ   s    (
   RH   t   S_IFREGt   S_IFDIRR   t   zipR   t   OrderedDictt	   itertoolst   chaint   from_iterable(   t   search_pathRY   R]   R   t   expanded_pathst
   stat_pathst
   load_pathst   raw_data(    (   Ra   Rc   sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   load_file_configsÔ   s    		
	%c         C@ s²   t  j ƒ  } t t ƒ } x | D] } t | | | ƒ q W|  pL | j d ƒ }  | j d i  ƒ } |  r® t |  ƒ }  |  | k r’ t j d |  ƒ q® t | | j |  i  ƒ ƒ n  | S(   Nu   default_siteu   sitesu1   Site alias "%s" does not exist in the config file(	   t   DEFAULT_CONFIGt   copyRq   t   SEARCH_PATHR   R    t   strR.   t   warning(   R'   R!   t   file_configst   fnt   sites(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyR,   ö   s    c         C@ sŠ   t  | ƒ } yH t | ƒ s+ t j | ƒ n  t | d ƒ  } t |  d | ƒWd  QXWn/ t k
 r… } t d | j | j	 f ƒ ‚ n Xd  S(   Nu   wt   streamu   %s: %s(
   R   R   R   RC   RE   R   t   EnvironmentErrorR   R[   t   strerror(   RT   RS   t   data_dirRM   t   exc(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   save_config  s    c         C@ s-   t  j d t ƒ t |  | r" t n t ƒ d  S(   Nu%   Use save_config instead of set_config(   R9   R:   R;   R   t   USER_CONFIGt   SYSTEM_CONFIG(   RT   t   user(    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt
   set_config  s    (D   t
   __future__R    R   R   t   os.pathR   R   R   R   R   R   R	   t   stringR
   R   R=   R   RH   R9   Ri   t   urllibR   t   ImportErrort   urllib.parset   binstar_client.utils.condaR   R   t   binstar_client.utils.appdirsR   R   t   binstar_client.errorsR   t   yamlR   R   t	   getLoggerR.   R   R   R   t   dirst   user_data_dirR€   t   PACKAGE_TYPESt   user_log_dirt   USER_LOGDIRt   SITE_CONFIGR   R-   R2   R+   Rr   t   CONFIGURATION_KEYSt   site_data_dirRt   R   R7   RA   RB   t	   TOKEN_DIRRN   R1   RR   RU   Rq   R,   R   Rƒ   (    (    (    sZ   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/utils/config.pyt   <module>   sˆ   4		
	
			
			
	
	"	