
-Tc           @   s;  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l m Z y d d l m Z Wn! e k
 r d d l m Z n Xy d d l m Z Wn e k
 r d Z n Xd Z d Z d   Z d  d	  Z d
   Z d e j f d     YZ e
 j d    Z d   Z e e e j d d  Z d   Z  d   Z! d   Z" e" e! _# d   Z$ d   Z% e% e$ _# d   Z& d   Z' e' e& _# d   Z( d   e( _# d   Z) e e e j d e) d  Z* d   Z+ d   Z, d   Z- e. d k r7e j/ e-    n  d S(!   s  Bootstrap setuptools installation

To use setuptools in your package's setup.py, include this
file in the same directory and add this to the top of your setup.py::

    from ez_setup import use_setuptools
    use_setuptools()

To require a specific version of setuptools, set a download
mirror, or use an alternate download directory, simply supply
the appropriate options to ``use_setuptools()``.

This file can also be run as a script to install or upgrade setuptools.
iN(   t   log(   t   urlopen(   t	   USER_SITEs   4.0.1s5   https://pypi.python.org/packages/source/s/setuptools/c          G   s#   t  j f |  }  t j |   d k S(   s/   
    Return True if the command succeeded.
    i    (   t   syst
   executablet
   subprocesst   call(   t   args(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   _python_cmd*   s    c         C   sT   t  |   B t j d  t d d |  sJ t j d  t j d  d SWd  QXd  S(   Ns   Installing Setuptoolss   setup.pyt   installs-   Something went wrong during the installation.s   See the error message above.i   (   t   archive_contextR    t   warnR   (   t   archive_filenamet   install_args(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   _install2   s    c      
   C   sk   t  |  + t j d |  t d d d d |  Wd  QXt j |   t j j |   sg t d   n  d  S(   Ns   Building a Setuptools egg in %ss   setup.pys   -qt	   bdist_eggs
   --dist-dirs   Could not build the egg.(   R
   R    R   R   t   ost   patht   existst   IOError(   t   eggR   t   to_dir(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt
   _build_egg=   s    t   ContextualZipFilec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sL   
    Supplement ZipFile class to support context manager for Python 2.6
    c         C   s   |  S(   N(    (   t   self(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt	   __enter__M   s    c         C   s   |  j    d  S(   N(   t   close(   R   t   typet   valuet	   traceback(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   __exit__P   s    c         O   s8   t  t j d  r" t j | |   St t |   j |   S(   sI   
        Construct a ZipFile or ContextualZipFile as appropriate
        R   (   t   hasattrt   zipfilet   ZipFilet   superR   t   __new__(   t   clsR   t   kwargs(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyR#   S   s    (   t   __name__t
   __module__t   __doc__R   R   R#   (    (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyR   H   s   		c         c   s   t  j   } t j d |  t j   } zt t j |  t |    } | j   Wd  QXt j	 j
 | t j |  d  } t j |  t j d |  d  VWd  t j |  t j |  Xd  S(   Ns   Extracting in %si    s   Now working in %s(   t   tempfilet   mkdtempR    R   R   t   getcwdt   chdirR   t
   extractallR   t   joint   listdirt   shutilt   rmtree(   t   filenamet   tmpdirt   old_wdt   archivet   subdir(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyR
   \   s    "	c         C   s   t  j j | d |  t j d t j d f  } t  j j |  sj t |  | | |  } t | | |  n  t j j d |  d t j	 k r t j	 d =n  d d  l
 } | | _ d  S(   Ns   setuptools-%s-py%d.%d.eggi    i   t   pkg_resourcesi(   R   R   R.   R   t   version_infoR   t   download_setuptoolsR   t   insertt   modulest
   setuptoolst   bootstrap_install_from(   t   versiont   download_baseR   t   download_delayR   R5   R<   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   _do_downloadr   s    !	i   c   	      C   s!  t  j j |  } d	 } t t j  j |  } y d d  l } Wn! t k
 rc t	 |  | | |  SXy | j
 d |   d  SWn | j k
 r t	 |  | | |  S| j k
 r} | r t j d  j d | d |   } t j j |  t j d  n  ~ t j d =t	 |  | | |  SXd  S(
   NR7   R<   is   setuptools>=sO  
                The required version of setuptools (>={version}) is not available,
                and can't be installed while this script is running. Please
                install a more recent version first, using
                'easy_install -U setuptools'.

                (Currently using {VC_err.args[0]!r})
                t   VC_errR>   i   (   s   pkg_resourcess
   setuptools(   R   R   t   abspatht   setR   R;   t   intersectionR7   t   ImportErrorRA   t   requiret   DistributionNotFoundt   VersionConflictt   textwrapt   dedentt   formatt   stderrt   writet   exit(	   R>   R?   R   R@   t   rep_modulest   importedR7   RB   t   msg(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   use_setuptools   s(    c         C   sT   y t  j |   Wn< t  j k
 rO t j | t j  rI t j |  n    n Xd S(   sm   
    Run the command to download target. If the command fails, clean up before
    re-raising the error.
    N(   R   t
   check_callt   CalledProcessErrorR   t   accesst   F_OKt   unlink(   t   cmdt   target(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   _clean_check   s    c         C   s?   t  j j |  } d t   } d d | g } t | |  d S(   s   
    Download the file at url to target using Powershell (which will validate
    trust). Raise an exception if the command cannot complete.
    s   [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; (new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)t
   powershells   -CommandN(   R   R   RC   t   varsR[   (   t   urlRZ   t   ps_cmdRY   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   download_file_powershell   s    
	c       
   C   sy   t  j   d k r t Sd d d g }  t t j j d  9 } y t j |  d | d | Wn t	 k
 rn t SXWd  QXt
 S(   Nt   WindowsR\   s   -Commands	   echo testt   wbt   stdoutRM   (   t   platformt   systemt   Falset   openR   R   t   devnullR   RT   t	   Exceptiont   True(   RY   Rh   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   has_powershell   s    c         C   s&   d |  d d | g } t  | |  d  S(   Nt   curls   --silents   --output(   R[   (   R^   RZ   RY   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   download_file_curl   s    c       
   C   s`   d d g }  t  t j j d  9 } y t j |  d | d | Wn t k
 rU t SXWd  QXt S(   NRl   s	   --versionRb   Rc   RM   (	   Rg   R   R   Rh   R   RT   Ri   Rf   Rj   (   RY   Rh   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   has_curl   s    c         C   s&   d |  d d | g } t  | |  d  S(   Nt   wgets   --quiets   --output-document(   R[   (   R^   RZ   RY   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   download_file_wget   s    c       
   C   s`   d d g }  t  t j j d  9 } y t j |  d | d | Wn t k
 rU t SXWd  QXt S(   NRo   s	   --versionRb   Rc   RM   (	   Rg   R   R   Rh   R   RT   Ri   Rf   Rj   (   RY   Rh   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   has_wget   s    c         C   sS   t  |   } z | j   } Wd | j   Xt | d   } | j |  Wd QXd S(   sa   
    Use Python to download the file, even though it cannot authenticate the
    connection.
    NRb   (   R   t   readR   Rg   RN   (   R^   RZ   t   srct   datat   dst(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   download_file_insecure   s    c           C   s   t  S(   N(   Rj   (    (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   <lambda>   s    c          C   s/   t  t t t f }  d   |  D } t | d   S(   Nc         s   s!   |  ] } | j    r | Vq d  S(   N(   t   viable(   t   .0t   dl(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pys	   <genexpr>  s    (   R`   Rm   Rp   Rv   t   nextt   None(   t   downloaderst   viable_downloaders(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   get_best_downloader   s    	c   	      C   s   t  j j |  } d |  } | | } t  j j | |  } t  j j |  sv t j d |  |   } | | |  n  t  j j |  S(   s  
    Download setuptools from a specified location and return its filename

    `version` should be a valid setuptools version number that is available
    as an egg for download under the `download_base` URL (which should end
    with a '/'). `to_dir` is the directory where the egg will be downloaded.
    `delay` is the number of seconds to pause before an actual download
    attempt.

    ``downloader_factory`` should be a function taking no arguments and
    returning a function for downloading a URL to a target.
    s   setuptools-%s.zips   Downloading %s(   R   R   RC   R.   R   R    R   t   realpath(	   R>   R?   R   t   delayt   downloader_factoryt   zip_nameR^   t   savetot
   downloader(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyR9   	  s    

	c         C   s   |  j  r d g Sg  S(   sT   
    Build the arguments to 'python setup.py install' on the setuptools package
    s   --user(   t   user_install(   t   options(    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   _build_install_args"  s    c          C   s   t  j   }  |  j d d d d d d t d d |  j d	 d d
 d d d t d d |  j d d d d d d d   d t d d |  j d d d d t |  j   \ } } | S(   s,   
    Parse the command line for options
    s   --usert   destR   t   actiont
   store_truet   defaultt   helps;   install in user site package (requires Python 2.6 or later)s   --download-baseR?   t   metavart   URLs=   alternative URL from where to download the setuptools packages
   --insecureR   t   store_constt   constc           S   s   t  S(   N(   Rv   (    (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyRw   6  s    s'   Use internal, non-validating downloaders	   --versions!   Specify which version to download(   t   optparset   OptionParsert
   add_optionRf   t   DEFAULT_URLR   t   DEFAULT_VERSIONt
   parse_args(   t   parserR   R   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   _parse_args(  s"    c          C   s@   t    }  t d |  j d |  j d |  j  } t | t |    S(   s-   Install or upgrade setuptools and EasyInstallR>   R?   R   (   R   R9   R>   R?   R   R   R   (   R   R5   (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   mainA  s    			t   __main__(    (0   R(   R   R0   R   R)   R    R   R   Rd   RJ   t
   contextlibt	   distutilsR    t   urllib.requestR   RF   t   urllib2t   siteR   R|   R   R   R   R   R   R!   R   t   contextmanagerR
   RA   t   curdirRS   R[   R`   Rk   Rx   Rm   Rn   Rp   Rq   Rv   R   R9   R   R   R   R&   RO   (    (    (    s6   /home/pi/europen/VLHKO/Adafruit_Python_DHT/ez_setup.pyt   <module>   sb   
																	
			
