ó
>ò†[c           @  s“  d  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 m Z d d l	 m
 Z
 d d l 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 d d l m Z m Z e j d ƒ Z e d „ Z  d 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 S(   u,  

    anaconda upload CONDA_PACKAGE_1.bz2
    anaconda upload notebook.ipynb
    anaconda upload environment.yml

##### See Also

  * [Uploading a Conda Package](http://docs.anaconda.org/using.html#Uploading)
  * [Uploading a PyPI Package](http://docs.anaconda.org/using.html#UploadingPypiPackages)

iÿÿÿÿ(   t   unicode_literalsN(   t   glob(   t   exists(   t   input(   t   errors(   t
   bool_inputt   DEFAULT_CONFIGt
   get_configt   get_server_apit   upload_print_callback(   t   PACKAGE_TYPES(   t   upload_project(   t   detect_package_typet	   get_attrsu   binstar.uploadc         C  s+   t  j |  d ƒ } | r' | j ƒ  } n  | S(   Nu   unknown(   R
   t   gett   lower(   t   pkg_typet	   lowercaset   verbose_type(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   verbose_package_type'   s    c         C  s    |  j  | | | g  | | ƒ d  S(   N(   t   add_release(   t   aserver_apit   usernamet   package_namet   versiont   release_attrst   announce(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   create_release.   s    c         C  s¡   t  j d | | | ƒ t d ƒ s> t  j d ƒ t d ƒ ‚ n  t d ƒ } t  j d ƒ t d t ƒ } | r{ t d ƒ } n d	 } |  j | | | g  | | ƒ d  S(
   Nu%   The release "%s/%s/%s" does not existu    Would you like to create it now?u   good-byeiÿÿÿÿu*   Enter a short description of the release:
u4   Announcements are emailed to your package followers.u@   Would you like to make an announcement to the package followers?u   Markdown Announcement:
u    (   t   loggert   infoR   t
   SystemExitR   t   FalseR   (   R   R   R   R   R   t   descriptiont   make_announcementR   (    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   create_release_interactive2   s    c         C  sw   | j  r | j  } n^ t j d ƒ t |  ƒ } | d k rc d |  } t j | ƒ t j | ƒ ‚ n  t j d | ƒ | S(   ud   
    return the file type from the inspected package or from the
    -t/--package-type argument
    u   Detecting file type...u_   Could not detect package type of file %r please specify package type with option --package-typeu   File type is "%s"N(   t   package_typeR   R   R   t   Nonet   errorR   t   BinstarError(   t   filenamet   argsR#   t   message(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   determine_package_typeE   s    	
c         C  sÊ   |  j  r„ d | k rx | d j ƒ  |  j  j ƒ  k rx d j |  j  j ƒ  | d j ƒ  ƒ } t j | ƒ t j | ƒ ‚ n  |  j  } nB d | k r¼ d | f } t j | ƒ t j | ƒ ‚ n  | d } | S(   Nu   nameuW   Package name on the command line " {}" does not match the package name in the file "{}"uR   Could not detect package name for package type %s, please use the --package option(   t   packageR   t   formatR   R%   R   R&   (   R(   t   package_attrsR'   R#   t   msgR   R)   (    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   get_package_name[   s    	+
c         C  s[   |  j  r |  j  } nB d | k rM d | f } t j | ƒ t j | ƒ ‚ n  | d } | S(   Nu   versionuU   Could not detect package version for package type %s, please use the --version option(   R   R   R%   R   R&   (   R(   R   R#   R   R)   (    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   get_versionn   s    	
c   	      C  s  y |  j  | | ƒ SWnü t j k
 r| j s_ d | | f } t j | ƒ t j | ƒ ‚ q| j rt | j } nB d | k r¬ d | f } t j | ƒ t j | ƒ ‚ n  | d } | j	 } |  j
 | | | | j d ƒ d | d | d | j d ƒ d	 | j d
 ƒ d | ƒSn Xd  S(   Nu‡   Anaconda repository package %s/%s does not exist. Please run "anaconda package --create" to create this package namespace in the cloud.u   summaryuU   Could not detect package summary for package type %s, please use the --summary optionu   licenset   publict   attrst   license_urlu   license_urlt   license_familyu   license_familyR#   (   R+   R   t   NotFoundt   auto_registerR   R%   t	   UserErrort   summaryR&   t   privatet   add_packageR   (	   R   R(   R   R   R-   R#   R)   R8   R1   (    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyR:   z   s4    		

c         C  sp   y |  j  | | | ƒ WnR t j k
 rk | j d k rR t |  | | | | ƒ ql t |  | | | | ƒ n Xd  S(   Nu   interactive(   t   releaseR   R5   t   modeR"   R   (   R   R(   R   R   R   R   (    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyR   Ÿ   s    c         C  sÔ   y |  j  | | | | d ƒ Wn t j k
 r5 t SX| j d k rv t j d | d ƒ |  j | | | | d ƒ n  | j d k rÐ t d | d ƒ rµ |  j | | | | d ƒ qÐ t j	 d | d ƒ t
 Sn  d  S(   Nu   basenameu   forceu+   Distribution "%s" already exists. Removing.u   interactiveu?   Distribution "%s" already exists. Would you like to replace it?u   Not replacing distribution "%s"(   t   distributionR   R5   R   R<   R   t   warningt   remove_distR   R   t   True(   R   R(   R   R   R   t
   file_attrs(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   remove_existing_fileª   s    c         C  sá  t  j d j t | ƒ ƒ ƒ y" t | |  d | ƒ\ } } } WnT t k
 r” d j |  t | ƒ ƒ } t  j | ƒ | j r‚ ‚  n  t j	 | ƒ ‚ n X| j
 r² | j
 | d d <n  t | | |  | ƒ }	 t | | | ƒ }
 t  j d |	 ƒ t | | | |	 | | ƒ } | j d g  ƒ } | rx| | k rxd j t | rA| d	 n d
 ƒ |	 t | ƒ ƒ } t  j | ƒ t j	 | ƒ ‚ n  t  j d |
 ƒ t | | | |	 |
 | ƒ | j d | ƒ } t |  d ƒ } t  j d | |	 |
 | d ƒ t | | | |	 |
 | ƒ rd  SyZ | j | |	 |
 | d | | | j d | j d ƒ d | d d | j d t | ƒ ƒ} WnY t j k
 r¶i  } | j d k r¦t  j d | |	 |
 | d ƒ ‚  q·t  j d ƒ n X| rÍt  j d ƒ n  |	 | g SWd  QXd  S(   Nu#   Extracting {} attributes for uploadt   parser_argsu=   Trouble reading metadata from {}. Is this a valid {} package?u   attrsu   binstar_buildu   Creating package "%s"u   package_typesuC   You already have a {} named '{}'. Use a different name for this {}.i    u    u   Creating release "%s"u   binstar_package_typeu   rbu   Uploading file "%s/%s/%s/%s"u   basenamet   dependenciesu   dependenciesR2   t   channelst   callbacku   skipuy   Distribution already exists. Please use the -i/--interactive or --force or --skip options or `anaconda remove %s/%s/%s/%su.   Distribution already exists. Skipping upload.
u   Upload complete
(   R   R   R,   R   R   t	   ExceptionR%   t   show_tracebackR   R&   t   build_idR/   R0   R:   R   R   t   popt   openRB   R$   t   uploadR    t   labelsR	   t   ConflictR<   (   R'   R#   R   R   R(   R-   R   RA   R)   R   R   R+   t   package_typest   binstar_package_typet   fdt   upload_info(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   upload_package¼   sZ    "			c   
      C  sè   t  j ƒ  } x |  D]w } t j d | ƒ t j d d d | d | g d t j d t j ƒ} | j ƒ  \ } } | r t j d | | ƒ q q Wg  } xM t	 j
 | ƒ D]< \ } } }  x* |  D]" }	 | j t	 j j | |	 ƒ ƒ qº Wq¤ W| S(	   Nu   Running conda convert on "%s"u   conda-convertu   -pu   allu   -ot   stdoutt   stderru.   Couldn't generate platform packages for %s: %s(   t   tempfilet   mkdtempR   R   t
   subprocesst   Popent   PIPEt   communicateR>   t   ost   walkt   appendt   patht   join(
   t   filest   tmpdirt   filepatht   processRT   RU   t   resultR_   t   dirsR'   (    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   get_convert_files   s    $c         C  s>  t  d |  j ƒ } t d |  j d |  j d | ƒ } | j ƒ  t } |  j rX |  j } n5 d | k rq | d } n t } | j ƒ  } | d } t j	 d | ƒ | rù y | j | ƒ Wqù t
 j k
 rõ d j | ƒ } t j | ƒ t
 j | ƒ ‚ qù Xn  g  } g  } g  |  j D] }	 |	 D] }
 |
 ^ qq} |  j rJ| t | ƒ 7} n  xk| D]c} t | ƒ s‘d j | ƒ } t j | ƒ t
 j | ƒ ‚ n t j	 d	 | ƒ t | |  ƒ } | d
 k rØ| j t | |  | ƒ ƒ qQ| d k rM|  j d k rMy t j t | ƒ t j ƒ WqMt k
 rI} t j d | | ƒ t j	 d ƒ qQqMXn  t | d | d | d | d |  ƒ} | d  k	 rQt | ƒ d k rQ| \ } } | r´| j | ƒ q´qQqQWxO | D]G \ } } | j d d | | f ƒ } t j	 d j t  | ƒ | ƒ ƒ q¿Wx- | D]% \ } } t j	 d j | | ƒ ƒ qWd  S(   Nt   sitet   tokent   configu   upload_useru   loginu   Using "%s" as upload usernameu   User "{}" does not existu   File "{}" does not existu   Processing '%s'u   projectu   ipynbu   forceu   Invalid notebook file '%s': %su&   Use --force to upload the file anywaysR#   R   R   R(   i   u   urlu   https://anaconda.org/%s/%su   {} located at:
{}
u   Project {} uploaded to {}.
(!   R   Rh   R   Ri   t   check_serverR@   t   userR   R   R   R   R5   R,   R%   R&   Ra   t   allRg   R   R*   R^   R   R<   t   nbformatt   readRK   t
   NO_CONVERTRG   RS   R$   t   lenR   R   (   R(   Rj   R   t   validate_usernameR   Rl   R)   t   uploaded_packagest   uploaded_projectst   fglobt   fRa   R'   R#   R%   t   package_infot   _packaget   _upload_infoR+   RR   t   package_urlt   project_namet   url(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   main  sn    !
	
)	
	#c         C  s0   t  j d k r% d |  k r% t |  ƒ S|  g Sd  S(   Nu   ntu   *(   R\   t   nameR   (   t   item(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   windows_globc  s    
c   	      C  s=  d } |  j  d d t j d | d | d t ƒ} | j d d d	 d d
 d g  d t ƒd } | j d d d d d g  d d d | j d d d d ƒ d d ƒ| j d d d d d d d | j d d d d ƒ ƒ| j d d d d d  ƒ| j d! d" d d# ƒ| j d$ d d% d d  ƒ| j d& ƒ } | j d' d( d d) ƒ| j d* d+ d d, ƒ| j d- d. d d/ ƒt j	 ƒ  } | j
 d0 ƒ | j
 d1 ƒ d2 j t | j ƒ  ƒ ƒ } | j d3 d4 d d5 j | ƒ ƒ| j d6 d7 d d8 ƒ| j d9 d d: ƒ| j d; d d< d d  ƒ| j ƒ  } | j d= d d> d d? d d@ ƒ| j dA d d> d d  d dB ƒ| j dC t j d> t ƒ ƒ | j dD d dE ƒ| j ƒ  } | j dF dG d dH d dI d dJ dK dL ƒ| j dM dN d dO d dH d dJ dK dP ƒ| j dQ d dR d dH d dJ dK dS ƒ| j dT d dU d dH d dJ dK dV ƒ| j dW t ƒ d  S(X   Nu+   Upload packages to your Anaconda repositoryu   uploadt   formatter_classt   helpR    t   epilogu   filest   nargsu   +u   Distributions to uploadt   defaultt   typeu•   {deprecation}Add this file to a specific {label}. Warning: if the file {label}s do not include "main", the file will not show up in your user {label}u   -cu	   --channelt   actionu   appendt   destu   labelst   deprecationu   [DEPRECATED]
t   labelu   channelt   metavaru   CHANNELSu   -lu   --labelu    u   labelu   --no-progressu   Don't show upload progressu
   store_trueu   -uu   --useru:   User account or Organization, defaults to the current useru   --alluH   Use conda convert to generate packages for all platforms and upload themu   metadata optionsu   -pu	   --packageu1   Defaults to the package name in the uploaded fileu   -vu	   --versionu4   Defaults to the package version in the uploaded fileu   -su	   --summaryu   Set the summary of the packageu   condau   pypiu   , u   -tu   --package-typeu2   Set the package type [{0}]. Defaults to autodetectu   -du   --descriptionu   description of the file(s)u   --thumbnailu   Notebook's thumbnail imageu	   --privateu&   Create the package with private accessu   --no-registeru   auto_registeru   store_falseu9   Don't create a new package namespace if it does not existu
   --registeru3   Create a new package namespace if it does not existR6   u
   --build-idu,   Anaconda repository Build ID (internal only)u   -iu   --interactiveu   store_constu5   Run an interactive prompt if any packages are missingu   modet   constu   interactiveu   -fu   --failu5   Fail if a package or release does not exist (default)u   failu   --forceu+   Force a package upload regardless of errorsu   forceu   --skip-existingu8   Skip errors on package batch upload if it already existsu   skipR}   (   t
   add_parsert   argparset   RawDescriptionHelpFormattert   __doc__t   add_argumentR€   R,   t   add_argument_groupR
   t   copyRJ   R`   t   listt   keyst   add_mutually_exclusive_groupt   set_defaultsR   R   R@   R}   (	   t
   subparsersR    t   parsert
   label_helpt   mgroupt   pkgst	   pkg_typest   register_groupt   group(    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyR   j  sZ    		%!(/   R   t
   __future__R    RŽ   RV   t   loggingR\   RX   R   t   os.pathR   Rn   t	   six.movesR   t   binstar_clientR   t   binstar_client.utilsR   R   R   R   R	   t   binstar_client.utils.configR
   t   binstar_client.utils.projectsR   t   binstar_client.utils.detectR   R   t	   getLoggerR   R@   R   R$   R   R"   R*   R/   R0   R:   R   RB   RS   Rg   R}   R€   R   (    (    (    s]   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/upload.pyt   <module>   s<   (					%			D		M	