
:\c           @   s  d  Z  d d l 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
 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 Z d d l m Z m Z m 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 m Z d d
 l  m! Z! d d l" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 d d l7 m8 Z8 m9 Z9 m: Z: d d l; m< Z= d d l> m? Z? d d l@ mA ZA d d lB mC ZC mD ZD mE ZE mF ZF y d d lG ZG eH ZI Wn eJ k
 r_eK ZI n Xd e f d     YZL eM aN d   ZO d   ZP d   ZQ d   ZR d   ZS eT d k reS   n  d S(   s=   API for using the api (anaconda-client, downloads and conda).i(   t   OrderedDict(   t   LooseVersionN(   t   QObjectt   QTimert   Signal(   t	   ClientAPI(   t   CondaAPI(   t   DownloadAPI(   t   DummyWorkert   WorkerManager(   t
   ProjectAPI(   t   BITS_32t   BITS_64t   CONFt	   CONF_PATHt   GLOBAL_VSCODE_APPt	   HOME_PATHt   LAUNCH_SCRIPTS_PATHt   LICENSE_NAME_FOR_PACKAGEt   LICENSE_PATHt   LINUXt	   LINUX_DEBt	   LINUX_DNFt	   LINUX_RPMt   MACt   METADATA_PATHt	   OS_64_BITt   PACKAGES_WITH_LICENSEt   REMOVED_LICENSE_PATHt   VALID_PRODUCT_LICENSESt   WIN(   t   contentt   imagest   scripts(   t	   constants(   t   logger(   t   path_is_writable(   t   PY2t   PY3t   is_binary_stringt   to_binary_stringt   _AnacondaAPIc           B   s<  e  Z d  Z e e  Z e e e  Z e e  Z e   Z e   Z	 i g  d 6Z
 d   Z d   Z d d  Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z e d  Z d   Z e d    Z e d  Z e d  Z e d  Z e d  Z e d  Z e d  Z e d    Z  e f  d  Z! e d  Z" d   Z# d   Z$ d   Z% d   Z& e' e' d  Z( e' d  Z) d   Z* d    Z+ d!   Z, e d"  Z- d#   Z. d$   Z/ d%   Z0 e d&  Z1 d'   Z2 e d(  Z3 d) f e' d*  Z4 d+   Z5 d,   Z6 d-   Z7 e' e' d.  Z8 e e' e' e' d/  Z9 e' d0  Z: d1   Z; d2   Z< e e d3   Z= d4   Z> e? d5    Z@ e d6    ZA e? e d7   ZB e? d8    ZC e? d9    ZD e? d:    ZE e? eF d;   ZG e? d<    ZH e? d=    ZI e? d>    ZJ e? d?    ZK e? d@    ZL e? dA    ZM RS(B   s   
    Anaconda Manager API.

    This class contains all methods from the different apis and acts as
    a controller for the main actions Navigator needs to execute.
    t   macc            s  t  t |   j   t |  _ t   |  _ t d |  j  |  _ t	 d |  j  |  _
 t   |  _ t   |  _ |  j j |  _ |  j j |  _ i  |  _ |  j j j   |  _ d |  _ i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6|  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _  d |  _ |  j j! |  _" |  j j# |  _$ |  j j% |  _& |  j j' |  _( |  j j) |  _* |  j j+ |  _, |  j j- |  _. |  j j/ |  _0 |  j j1 |  _2 |  j j3 |  _4 |  j j5 |  _6 |  j j7 |  _8 |  j j9 |  _: |  j j; |  _< |  j j= |  _> |  j j? |  _@ |  j
 jA   |  j
 jB } |  j jC  |  j
 jD |  _D |  j
 jE |  _F | |  _G    f d   |  _H |  j
 jI |  _J |  j
 jK |  _L |  j jM |  _N |  j jO |  _P |  j jQ |  _R |  j jC |  _S |  j jT |  _U |  j jV |  _W |  j jX |  _Y |  j jZ |  _[ |  j j\ |  _] |  j j^ |  __ |  j j` |  _a |  j jb |  _c |  j jd |  _e |  j jf d d  } | r|  jg   n  d S(   s$   Anaconda Manager API process worker.t   configt   7t   rhelt   12t   slest   centost   8t   debiant   23t   fedoras   42.1t   suses   14.04t   ubuntuc              s         S(   N(    (    (   t   _get_api_infot   _get_api_url(    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   <lambda>   t    t   homet   vscode_enableN(h   t   superR)   t   __init__R   R+   R   t
   _conda_apiR   t   _client_apiR   t   _download_apiR
   t   _project_apiR	   t   _process_apit   ROOT_PREFIXt   CONDA_PREFIXt	   _metadatat
   user_agentt   lowert   _user_agentt   Nonet   _data_directoryt   _DISTRO_MAPt   _DISTRO_NAMEt   _DISTRO_VERt   _VSCODE_SUBDIRt   _VSCODE_INST_DIRt   _VSCODE_EXEt   _VSCODE_EXE_USERt   _VSCODE_APPDIRt   _VSCODE_ENDPOINTt   _VSCODE_INSTFILEt   dependenciest   conda_dependenciest   removet   conda_removet   terminate_all_processest   conda_terminatet
   config_addt   conda_config_addt
   config_sett   conda_config_sett   config_removet   conda_config_removet
   clear_lockt   conda_clear_lockt   environment_existst   conda_environment_existst   get_envst   conda_get_envst   linkedt   conda_linkedt   linked_apps_infot   conda_linked_apps_infot   get_prefix_envnamet   conda_get_prefix_envnamet   package_versiont   conda_package_versiont   get_platformt   conda_platformt   load_proxy_configt   conda_load_proxy_configt   split_canonical_namet   conda_split_canonical_namet   get_api_infot   is_valid_api_urlt   get_api_urlt   downloadt   is_valid_urlt   download_is_valid_urlt   download_is_valid_api_urlt   download_get_api_infot   is_valid_channelt   download_is_valid_channelt	   terminatet   download_terminatet   logint   client_logint   logoutt   client_logoutt   usert   client_usert   client_get_api_urlt   set_api_urlt   client_set_api_urlt   get_sslt   client_get_sslt   set_sslt   client_set_sslt   get_user_licensest   client_get_user_licensest   domaint   client_domaint   reload_binstar_clientt   client_reloadt   create_projectt   project_createt   uploadt   project_uploadt   load_projectt   project_loadt   gett   vscode_init(   t   selft   _is_valid_urlt   apps_vscode_enable(    (   R7   R8   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR>   S   s    														c         C   s#   t  j d j |   | |  _ d S(   s+   Set the directory where metadata is stored.s   data_directory: {}N(   R#   t   debugt   formatRK   (   R   t   data_directory(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   set_data_directory   s    s   https://conda.anaconda.orgc         C   s   t  j d j | |   | j d  s7 | j d  r@ | } n d j | |  } | d d k ro | d  } n  |  j   } d j | | d  } |  j |  } | | _ | S(	   s   Check if channel is valid.s   channel: {}, conda_url: {}s   https://s   http://s   {0}/{1}it   /s   {0}/{1}/{2}s   repodata.json(   R#   R   R   t
   startswithRq   R{   t   url(   R   t   channelt	   conda_urlR   t   platt   repodata_urlt   worker(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   check_valid_channel   s    		c   	         sv   t      |  j } d   }   f d   } | j | | | | |  } | j j   j  | j j |  | j     S(   s$   Check pids and child spawned by pid.c         S   s   t  |   } d } x | d k  r t    } x\ | D]T } t j |  r1 t j |  } x- | j d t  D] }	 | j |	 j  qh Wq1 q1 W| d 7} | j |  } q Wt	 t
 |   } i | d 6| d 6| d 6| d 6}
 |
 S(	   s$   Check pids and child spawned by pid.i    i2   t	   recursivei   t   pidst   packaget   commandt   prefix(   t   sett   psutilt
   pid_existst   Processt   childrent   Truet   addt   pidt   uniont   listt   sorted(   t	   processest   package_nameR   R   R   t   countt   new_pidsR   t   proct   pt   data(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt
   _check_pid   s$    	

c            s-   t  j | | f    j j   | |  d S(   s   Callback for _check_pid.N(   R#   R   t   sig_finishedt   emit(   R   t   outputt   error(   t   dummy_worker(    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt	   _finished   s    (   R   RC   t   create_python_workert   sig_partialt   connectR   t   start(	   R   R   R   R   R   t   wmR   R   R   (    (   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt	   check_pid   s    				
c         C   s(   |  j  j d d  r t } n t } | S(   s   Check initernet availability.t   maint   offline_mode(   R+   R   t   FalseR   (   R   t   connectivity(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   is_internet_available   s    	c         C   s   |  j    S(   R:   (   R   (   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt
   is_offline  s    c         C   s<   t  j d j | d t |    |  j j | | d d  S(   sq   
        Login to anaconda cloud via the anaconda-client API.

        This method does not use workers.
        s   username: {}, password: {}t   *s   Anaconda NavigatorR:   (   R#   R   R   t   lenR@   R   (   R   t   usernamet   password(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR     s    	c         C   s   t  j d  |  j j   S(   st   
        Logout from anaconda cloud via the anaconda-client API.

        This method does not use workers.
        R:   (   R#   R   R@   R   (   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR     s    c         C   s    t  j d  t |  j j    S(   s   Check if an user is logged in.R:   (   R#   R   t   boolR@   R   (   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   is_logged_in!  s    c            s]   t  j d   j j        f d   } d      j j   } | j j |  | S(   s-   Get all the api urls for the current api url.R:   c            s~   t  j d j | |   |  } | j d i   } | j d t  }  j j  d | d | }  | |  _ |  j j	    d  S(   Ns   output: {}, error: {}t   proxy_serverst
   ssl_verifyt   verify(
   R#   R   R   R   R   R@   Rv   t   base_workerR   R   (   R   R   R   R   R   R   (   t	   _api_infot   api_urlR   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _config+  s    			c         S   s<   t  j d j | |   |  j } | j j | | |  d  S(   Ns   output: {}, error: {}(   R#   R   R   R   t   sig_chain_finishedR   (   R   R   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR   8  s    	(   R#   R   R@   Rx   R?   t   config_showR   R   (   R   R   R   (    (   R   R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   api_urls&  s    	c            s`   t  j d j |      f d   }  f d      j j d |  } | j j |  | S(   s   
        Load packages and apps from conda cache, based on `prefix`.

        Returns a Conda Worker with chained finish signal.
        s
   prefix: {}c            s   t  j d j | |   | d } | d }  j j d d d |  }  j j d |  }  j j d | d  j d	 |  } |  | _	 | j
 j    d
 S(   s4   Load processed channels for prefix using conda info.s   info: {}, error: {}t   channelst   default_prefixt   pkgt   pythonR   t   repodatat   metadatat   python_versionN(   R#   R   R   R?   Rn   t   get_repodataR@   t   load_repodataRF   R   R   R   (   R   t   infoR   R   R   R   R   R   (   t   _load_repo_dataR   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _load_channelsI  s    

			c            sj   t  j d j | |   |  j } | r7 i  i  f } n  | rf   j j |   | j j | | |  n  d S(   s2   Loads the repository data from speficied channels.s   output: {}, error: {}N(   R#   R   R   R   t   sig_repodata_loadedR   R   (   R   R   R   R   (   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR   Z  s    	R   (   R#   R   R   R?   R   R   R   (   R   R   R   R   (    (   R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR   A  s    c         C   s5   t  j d  |  j j   } | j d  |  j j f S(   s   Get username and token.R:   R   (   R#   R   R@   R   R   t   token(   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   get_username_tokenj  s    c         C   s  d } d } t    } x | D]y } | | k r | j |  \ } } | | } | j d  } | d }	 d j d g | d  }
 |	 | | | |
 <q q Wg  } xk |  D]c } | | k r xA | j   D]0 \ } }	 | j |  r | j | |	  } q q Wn  | j |  q W| S(   s  
        Fix channels with tokens so that we can correctly process conda cache.

        From this:
            - 'https://conda.anaconda.org/t/<TOKEN>/goanpeca/<SUBDIR>'
        to this:
            - 'https://conda.anaconda.org/t/<ACTUAL-VALUE>/goanpeca/<SUBDIR>'
        s   /t/s   <TOKEN>R   i    R:   i   (   R    t   splitt   joint   itemsR   t   replacet   append(   R   t   unsafe_channelst   TOKEN_START_MARKt   TOKEN_VALUE_MARKt   token_channelst   chR   t   token_plus_user_and_systemt   partsR   t   endt   new_channelst   uch(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _process_unsafe_channelsr  s&    
	

c            s   t  j d j     j s,  j   n      f d   }    f d       f d    d     j j d  d t  } | j j	 |  | S(   s   
        Return all the conda data needed to make the application work.

        If prefix is None, the root prefix is used.
        s
   prefix: {}c            s?    j  j d   } | j j    | d | _ |  | _ d S(   R:   R   R   N(   R?   R   R   R   R   R   (   R   R   R   t
   new_worker(   t   _conda_info_processedR   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _load_unsafe_channels  s    c            s<  t  j d j | |   |  j }  j |  } | | _ | | _  j | d |  j  } | d }  j	 j
 d d d |  } | d }  j	 j d | d |  }	 |	 r  j j d |	 d	  j d
 |  }
 | |
 _ |
 j j   nL  j	 j d d | }
 | |
 _ | |
 _ | |
 _ | |
 _ |
 j j    d  S(   Ns   info: {}, error: {}R   R   R   R   R   t	   pkgs_dirsR   R   R   t   conda(   R#   R   R   R   t   _process_conda_infoR   t   processed_infoR  R   R?   Rn   R   R@   R   RF   R   R   t   searchR   R	  R   (   R   R   R   R   R  R   R   R   R	  R   R  (   t   _get_repodataR   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s4    			

							c            sh    j  j d |  j d |  j  }  j j d | d  j d |  j  } |  j | _ | j	 j
    d  S(   NR   R	  R   R   R   (   R?   R   R   R	  R@   R   RF   R   R   R   R   (   R   R   R   R   R  (   R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    	c         S   sp   t  j d j | |   |  j } | \ } } i | j d 6| j d 6| d 6| d 6} | j j | | |  d  S(   Ns   output: {}, error: {}R   R  t   packagest   applications(   R#   R   R   R   R   R  R   R   (   R   R   R   R   R  R  t
   new_output(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR     s    	


R   R   (
   R#   R   R   RF   t   load_bundled_metadataR?   R   R   R   R   (   R   R   R  R   (    (   R  R  R   R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt
   conda_data  s    	%	c            sN   t  j d j |     f d   }   j j d |  } | j j |  | S(   sz   
        Return the processed conda info for a given prefix.

        If prefix is None, the root prefix is used.
        s
   prefix: {}c            sB   t  j d j | |     j |  } |  j j |  | |  d  S(   Ns   info: {}, error: {}(   R#   R   R   R  R   R   (   R   R   R   R  (   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    R   (   R#   R   R   R?   R   R   R   (   R   R   R  R   (    (   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt
   conda_info  s
    c         C   sH   t  j d j |   d   } |  j j d |  } | j j |  | S(   s   Show config for a given prefix.s
   prefix: {}c         S   sF   t  j d j | |   | } i | d 6} |  j j |  | |  d  S(   Ns   output: {}, error: {}R+   (   R#   R   R   R   R   (   R   R   R   R+   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR     s    R   (   R#   R   R   R?   R   R   R   (   R   R   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   conda_config  s
    	c         C   sH   t  j d j |   d   } |  j j d |  } | j j |  | S(   s'   Show config sources for a given prefix.s
   prefix: {}c         S   sF   t  j d j | |   | } i | d 6} |  j j |  | |  d  S(   Ns   output: {}, error: {}t   config_sources(   R#   R   R   R   R   (   R   R   R   R  R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _config_sources	  s    R   (   R#   R   R   R?   t   config_show_sourcesR   R   (   R   R   R  R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   conda_config_sources  s
    	c            s]   t  j d j        f d   } d      j j d   } | j j |  | S(   s2   Show config and config sources for a given prefix.s
   prefix: {}c            sZ   t  j d j | |   |  }  j j d   }  | |  _ | |  _ |  j j    d  S(   Ns   output: {}, error: {}R   (	   R#   R   R   R?   R   R  R   R   R   (   R   R   R   R   (   R   R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    		c         S   s_   t  j d j | |   |  j } |  j } | } i | d 6| d 6} | j j | | |  d  S(   Ns   output: {}, error: {}R+   R  (   R#   R   R   R   R  R   R   (   R   R   R   R   R  R+   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR     s    		
R   (   R#   R   R   R?   R  R   R   (   R   R   R  R   (    (   R   R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   conda_config_and_sources  s    	c            sr   t  j d j       f d   }     f d    d      j j d   } | j j |  | S(   sz   
        Return the processed conda info for a given prefix.

        If prefix is None, the root prefix is used.
        s
   prefix: {}c            sr   t  j d j | |    j |  } |  } | | _ | | _  j j d   }  | |  _ |  j	 j
    d  S(   Ns   info: {}, error: {}R   (   R#   R   R   R  R  R   R?   R  R   R   R   (   R   R   R   R  R   (   R  R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR  6  s    			c            s]   t  j d j | |   |  j }  j j d   }  | | _ | |  _ |  j j    d  S(   Ns   config_sources: {}, error: {}R   (	   R#   R   R   R   R?   R   R  R   R   (   R   R  R   R   (   R   R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR  A  s    			c         S   ss   t  j d j | |   |  j } | | _ i | j d 6| j d 6| j d 6| j d 6} | j j	 | | |  d  S(   Ns   output: {}, error: {}R   R  R+   R  (
   R#   R   R   R   R+   R   R  R  R   R   (   R   R   R   R   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR   K  s    		


R   (   R#   R   R   R?   R   R   R   (   R   R   R  R   (    (   R   R  R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   conda_info_and_config.  s    
	c         C   sY  t  j d j |    |  j   } g  } x. |  d D]" } t |  r3 | j |  q3 q3 W| | d <g  } x. |  d D]" } t |  rt | j |  qt qt W| | d <|  d } t   } d | | <|  d } g  | D] }	 t j j	 |	  ^ q }
 xN t
 t |
 |   D]7 \ } } t r3| d	 j   | d
 } n  | | | <qWd | | <| | d <| S(   s2   Process conda info output and add some extra keys.s   info: {}t	   envs_dirst   __envs_dirs_writableR	  t   __pkgs_dirs_writablet   root_prefixs   base (root)t   envsi    i   t   __environments(   R#   R   R   t   copyR$   R   R    t   ost   patht   basenameR   t   zipR   t   upper(   R   R  t   envs_dirs_writablet   env_dirt   pkgs_dirs_writablet   pkg_dirR  t   environmentsR   t   envt
   envs_namest   env_namet
   env_prefix(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR  [  s0    


	

%"

c            s   t  j d j  |        f d   }  f d     | j   } x*  D]" } | | k rS | j |  qS qS W j j d   } | | _ | j j	 |  | S(   sA   Process packages data and metadata to row format for table model.s&   prefix: {}, packages: {}, blacklist={}c            s   t  j d j | |   |  } | j } | r> t  j |  n t  j d  | pT g  }  j j d   }  j j | | |  }  | |  _	 |  j
 j    d  S(   Ns   output: {}, error: {}R:   R   (   R#   R   R   R  R   R?   Rh   R@   t   prepare_model_dataR   R   R   (   R   R   R   R   t   clean_packagest   pip_packagesRh   (   t   _model_data_readyR   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _pip_data_ready  s    			c   	         s   t  j d j | |   |  j } | j } | } xn   D]f } | | k r[ | j |  n  xA t |  D]3 \ } } | | | t j k rh | j |  qh qh Wq9 W| j	 j
 | | | f |  d  S(   Ns   output: {}, error: {}(   R#   R   R   R   R  t   popt	   enumeratet   Ct   COL_NAMER   R   (	   R   R   R   R   R2  R   R   t   rowt   row_data(   t	   blacklist(    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR4    s    			R   (
   R#   R   R   R"  R6  R?   t   pip_listR  R   R   (   R   R  R   R<  R5  R2  R   R   (    (   R4  R<  R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   process_packages  s    	c         C   s  t  j d j | |   i  } | d> k r7 |  j } n  |  j |  } g  | D] } | | k rM | ^ qM } x | D] } | | | | <qr Wd | k } i t j d 6t j d 6t j d 6t j	 d 6t j	 d 6t j
 d 6t j
 d	 6t j d
 6t j d 6t j d 6t j d 6t j d 6t j d 6t j d 6t j d 6t j d 6t j d 6} i d d 6d d 6d d 6d d 6d d	 6d d
 6d d 6d d 6d d 6d d 6d d 6d  d 6d! d 6d" d 6}	 |	 d
 |	 d <|	 d |	 d <i d# d 6d$ d 6d% d	 6d& d 6d' d 6d( d 6d) d 6d* d 6}
 d d d d+ g } xF| D]>} | | k r9q!n  | | } |
 j | |  } | j d,  } |	 j | | j d- d.   } | d/ } | j | t j  } | j d0  j | d.  } d1 | j   k r| j d1 d2  } n' d3 | j   k r
