ó
mÜJ]c           @` sC  d  Z  d d l m Z m Z m Z m Z d d l Z e j e ƒ 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 d d l m Z d d	 l m Z m Z m Z d
 Z d Z d Z d „  Z d d d „ Z d d d „ Z  e j d ƒ j! e j" ƒ e j d ƒ j! e j" ƒ e j d ƒ j! e j" ƒ d S(   u(    Provide tools for interacting with S3

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   join(   t   NoAuthHandlerFound(   t   Key(   t   __version__(   t   JOB_ID(   t   tracet   okt   failu   ci.bokeh.orgu   https://ci.bokeh.org/u   connect_to_s3u   upload_file_to_s3u   upload_file_to_s3_by_job_idc          C` s^   y' d d l  m }  t j d |  ƒ  ƒ SWn0 t k
 rY t d ƒ t d ƒ t d ƒ d SXd S(   uA    Return the connection object or None if connection failed.

    i    (   t   OrdinaryCallingFormatt   calling_formatu1   Upload was requested but could not connect to S3.uM   This is expected if you are an external contributor submitting a PR to Bokeh.ue   This could also happen if S3 credentials are not available on the machine where this test is running.N(   t   boto.s3.connectionR   t   botot
   connect_s3R   R   t   None(   R   (    (    s5   lib/python2.7/site-packages/bokeh/_testing/util/s3.pyt   connect_to_s36   s    


u	   text/htmlc         C` s%   t  d t |  ƒ } t |  | | | ƒ S(   uH    Upload a file to the ci.bokeh.org s3 bucket under a travis/JOB_ID

    u   travis(   R   R   t   upload_file_to_s3(   t	   file_patht   content_typet   extra_messaget   s3_filename(    (    s5   lib/python2.7/site-packages/bokeh/_testing/util/s3.pyt   upload_file_to_s3_by_job_idD   s    c         C` s  t  ƒ  } | d k	 } y( t |  d ƒ  } | j ƒ  } Wd QXWn% t k
 rd t d |  ƒ t } n Xt j d ƒ r‘ t d ƒ t d ƒ t } n  | r| j	 t
 ƒ } t | | ƒ }	 |	 j d | ƒ |	 j | d d	 ƒt t | ƒ }
 | d k	 r
t d
 | |
 f ƒ qt d |
 ƒ n  d S(   u2    Upload a file to the ci.bokeh.org s3 bucket

    u   rbNu3   Upload was requested but file %s was not available.u   -dirtyu:   Uploads are not permitted when working directory is dirty.u9   Make sure that __version__ doesn't contain -dirty suffix.u   Content-Typet   policyu   public-readu   %s | Access upload at: %su   Access upload at: %s(   R   R   t   opent   readt   OSErrorR   t   FalseR   t   endswitht
   get_buckett	   S3_BUCKETt   S3Keyt   set_metadatat   set_contents_from_stringR   t   S3_URLR
   R	   (   R   R   R   R   t   connt   uploadt   ft   contentst   buckett   keyt   url(    (    s5   lib/python2.7/site-packages/bokeh/_testing/util/s3.pyR   L   s*    	


	u   botou   urllib3.connectionpoolu(   requests.packages.urllib3.connectionpool(   u   connect_to_s3u   upload_file_to_s3u   upload_file_to_s3_by_job_id(#   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logt   os.pathR   R   t   boto.exceptionR   t   boto.s3.keyR   R!   t   bokeh._testing.util.gitR   t   bokeh._testing.util.travisR   t   bokeh.util.terminalR	   R
   R   R    R$   t   __all__R   R   R   R   t   setLevelt   INFO(    (    (    s5   lib/python2.7/site-packages/bokeh/_testing/util/s3.pyt   <module>	   s*   "  	*