σ
mάJ]c           @` sΑ   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 Z d d l m Z d d l m Z d d l m Z m Z d Z d
 e f d     YZ d S(   uI    Abstract base class for subcommands that output to a file (or stdout).

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   abstractmethod(   t   decode_utf8i   (   t
   Subcommand(   t!   build_single_handler_applicationst   dieu   FileOutputSubcommandt   FileOutputSubcommandc           B` se   e  Z d  Z d Z e d    Z e d    Z d   Z d   Z	 d   Z
 d   Z e d    Z RS(	   uG    Abstract subcommand to output applications as some type of file.

    c      
   C` s)   d t  d d d d d d | d d	  f S(
   uΟ   Returns a positional arg for ``files`` to specify file inputs to
        the command.

        Subclasses should include this to their class ``args``.

        Example:

            .. code-block:: python

                class Foo(FileOutputSubcommand):

                    args = (

                        FileOutputSubcommand.files_arg("FOO"),

                        # more args for Foo

                    ) + FileOutputSubcommand.other_args()

        u   filest   metavaru   DIRECTORY-OR-SCRIPTt   nargsu   +t   helpu1   The app directories or scripts to generate %s fort   defaultN(   t   dictt   None(   t   clst   output_type_name(    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyt	   files_arg;   s
    	
c      
   C` sI   d t  d d d d d t d d	  f d
 t  d d d t j d d  f f S(   u.   Return args for ``-o`` / ``--output`` to specify where output
        should be written, and for a ``--args`` to pass on any additional
        command line args to the subcommand.

        Subclasses should append these to their class ``args``.

        Example:

            .. code-block:: python

                class Foo(FileOutputSubcommand):

                    args = (

                        FileOutputSubcommand.files_arg("FOO"),

                        # more args for Foo

                    ) + FileOutputSubcommand.other_args()

        u   -ou   --outputR
   u   FILENAMEt   actionu   appendt   typeR   u1   Name of the output file or - for standard output.u   --argsu   COMMAND-LINE-ARGSR   uM   Any command line arguments remaining are passed on to the application handler(   u   -ou   --output(   R   t   strt   argparset	   REMAINDER(   R   (    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyt
   other_argsX   s    				c         C` s-   | d k r d } n
 | d } d | | f S(   u
   

        u   /u   indexi   u   %s.%s(    (   t   selft   routet   extt   base(    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyt   filename_from_route~   s    	
c   	      ` s    f d     j  D } t   j  |  }   j d k rC g  } n t   j  } t |  t |  k r t d t |  t |  f  n  xr | j   D]d \ } } | j   } t |  d k rΦ | j	 d  } n |  j
 | |  j  } |  j   | |  q Wd S(   u
   

        c         ` s   i  |  ] }   j  |  q S(    (   t   args(   t   .0t   f(   R   (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pys
   <dictcomp>   s   	 uC   --output/-o was given too many times (%d times for %d applications)i    N(   t   filesR   t   outputR   t   listt   lenR   t   itemst   create_documentt   popR   t	   extensiont
   write_file(	   R   R   t   argvst   applicationst   outputsR   t   appt   doct   filename(    (   R   sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyt   invoke   s    	c         C` s|   |  j  | |  } | d k r1 t t |   n4 t j | d d d  } | j t |   Wd QX|  j | | |  d S(   u
   

        u   -u   wt   encodingu   utf-8N(   t   file_contentst   printR   t   iot   opent   writet   after_write_file(   R   R   R/   R.   t   contentst   file(    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyR)   £   s    c         C` s   d S(   u
   

        N(    (   R   R   R/   R.   (    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyR7   °   s    c         C` s   t  d   d S(   uc    Subtypes must override this to return the contents of the output file for the given doc.

        u   file_contentsN(   t   NotImplementedError(   R   R   R.   (    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyR2   Ά   s    N(   t   __name__t
   __module__t   __doc__R   R(   t   classmethodR   R   R   R0   R)   R7   R   R2   (    (    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyR	   4   s   &				(   u   FileOutputSubcommand(   R=   t
   __future__R    R   R   R   t   loggingt	   getLoggerR;   t   logt   abcR   R   R4   t   bokeh.util.stringR   t
   subcommandR   t   utilR   R   t   __all__R	   (    (    (    sD   lib/python2.7/site-packages/bokeh/command/subcommands/file_output.pyt   <module>	   s   "