| j d3 d4  } n  | j   t k } t d5 | d6 | d- | d, | d7 | d8 | d9 | d: t  } | | | <q!W|  j j d; d<  } | s| r|  j   r|  j   } t } d* } t d5 | d6 | d- |	 | d, | j d=  g d7 |  j d8 | | d9 t d: t  | | <qn  | S(?   s   Process app information.s   prefix: {}, apps: {}t   vscodet   gluevizs
   spyder-appt   spyders   ipython-qtconsolet	   qtconsoles   ipython-notebookt   notebooks
   orange-appt   orange3t   rodeot   veuszt   rstudiot
   jupyterlabt   pyvscodet	   qtcreatort
   qt3dstudios   Integration between Excel ® and Anaconda via Notebooks. Run data science functions, interact with results and create advanced visualizations in a code-free app inside Excel.s   anaconda-fusionsv   Interactive exploration of larger than memory datasets. Create data sources, perform transformations and combinations.s   anaconda-mosaicsj   Multidimensional data visualization across files. Explore relationships within and among related datasets.su   An extensible environment for interactive and reproducible computing, based on the Jupyter Notebook and Architecture.s{   Web-based, interactive computing notebook environment. Edit and run human-readable docs while describing the data analysis.s   Component based data mining framework. Data visualization and data analysis for novice and expert. Interactive workflows with a large toolbox.sw   PyQt GUI that supports inline figures, proper multiline editing with syntax highlighting, graphical calltips, and more.sn   A browser-based IDE for data science with python. Includes autocomplete, syntax highlighting, IPython support.sn   A set of integrated tools designed to help you be more productive with R. Includes R essentials and notebooks.s   Scientific PYthon Development EnviRonment. Powerful Python IDE with advanced editing, interactive testing, debugging and introspection featuress~   Veusz is a GUI scientific plotting and graphing package. It is designed to produce publication-ready Postscript or PDF output.sq   Streamlined code editor with support for development operations like debugging, task running and version control.s[   Cross platform integrated development environment (IDE) to create C++ and QML applications.s   Rapidly build and prototype high quality 2D and 3D user interfaces using the built-in material and effects library or import your own design assets.t   Gluevizt
   JupyterLabt   Notebooks   Orange 3s
   Qt Consolet   RStudiot   Spyders   VS Codet   anacondafusiont   versionst   descriptionR:   it	   app_entrys   ipython notebooks   jupyter-notebooks   ipython qtconsoles   jupyter-qtconsolet   namet   display_nameR   t
   image_patht   needs_licenset	   non_condaR;   R<   t   productVersionN(   R#   R   R   RJ   RD   Rk   R    t   GLUEVIZ_ICON_1024_PATHt   SPYDER_ICON_1024_PATHt   QTCONSOLE_ICON_1024_PATHt   NOTEBOOK_ICON_1024_PATHt   ORANGE_ICON_1024_PATHt   RODEO_ICON_1024_PATHt   VEUSZ_ICON_1024_PATHt   RSTUDIO_ICON_1024_PATHt   JUPYTERLAB_ICON_1024_PATHt   VSCODE_ICON_1024_PATHt   QTCREATOR_ICON_1024_PATHR   t   ANACONDA_ICON_256_PATHRH   R   R   t   dictR   R+   t   is_vscode_availablet   vscode_application_dataR   RQ   R   (   R   t   appsR   R  t   linked_appst   appt   missing_appst   vscode_conda_package_existst   image_pathst   APPS_DESCRIPTIONSt   APPS_DISPLAY_NAMESt   invalid_appst   app_nameR   RV  RR  RS  t   versionRW  RT  RX  t   applicationR   t   vsdata(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   process_apps  s    %

















	

	
	
c         C   sX  |  j  } d } d } t } d) } t rEd d l m } m } d } t j j	 }	 t j
 d  }
 |	 j |
 d  |
 j d  } t r d } | | j  d } t j j | d	  } n7 t r d
 } | | j  d } t j j | d  } n  | | j  d } | | j  d p!t j j | d  } | d) k rHt j j d |  } n  t j j t j j | d   rt j j | d  } nW | rt j j t j j | d   rt j j | d  } n t j j | d d  } t j j | d d  } t j j | d d  } | | j  d } | d) k rzt j j | d d  } qzn5t rd } d } t j j t d  } t j j | d d  } t j j | d d  } n t rzxW | j   D]I } d j |  } t j | |  j  } | r| } | j  d  } PqqW| d* k rd } n d } t! r&d  n d! } d" j | |  } | } d# } t j j | d d$  } t j j | d%  } n  d& j |  } t j j t" d' d( j |   } | |  _# | |  _$ | |  _% | |  _& | |  _' | |  _( | |  _) | |  _* | |  _+ yE | r?t j j, t j j- |   r?t j. t j j- |   n  Wn t/ k
 rSn Xd) S(+   s(   Initialize VSCode setttings for install.R:   i(   t   get_folder_patht   FOLDERIDt   exei   i   s
   win32-useri    s   Program Files (x86)s   win32-x64-users   Program Filest   ProgramFiless   Microsoft VS Codet   Programst   bins   code.cmdt   AppDatat   Roamingt   darwinR&  t   Applicationss   Visual Studio Code.apps   Contents/Resources/app/bin/codet   Librarys   Application Supports   .*{}/([^ ]*)i   R6   R2   t   debt   rpmt   x64t   ia32s   linux-{}-{}s   /usr/share/codet   codes   .configsA   https://update.code.visualstudio.com/api/update/{}/stable/versiont   temps   vscodetemp.{}N(   R6   R2   (0   RL   R   RJ   R   t(   anaconda_navigator.external.knownfoldersRx  Ry  t   ctypest   windllt   kernel32t   create_unicode_buffert   GetWindowsDirectoryWt   valueR   t   ProgramFilesX86R#  R$  R   R   t   ProgramFilesX64t   LocalAppDatat   environR   t   existst   RoamingAppDataR   R   t   keysR   t   ret   matchRI   t   groupR   R   RM   RN   RO   RP   t   _VSCODE_INST_DIR_FOUNDRQ   RS   RT   RU   t   isdirt   dirnamet   makedirst	   Exception(   R   t
   DISTRO_MAPt   DISTRO_NAMEt
   DISTRO_VERt   VSCODE_HOMEPATHt   VSCODE_INST_DIR_FOUNDRx  Ry  t   VSCODE_INST_EXTt	   _kernel32t   _windirt	   _windrivet   VSCODE_SUBDIRt   PROGRAM_FILESt	   _fallbackt   LOCAL_APP_DATAt   PROGRAM_FILES_64t   VSCODE_INST_DIRt
   VSCODE_EXEt   VSCODE_APPDIRt   distrot   _distro_regext   mt	   _pkg_typet   _os_archt   VSCODE_ENDPOINTt   VSCODE_INSTFILE(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR     s    																								 c         C   s   y t  r t St r9 t t j   d  t d  k } | St r |  j |  j } t	 |  j  d k o t	 |  j
  d k o t |  j
  t |  k SWn! t k
 r } t j |  t SXt S(   s6   Is VSCode available for installation on this platform.i    s   10.9(   R   R   R   R   t   platformt   mac_verR   RL   RM   R   RN   R  R#   R   R   (   R   t   vt   _distro_min_vert   e(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyRh    s     "c         C   sU   t  rH |  j d  k	 rH t j j |  j  rH t j j |  j d d  } n	 |  j } | S(   NR}  s   code.cmd(   R   R  RJ   R#  R$  R  R   RQ   (   R   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_executable-  s    		c         C   s=   i  } |  j  } | r9 |  j j d | d t d t  } n  | S(   s(   Get vscode data from microsoft rest api.R   t   as_jsont   non_blocking(   RT   RA   t   get_urlR   R   (   R   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyRi  8  s    	c         C   sq   | r d } n d } t  j j t d |  } | rm t  j j |  rm y t  j |  Wqm t k
 ri qm Xn  | S(   s.   Return the log path for installer/uninstaller.s   vscode-uninstall-log.txts   vscode-install-log.txtR  (   R#  R$  R   R   t   isfileRX   R  (   R   t	   uninstallt   deletet   fnamet   log_path(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_log_pathD  s    	c         C   s]   |  j  d |  } t j j |  rL t j | d   } | j   Wd QXn  i t d 6} | S(   s6   Return the parsed log data from installer/uninstaller.R  t   rNt
   successful(   R  R#  R$  R  t   iot   opent   readR   (   R   R  R  t   ft   log_data(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_log_dataU  s    c         C   sI  t  j  j   } | j d  } t j j |  j d d  } t j j | d j d |   } t j	 d j |   t
 j | d d d	  } | j |  Wd
 QXt j |  } g  | D]9 } | j d  r | j d  r t j j | |  ^ q }	 t t |	 d t  d }
 x3 |
 D]+ } y t j |  Wqt k
 r@qXqWd
 S(   sx   
        Create a backup copy of the vscode configuration file `data`.

        Leave only the last 10 backups.
        s   %Y%m%d%H%M%St   Codet   Users"   bck.{date}.navigator.settings.jsont   dates&   Creating backup vscode config file: {}t   wt   encodings   utf-8Ns   bck.s   .navigator.settings.jsont   reversei
   (   t   datetimet   nowt   strftimeR#  R$  R   RS   R   R#   R   R  R  t   writet   listdirR   t   endswithR   R   R   RX   R  (   R   R   R  R  t   _vscode_config_dirt   _vscode_config_bckt   f_handlet   filesR  t   fpathst   fpaths_removet   fpath(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_create_config_backupa  s.    			
9c         C   s  t  j d j |   y}t j j |  j d d d  } t j j |  } y& t j j |  sn t j	 |  n  Wn  t
 k
 r } t  j |  n Xi | d 6} t j j |  r=yt t j | d d d  } | j   } Wd	 QX|  j |  t j |  } x$ | j   D] \ }	 }
 |
 | |	 <q
