ó
;c›]c           @  s8  d  Z  d d l m Z d d l Z d d l Z d d l m Z d d l Z d d l Z d d l	 m
 Z
 d d l m Z d d	 g Z d
 g e d „ Z d „  Z d
 g d „ Z d „  Z e d k r4e e j ƒ d k ró e j d d k ró e ƒ  q4e e j ƒ d k r%e j d d k r%e ƒ  q4e d ƒ ‚ n  d S(   s=    
Console scripts and associated helper methods for imageio.
iÿÿÿÿ(   t   print_functionN(   t   pathi   (   t   plugins(   t   utilt   avbint	   freeimaget   allc         C  s·   |  j  d ƒ r t }  n  |  j ƒ  t d j d j |  ƒ ƒ ƒ | rS t j ƒ  } n d } xW |  D]O } | t k r d j | ƒ } t	 | ƒ ‚ n  t
 t | ƒ } | j d | ƒ q` Wd S(   s•   Download binary dependencies of plugins
    
    This is a convenience method for downloading the binaries
    (e.g. for freeimage) from the imageio-binaries
    repository.
    
    Parameters
    ----------
    plugin_names: list
        A list of imageio plugin names. If it contains "all", all
        binary dependencies are downloaded.
    package_dir: bool
        If set to `True`, the binaries will be downloaded to the
        `resources` directory of the imageio package instead of
        to the users application data directory. Note that this
        might require administrative rights if imageio is installed
        in a system directory.
    R   s   Ascertaining binaries for: {}.s   , s-   Plugin {} not registered for binary download!t	   directoryN(   t   countt   PLUGINS_WITH_BINARIESt   sortt   printt   formatt   joinR   t   resource_package_dirt   Nonet	   Exceptiont   getattrR   t   download(   t   plugin_namest   package_dirR   t   plgt   msgt   mod(    (    s/   lib/python2.7/site-packages/imageio/__main__.pyt   download_bin   s    	
c       
   C  sÀ   d }  d d } d d d } d d d	 } t  j d
 |  d | d t  j ƒ } | j d d t d d d d d | ƒ| j d d d d d d t d | ƒ| j ƒ  } t d | j d | j	 ƒ d S(   s-    Argument-parsing wrapper for `download_bin` s#   Download plugin binary dependenciess.   Plugin name for which to download the binary. s5   If no argument is given, all binaries are downloaded.s/   Download the binaries to the package directory s3   (default is the users application data directory). s)   This might require administrative rights.s
   examples:
s     imageio_download_bin all
s     imageio_download_bin avbin
t   descriptiont   epilogt   formatter_classt   plugint   typet   nargst   *t   defaultR   t   helps   --package-dirt   destR   t   actiont
   store_trueR   N(
   t   argparset   ArgumentParsert   RawDescriptionHelpFormattert   add_argumentt   strt   Falset
   parse_argsR   R   R   (   R   t   phelpt   dhelpt   example_textt   parsert   args(    (    s/   lib/python2.7/site-packages/imageio/__main__.pyt   download_bin_mainA   s$    	%c   
      C  s:  |  j  d ƒ r t }  n  t d j d j |  ƒ ƒ ƒ t j ƒ  } x8 |  D]0 } | t k rG d j | ƒ } t | ƒ ‚ qG qG Wg  } x{ | D]s } xj t j	 | ƒ D]Y } | |  k rž t
 j | | ƒ } y t j | ƒ Wq÷ t k
 ró | j | ƒ q÷ Xqž qž Wqˆ W| r6d j | ƒ } d j | ƒ d }	 t |	 ƒ ‚ n  d S(	   s   Remove binary dependencies of plugins
    
    This is a convenience method that removes all binaries
    dependencies for plugins downloaded by imageio.
    
    Notes
    -----
    It only makes sense to use this method if the binaries
    are corrupt.
    R   s   Removing binaries for: {}.s   , s-   Plugin {} not registered for binary download!t   ,s-   These plugins files could not be removed: {}
s9   Make sure they are not used by any program and try again.N(   R   R	   R   R   R   R   t   resource_dirsR   t   ost   listdirt   opt   shutilt   rmtreet   append(
   R   t   rdirsR   R   t   not_removedt   rdt   rsubt   plgdirt   nrst   msg2(    (    s/   lib/python2.7/site-packages/imageio/__main__.pyt
   remove_binc   s,    	c       
   C  s„   d }  d d } d d d } t  j d |  d | d	 t  j ƒ } | j d
 d t d d d d d | ƒ| j ƒ  } t d | j ƒ d S(   s+    Argument-parsing wrapper for `remove_bin` s!   Remove plugin binary dependenciess,   Plugin name for which to remove the binary. s2   If no argument is given, all binaries are removed.s
   examples:
s     imageio_remove_bin all
s     imageio_remove_bin avbin
R   R   R   R   R   R   R   R    R   R!   R   N(   R%   R&   R'   R(   R)   R+   RA   R   (   R   R,   R.   R/   R0   (    (    s/   lib/python2.7/site-packages/imageio/__main__.pyt   remove_bin_mainŽ   s    	%t   __main__R   RA   s   Invalid use of the imageio CLI(   t   __doc__t
   __future__R    R%   R4   R   R6   R7   t   syst    R   t   coreR   R	   R*   R   R1   RA   RB   t   __name__t   lent   argvt   RuntimeError(    (    (    s/   lib/python2.7/site-packages/imageio/__main__.pyt   <module>   s&   ,	"+	(
(