WWqIt
 k
 r9t SXn | j   } t rUd
 n d } t j | |  # } t j | | d t d d Wd	 QXWn! t
 k
 r} t  j |  t SXt S(   s-   Update vscode python interpreter user config.s%   Update vscode config to use prefix {}R  R  s   settings.jsons   python.pythonPathR  R  s   utf-8NR  t   wbt	   sort_keyst   indenti   (   R#   R   R   R#  R$  R   RS   R  R  R  R  R   R  R  R  R  R  t   jsont   loadsR   R   R"  R&   t   dumpR   (   R   R   t   _vscode_configR  R  t   config_updateR  R   t   config_datat   keyt   valt   mode(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_update_config  sH    		c            sn      f d     t    |  _ |  j j d  |  j j t  |  j j j   f d    |  j j   d S(   R:   c             s3      f }  i |  d 6}  j  j  | d   d  S(   NR   (   R   R   RJ   (   R   t   o(   t   messaget   titleR   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   func  s    i  c              s       S(   N(    (    (   R  (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR9     R:   N(   R   t   _timer_errort   setIntervalt   setSingleShotR   t   timeoutR   R   (   R   R  R  R   (    (   R  R  R  R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   trigger_finished_error  s    c      	      s  t      j   } | j d  } d  j k 	  j d k   j d k 
  j  | sw  j d d	    St r  d k r  j d
 d    S d k r  Sn        
    f	 d   }     f d       	   f d      	   f d      	   f d       f d       f d     f d     j j	 | d  j
 } | j j  j  | j j |   S(   s   Install vscode.R   t   opensuseR6   R2   R0   R-   R4   s   Connectivity Errors1   Please check your internet connection is working.s   Password Errors5   Please try again and provide the correct credentials.R:   c   
         sL  t  j d  | r-  j j  | |  d St ry t j  j  Wn5 t k
 r~ } | j	 t	 j
 k r t  j |  q n Xt  j d  d d  j d  j g }  j |  }  |  j j  j  |  j j  i d d 6d  |  j j   |  j   nEt r,d	 d
 d d j  j  d d d d d j  j d t   d j  j  g
 } d j |  } t  j |  t j j t d d  } t j j |  } t j j |  st j |  n  t j | d   } | j |  Wd QX j | g  }  |  j j  j  |  j j   |  j   nt rHt r rd d d d  j g }  j |  }  |  j j  j  |  j j    |  j   t   d  }	 |  j |	  qHt! r/ r/d d d d d g }  j |  }  |  j j  j  |  j j   |  j   t   d  }	 |  j |	  qH j j  d d  n  d S(    s   Download callback.s   Finished VSCode downloadNs    Decompressing vscode applications   /usr/bin/unzips   -qos   -ds   Uncompressing file...R  t   STARTs   /WAITs   ""s   "{}"s   /VERYSILENTs   /MERGETASKS=!runcodes   /SUPPRESSMSGBOXESs
   /NORESTARTs	   /LOG="{}"R  s   /DIR="{0}\"u    R  s   vscode-install.batR  t   sudos   -kSt   dpkgs   -is   
R  s   --imports1   https://packages.microsoft.com/keys/microsoft.asc("   R#   R   R   R   R   R#  R  RP   t   OSErrort   errnot   EEXISTR   RU   t   create_process_workerR   R   RJ   R   R   R   R  R   R   R$  R   R  R  R  R  R  R   R   R(   R   (
   R   R   R   R  R   t   cmdt   bat_patht   base_temp_pathR  t   stdin(	   t   _install_deb_dependenciest   _install_extensionst   _install_rpm_repodataR   t   is_debt   is_rpmR   R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _download_finished  s    	
		
	
c            s   d d d d d g }  j  |  }  |  j j  j  |  j j    |  j j  i d d 6d   |  j   t  d  } |  j |  d  S(	   NR  s   -kSs   apt-gett   installs   -fs   Installing dependencies...R  s   
(	   R  R   R   R   R   RJ   R   R(   R  (   R   R   R   R   R  (   R  R   R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR  M  s    	

c            s   t  j d   r d n d } d d t j t j | g } t  j d j |    j |  }  |  j j	  j  |  j
 j	    |  j j  i d d 6d   |  j   t  d	  } |  j |  d  S(
   Ns   install rpm repodataR  R4   R  s   -kSt    s   Installing repodata...R  s   
(   R#   R   t   syst
   executableR!   t   VSCODE_INSTALL_SCRIPTR   R  R   R   R   R   RJ   R   R(   R  (   R   R   R   R  R   R  (   t   _update_rpm_managerR   t   is_opensuseR   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR  [  s$    		

c            s   t  j d   r( d d d d g } n! t r= d d g } n d d g } t  j d	 j |    j |  }  |  j j  j  |  j j    |  j j  i d
 d 6d   |  j
    r t  d  } |  j |  n  d  S(   Ns   update rpm managerR  s   -kSt   zyppert   refresht   dnfs   check-updatet   yumR  s   Updating manager...R  s   
(   R#   R   R   R   R  R   R   R   R   RJ   R   R(   R  (   R   R   R   R   R  (   t   _install_rpm_packageR   R  R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR  r  s$    	

c            s   t  j d   r. d d d d d d g } n9 t rO d d d d	 d d g } n d d d
 d	 d d g } t  j d j |    j |  }  |  j j  j  |  j j    |  j j  i d d 6d   |  j
   t  d  } |  j |  d  S(   Ns   install rpm packageR  s   -kSR  s   --non-interactiveR
  R  R  s   --assumeyesR  R  s   Installing rpm package...R  s   
(   R#   R   R   R   R  R   R   R   R   RJ   R   R(   R  (   R   R   R   R   R  (   R  R   R  R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s$    	

c            s   t  j d  | j   } d | k } d | k p: d | k } | ri | ri | ri  j j  | |  d S j   }  |  j j  i d d 6d  |  j j    |  j	   d S(   s5   Install vscode extensions as part of install process.s   install extensionsR   R   R  Ns   Installing python extensions...R  (
   R#   R   RH   R   R   t   vscode_install_extensionsR   RJ   R   R   (   R   R   R   t   check_int   check_not_in(   t   _send_telemetryR   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    	
c            s   t  j d  d | k } d | k p. d | k } | r] | r] | r]  j j  | |  d S j   }  |  j j  i d d 6d  |  j j    |  j   d S(   s1   Send vscode telemetry as part of install process.s   send telemetryR   R   R  Ns   Updating vscode data...R  (	   R#   R   R   R   t   vscode_send_telemtryR   RJ   R   R   (   R   R   R   R  R  (   t   _installation_finishedR   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    	
c            s'   t  j d    j j   | |  d  S(   Ns   Finished vscode installation(   R#   R   R   R   (   R   R   R   (   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    R$  (   R6   R2   (   R0   R-   R4   N(   R   Ri  R   RM   RC   R  R   RJ   RA   Ry   RU   R   R   R   (   R   R   Rv  R   R	  R   (    (   R  R  R  R  R  R  R  R   R  R  R  R   R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_install  sD    		'dc         C   sQ   |  j  } t j d  |  j d d g } t j d j |   | j |  } | S(   s   Install vscode extensions.s   Installing vscode extensionss   --install-extensions!   ms-python.anaconda-extension-packR  (   RC   R#   R   RQ   R   R  (   R   R   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    		c         C   sQ   |  j  } t j d  |  j d d g } t j d j |   | j |  } | S(   s   Send vscode telemetry.s   Sending vscode telemetrys   --install-sources   Anaconda-NavigatorR  (   RC   R#   R   RQ   R   R  (   R   R   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    		c   
      C   s  g  } g  } t    } |  j d k	 rE t j j |  j  rE |  j } n	 |  j } x t j |  D] } t j j | |  j	   } | j	   } t j j
 |  r^ | j d  } | r | d } n | } | j d  r | j d  r | j |  | j |  q>| j d  r>| j d  r>| j |  | j |  q>q^ q^ Wx8 t |  D]* }	 |	 d | k rO|	 d | k rOPqOqOW|	 d pd S(   s,   Check the right uninstaller file on windows.t   .i    t   uninss   .dats   .exes   unins000.exeN(   R   R  RJ   R#  R$  R  RP   R  R   RH   R  R   R   R  R   R   R   (
   R   t   datsR  t   namest   VSCODE_INST_FOLDERt   itemR$  R  R%  RU  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_win_uninstaller  s2    		 c            s+  t  j d   j  t    g   g  } d  j k }  j d k }  j d k } t rm  j g  nt r j g   j d k	 r t
 j j  j  r t
 j j  j  j    } n t
 j j  j  j    } | GHd | k rd	 | d	 } n  | g } d j |  } t
 j j t d
 d  }	 t
 j j |	  }
 t
 j j |
  sht
 j |
  n  t rtd n d } t j |	 |   } | j |  Wd QX|	 g } n t rGt r| rd d d d d d g } qGt rG| rG| rd d d d d d g } qDt r)d d d d d d g } qDd d d d d d g } qGn  d          f d   }   f d     | rt  j d j |    j |  } | j j  j  | j j |  | j   t r'| rt  | d  } | j |  q|  d d  q'n |  d d   S(    s5   Remove vscode files from computer or run uninstaller.s   Removing vscodeR  R6   R2   R0   R-   R4   R  t   "R  s   vscode-uninstall.batR  R  NR  s   -kSs   apt-gets   --yesRX   R  R  s   --non-interactiveR  s   --assumeyesR  c         S   s   xm |  D]e } t  j j |  r t j d j |   y t j |  Wql t k
 rh } t j |  ql Xq q W| j	 j
 | i  d  |  S(   s   Remove location.s   Removing location: {}N(   R#  R$  R  R#   R   R   t   shutilt   rmtreeR  R   R   RJ   (   t	   locationsR   t   locationR  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _remove_locationsf  s    c            sF    j      } | j j  j  | j j    | j   d S(   s   Remove location callback.N(   R   R   R   R   R   (   R   R   R   R  (   R   R)  R   R'  R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _uninstall_finishedt  s    	c            sM    j    } | s | d r- i | d 6} n | }   j j   | d   d  S(   NR  R   (   R  R   R   RJ   (   R   R   R   R  t   out(   R   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR     s
    s   
(   R6   R2   (   R0   R-   R4   (!   R#   R   RC   R   RM   R   RP   R   R  RJ   R#  R$  R  R   R#  R   R  R  R  R&   R  R  R  R   R   R   R   R  R   R   R   R   R(   (   R   R   t   uninstall_cmdR  R  R  t   uninstaller_pathR   R   R  R  R  R  R*  R   R  (    (   R   R)  R   R'  R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   vscode_remove  s    							
c         C   sB  t  j d  t j } t j } t } t j j |  s_ y t j	 |  Wq_ t
 k
 r[ q_ Xn  d } | r t j j |  r t | d   } | j   } Wd QXn  | r>ye t j |  } t | d   } | j |  Wd QXt |  r | j   } n  t j |  |  _ Wq>t
 k
 r:} t  j |  i  |  _ q>Xn  d S(   s   Load bundled metadata.R:   t   rbNR  (   R#   R   R   t   BUNDLE_METADATA_COMP_PATHt   CONF_METADATA_PATHR   R#  R$  R  R  R  RJ   R  R  R  t   bz2t
   decompressR  R'   t   decodeR  R  RF   R   (   R   t   comp_meta_filepatht   conf_meta_filepatht   conf_meta_foldert   binary_dataR  R   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s0    		c            s   t  j d      f d   } d      j d k rI t d   n  d } t j }  j | |  } t j	 | _
  | _  | _ | j j |  | S(   s   
        Update the metadata available for packages in repo.anaconda.com.

        Returns a download worker with chained finish signal.
        R:   c            s   t  j d j | |   |  } | r^ t j j |  r^ t | d   } | j   } Wd QXn  y t j	 |   _
 Wn t k
 r i   _
 n X j j d d  }  | |  _ |  j j    d S(   s   Callback for update_metadata.s   path: {}, error: {}R  NR
  R   (   R#   R   R   R#  R$  R  R  R  R  R  RF   R  R?   R  R   R   R   (   R   R$  R   R   R  R   (   t   _index_updatedR   R   (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   _metadata_updated  s    	c         S   s<   t  j d j | |   |  j } | j j | d  d   d  S(   Ns   output: {}, error: {}(   R#   R   R   R   R   R   RJ   (   R   R   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR9    s    	s,   Need to call `api.set_data_directory` first.s,   https://repo.anaconda.com/pkgs/metadata.jsonN(   R#   R   RK   RJ   R  R   R1  Ry   R8  t   ACTION_SEARCHt   actionR   t
   old_prefixR   R   (   R   R   R:  t   metadata_urlt   filepathR   (    (   R9  R   R   sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   update_index_and_metadata  s    				R   c      	   C   s   t  j d j | |   |  j j d | d | d | d |  j    } t j | _ d j |  | _	 | | _
 |  j j |  | _ | S(   s*   Create environment and install `packages`.s   prefix: {}, pkgs: {}R   t   pkgst   no_default_pythont   offlines   Creating environment <b>{0}</b>(   R#   R   R   R?   t   createR   R8  t   ACTION_CREATER<  t
   action_msgR   t   get_name_envprefixRU  (   R   R   R  RB  R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   create_environment  s    	c         C   s   t  j d j | |   |  j j | d | d |  j   } t j | _ |  j j	 |  } d j | |  | _
 | | _ |  j j	 |  | _ | | _ | S(   s8   Clone environment located at `clone` (prefix) into name.s!   prefix: {}, clone_from_prefix: {}R   RC  s3   Cloning from environment <b>{0}</b> into <b>{1}</b>(   R#   R   R   R?   t   clone_environmentR   R8  t   ACTION_CLONER<  RG  RF  R   RU  t   clone(   R   t   clone_from_prefixR   R   t   clone_from_name(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyRI    s    			c         C   s   t  j d j | |   |  j j d | d | d |  j    } t j | _ d j |  | _	 | | _
 |  j j |  | _ | | _ | S(   s9   Import new environment on `prefix` with specified `file`.s   prefix: {}, file: {}R   t   fileRC  s    Importing environment <b>{0}</b>(   R#   R   R   R?   RD  R   R8  t   ACTION_IMPORTR<  RF  R   RG  RU  RN  (   R   R   RN  R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   import_environment  s    		c         C   s   t  j d j |   |  j j d | d |  j    } t j | _ d j |  | _	 | | _
 |  j j |  | _ t } | |  j k r t j j | | j  } n  y t j |  Wn t k
 r n X| S(   s   Remove environment `name`.s
   prefix: {}R   RC  s   Removing environment <b>{0}</b>(   R#   R   R   R?   t   remove_environmentR   R8  t   ACTION_REMOVE_ENVR<  RF  R   RG  RU  R   RD   R#  R$  R   R%  R&  R  (   R   R   R   t   scripts_path(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyRQ    s    	c         C   s   t  j d j | | |   |  j j d | d | d | d | d |  j    } d j |  | _ t j | _	 | | _
 | | _ |  j j |  | _ | | _ | S(   s'   Install `pkgs` in environment `prefix`.s!   prefix: {}, pkgs: {}, dry-run: {}R   RA  t   dry_runRB  RC  s!   Installing packages on <b>{0}</b>(   R#   R   R   R?   R
  R   RF  R8  t   ACTION_INSTALLR<  RT  R   RG  RU  RA  (   R   R   RA  RT  RB  R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   install_packages2  s    			c         C   s   t  j d j | | |   |  j j d | d | d | d | d | d |  j    } d j |  | _ t j | _	 | | _
 | | _ |  j j |  | _ | | _ | S(	   s&   Update `pkgs` in environment `prefix`.s!   prefix: {}, pkgs: {}, dry-run: {}R   RA  RT  RB  t   all_RC  s   Updating packages on <b>{0}</b>(   R#   R   R   R?   t   updateR   RF  R8  t   ACTION_UPDATER<  RT  R   RG  RU  RA  (   R   R   RA  RT  RB  RW  R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   update_packagesH  s     				c      	   C   s   t  j d j | |   |  j j d | d | d | d |  j    } d j |  | _ t j | _	 | | _
 |  j j |  | _ | | _ | S(   s(   Remove `pkgs` from environment `prefix`.s   prefix: {}, pkgs: {}R   RA  RT  RC  s!   Removing packages from <b>{0}</b>(   R#   R   R   R?   RX   R   RF  R8  t   ACTION_REMOVER<  R   RG  RU  RA  (   R   R   RA  RT  R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   remove_packagesd  s    		c         C   s}   t  j d j | |   |  j j d | d |  } d j |  | _ t j | _ | | _	 |  j j
 |  | _ | | _ | S(   s,   Remove pip `pkgs` from environment `prefix`.s   prefix: {}, pkgs: {}R   RA  s!   Removing packages from <b>{0}</b>(   R#   R   R   R?   t
   pip_removeRF  R8  R[  R<  R   RG  RU  RA  (   R   R   RA  R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   remove_pip_packagest  s    		c            s  t  j d j | |   | t j k r1 t } nPi d d 6d d 6d d 6d d 6d d 6t ri t ri d n d	 d
 6d d 6d d 6} t } | r t	 | t
  r | d } n  | r| j d g   } | j d g   } |  j   y   f d   | D } Wn' t k
 r  f d   | D } n Xy   f d   | D } Wn' t k
 rc  f d   | D } n Xd d l m } i  } g  }	 x | D] }
 |
 | k r| | |
 d  } | j |
  } | r| | |
 d  n d } | r| | k r| | |
 <n  | s|	 j |
  qqqWxT | j   D]F \ } } | j |  } | r%| |  } | | k rkt } Pqkq%q%W|	 rt } qn  | S(   s?   Check if navigator is affected by the operation on (base/root).s   actions: {}, prefix: {}t   _licenses   1.6.14s   anaconda-clientt   chardett   pillowR   s   5.6s   5.9t   pyqtt   pyyamls   1.4.1t   qtpyi    t   LINKt   UNLINKc            s)   i  |  ] }   |    |  d   q S(   i    (    (   t   .0R   (   t
   split_cano(    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pys
   <dictcomp>  s   	 c            s1   i  |  ]' }   | d     | d   d  q S(   t	   dist_namei    (    (   Rg  R   (   Rh  (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pys
   <dictcomp>  s   	c            s)   i  |  ] }   |    |  d   q S(   i    (    (   Rg  R   (   Rh  (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pys
   <dictcomp>  s   	c            s1   i  |  ]' }   | d     | d   d  q S(   Ri  i    (    (   Rg  R   (   Rh  (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pys
   <dictcomp>  s   	i(   R   i   N(   R#   R   R   R  R   R   RJ   R   R%   t
   isinstanceR   R   Ru   t   AttributeErrort   distutils.versionR   R   R   R   (   R   t   actionsR   t	   conflictst   navigator_dependenciesRh   t   unlinkedt   lvt   downgraded_depst   removed_depsR   t	   u_pkg_vert   l_pkgt	   l_pkg_vert   down_dept   down_dep_versiont   nav_dep_version(    (   Rh  sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   check_navigator_dependencies  sh    	
	 c         C   s   t  j |   t   } |  rd |  k rg  } |  rt |  t t f  rxg |  D]_ } | j g  t j	 |  D]< } t j
 j t j
 j | |   rl t j
 j | |  ^ ql  qP Wxc | D]X } g  } y t j	 |  } Wn t k
 r n Xd | k r t j
 j |  | | <q q Wqn  | S(   s?   Return an ordered dictionary of all existing projects on paths.s   anaconda-project.ymlN(   R#   R   R    RJ   Rj  R   t   tuplet   extendR#  R  R$  R  R   R  R%  (   t   pathst   projectst   project_pathsR$  t   it   project_pathR  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   get_projects  s$    	A#c         C   s)  t  j |  i  } i  } g  | D] } t j j |  r  | ^ q  } x: | D]2 } t j |  } | rs | | | <qK d | | <qK Wt j j |  j	    s t j
 |  j	    n  xm | D]e } t j j |  \ } } t j j |  j	   |  }	 t |	 d   }
 t j | | |
  Wd QXq W| | f S(   s   Add license file callback.R  N(   R#   R   R#  R$  R  R_  t   read_licensesRJ   R  t   license_locationt   mkdirR   R   R  R  R  (   R   R}  t   valid_licensest   invalid_licensesR   R$  t   lict   headt   tailt   new_pathR  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   add_license  s"    +c         C   si   t  j d  |  j   } xI | D]A } y t j |  Wq  t k
 r` t  j d j |   q  Xq  Wd S(   s   Remove all found licenses.R:   s&   Could not remove license located at {}N(   R#   R   t   license_pathsR#  RX   R  t   warningR   (   t   clsR}  R$  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   remove_all_licenses  s    c      
   C   s1  t  j |   |  j t  } |  j d  } t |   } t j |  } Wd QXx3 t |  D]% \ } }  |  j d  | k r\ Pq\ q\ W| j |  } t | d   } t j	 | |  Wd QXt
 j j t
 j j |   \ } } t
 j j | t  }	 t
 j j |	 |  }
 t
 j j |	  sZy t
 j |	  WqZt k
 rVt  j d j |   qZXn  | g } t
 j j |
  ry5 t |
  # } t j |  } | j |  Wd QXWqt k
 rt  j d j |
   qXn  y, t |
 d   } t j	 | |  Wd QXWn' t k
 r,t  j d j |
   n Xd S(   s   Remove license callback.t   sigNR  s2   Could not create folder for removed licenses at {}s&   Could not remove license located at {}s%   Could not store removed license on {}(   R#   R   R   R   R  R  t   loadR7  R6  R  R#  R$  R   t   abspathR   R   R  R  R  R  R   R  R|  (   R  R$  R  R  t   licensesR  t   removed_licenseR  R  t   removed_foldert   removed_patht   removed_licensest   existing_removed_licenses(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   remove_license  sL    $	c   	      C   s   t  j |  g  } x|  j   D] } y t j |  } Wn- t k
 rh t  j d j |   g  } n Xx | D] } | j d  } | r | | k n t	 } | t
 k rp | rp |  j |  } | | d <| r d n d | d <| j d d  j   | d	 <| | t <| j |  qp qp Wq  W| S(
   s   Load license files.s#   Can't read licenses from folder {0}t   productt	   __valid__t   Validt   Invalidt
   __status__t   typet
   Enterpriset   __type__(   R#   R   R  R_  R  R  R  R   R   R   R   t   is_valid_licenseRH   R   R   (	   R  R  t   rest   license_pathR  R  t   product_namet   product_filtert   valid(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   load_licensesR  s(    


c   
      C   s*  t  s
 i  St j |  g  } xg t j | g   D]S } |  j d |  } g  | D]! } |  j | d t rO | ^ qO } | j |  q0 Wg  } g  } x: | D]2 }	 |  j	 |	  r | j
 |	  q | j
 |	  q Wt | d d   } t | d d   } | r| d }	 n | r | d }	 n i  }	 |	 S(   s%  
        Get stored license for a package.

        If several license found only the valid ones with the largest date
        is returned including expired and non expired licenses. Priority is
        given to nontrial over trial licenses, even if a trial has a larger
        date.
        R  t   check_expiredR  c         S   s   |  j  d  S(   Nt   end_date(   R   (   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR9     R:   c         S   s   |  j  d  S(   NR  (   R   (   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR9     R:   i(   t   LICENSE_PACKAGER#   R   R   R   R  R  R   R|  t   is_trial_licenseR   R   (
   R  R   t   all_licensesRU  R  t   lR  t   trial_valid_licensest   nontrial_valid_licensesR  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   get_package_licensen  s6    
!c         C   s+   t  s
 g  St j d  t j   t j   S(   s.   Return licenses paths founds on main location.R:   (   R  R#   R   R_  t   get_license_paths(   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s
    
c         C   s%   t  s
 g  St j d  t j   d S(   s   Return license main location.R:   i    (   R  R#   R   R_  t   get_license_dirs(   R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    c         C   sp   t  s
 t St j d j | |   |  j |  } | rJ |  j |  } n t } |  j |  } | oo | oo | S(   s,   Return wether a license dictionary is valid.s   {} check_expired={}(   R  R   R#   R   R   t   is_verified_licenset   is_expired_licenset   is_valid_vendor(   R  R  R  t   verifiedt   expiredt   valid_vendor(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    c         C   sx   t  s
 t St j |  t j |  } x< | D]4 } | j d  r- | j d  r- | j |  q- q- Wt	 t
 j |   S(   s#   Check that the license is verified.t   __(   R  R   R#   R   R"  t   deepcopyR   R  R6  R   R_  t   verify_license(   R  R  t   check_licenseR  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    c         C   s+   t  s
 t St j |  | d } | d k S(	   s*   Check if a license is from a valid vendor.t   vendors   Anaconda, Inc.s   Continuum Analytics, Inc.s   Continuum Analyticst   Anacondat	   continuumt   anaconda(   s   Anaconda, Inc.s   Continuum Analytics, Inc.s   Continuum AnalyticsR  R  R  (   R  R   R#   R   (   R  R  R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    
     c         C   s*   t  s
 t St j |  |  j |  d k S(   s    Check if the license is expired.i    (   R  R   R#   R   t   get_days_left(   R  R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    c         C   s3   t  s
 t St j |  | j d d  j   d k S(   s$   Check if a license is of trial type.R  R:   t   trial(   R  R   R#   R   R   RH   (   R  R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR    s    c         C   s%   t  s
 t St j |  |  j |  S(   s)   Check if a license is of enterprise type.(   R  R   R#   R   R  (   R  R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   is_enterprise_license  s    c         C   s   t  s
 d St j |  d } yJ t j | j d d   } | t j j   j	 } | d k  rf d } n  Wn t
 t f k
 r d } n X| r d | k r t d  } n  | S(   s*   Get the number of days left for a license.i    R  R:   t   inf(   R  R#   R   R_  t   date_from_stringR   R  R  t   todayt   dayst
   ValueErrort	   TypeErrort   float(   R  R  R  R  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR  	  s    
(N   t   __name__t
   __module__t   __doc__R   t   objectt   sig_metadata_updatedR   t   sig_repodata_updatedt   sig_repodata_erroredt	   sig_errort   VSCODE_DATAR>   R   R   R   R   R   R   R   R   R   RJ   R   R   t   staticmethodR  R  R  R  R  R  R  R  R>  Rw  R   Rh  R  Ri  R   R  R  R  R  R  R  R  R  R#  R.  R  R@  RH  RI  RP  RQ  RV  RZ  R\  R^  Rz  R  R  t   classmethodR  R  R  R  R  R  R   R  R  R  R  R  R  R  (    (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyR)   A   s   		
	b		1								)	 T-(=					(	2	 			!	 .					W	54
				c           C   s   t  d k r t   a  n  t  S(   s   Manager API threaded worker.N(   t   ANACONDA_APIRJ   R)   (    (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   AnacondaAPI	  s    c         C   s.   |  | | f GHt  j    |  j GHd GHd GHd S(   s#   Print information on test finished.N(    (    (   t   timet
   start_time(   R   R   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   finished(	  s    c         C   s   |  | f GHd S(   s'   Print information on downlaod finished.N(    (   R   R$  (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   download_finished0	  s    c         C   s	   |  GHd S(   s&   Print information on repodata updated.N(    (   t   repos(    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   repodata_updated5	  s    c          C   sn   d d l  m }  |    } t   } t } | j |  | j   } t j   | _ | j j	 t
  | j   d S(   s   Main local test.i(   t   qapplicationN(   t"   anaconda_navigator.utils.qthelpersR  R  R   R   R@  R  R  R   R   R  t   exec_(   R  Rl  t   apiR   R   (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt
   local_test:	  s    		t   __main__(U   R  t   collectionsR    Rl  R   R2  R"  R  R  R  R  R  R#  R  R  R%  R  R  t   qtpy.QtCoreR   R   R   R   t!   anaconda_navigator.api.client_apiR   t    anaconda_navigator.api.conda_apiR   t#   anaconda_navigator.api.download_apiR   t   anaconda_navigator.api.processR   R	   t"   anaconda_navigator.api.project_apiR
   t   anaconda_navigator.configR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   anaconda_navigator.staticR   R    R!   t   anaconda_navigator.utilsR"   R8  t   anaconda_navigator.utils.logsR#   t   anaconda_navigator.utils.miscR$   t"   anaconda_navigator.utils.py3compatR%   R&   R'   R(   R_  R   R  t   ImportErrorR   R)   RJ   R  R  R  R  R  R  R  (    (    (    sB   lib/python2.7/site-packages/anaconda_navigator/api/anaconda_api.pyt   <module>   sd   	"

        					