
2\c           @   sr  d  d l  Z  d  d l Z d d l m Z m Z m Z m 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 d	 Z d
 Z d   Z e e d d  Z d d  Z e e d d  Z e e d d  Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ e j  Z! e" d k rne!   n  d S(   iNi   (   t   BaseExtensionAppt   _get_config_dirt   GREEN_ENABLEDt   RED_DISABLED(   t   __version__(   t   BaseJSONConfigManager(   t   jupyter_config_path(   t   import_item(   t   Boolt   notebookt   bundlerextensionsc         C   sI   t  |   } t | d  s3 t d j |     n  | j   } | | f S(   s   Gets the list of bundlers associated with a Python package.
    
    Returns a tuple of (the module, [{
        'name': 'unique name of the bundler',
        'label': 'file menu item label for the bundler',
        'module_name': 'dotted package/module name containing the bundler',
        'group': 'download or deploy parent menu item'
    }])
    
    Parameters
    ----------

    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    t   _jupyter_bundlerextension_pathss>   The Python module {} does not contain a valid bundlerextension(   R   t   hasattrt   KeyErrort   formatR   (   t   modulet   mt   bundlers(    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   _get_bundler_metadata   s
    c   
      C   s   | r t  n | } t j j t d | d |  d  } t d |  }	 | rv | j d j | rc d n d |  |   n  | r |	 j t	 i i i | d 6| d	 6| d
 6|  6t
 6 n |	 j t	 i i d |  6t
 6 |	 j t	  j t
 i   j |   d k	 | k S(   sF  Set whether a bundler is enabled or disabled.
    
    Returns True if the final state is the one requested.
    
    Parameters
    ----------
    name : string
        Unique name of the bundler
    label : string
        Human-readable label for the bundler menu item in the notebook UI
    module_name : string
        Dotted module/package name containing the bundler
    group : string
        'download' or 'deploy' indicating the parent menu containing the label
    state : bool
        The state in which to leave the extension
    user : bool [default: True]
        Whether to update the user's .jupyter/nbconfig directory
    sys_prefix : bool [default: False]
        Whether to update the sys.prefix, i.e. environment. Will override
        `user`.
    logger : Jupyter logger [optional]
        Logger instance to use
    t   usert
   sys_prefixt   nbconfigt
   config_dirs   {} {} bundler {}...t   Enablingt	   Disablingt   labelt   module_namet   groupN(   t   Falset   ost   patht   joinR   R   t   infoR   t   updatet   BUNDLER_SECTIONt   BUNDLER_SUBSECTIONt   Nonet   get(
   t   nameR   R   R   t   stateR   R   t   loggerR   t   cm(    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   _set_bundler_state)   s,    	c         C   sl   t  |  \ } } g  | D]O } t d | d d | d d | d d | d d |  d | d | d |  ^ q S(	   sP  Enables or disables bundlers defined in a Python package.
    
    Returns a list of whether the state was achieved for each bundler.
    
    Parameters
    ----------
    state : Bool
        Whether the extensions should be enabled
    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    user : bool
        Whether to enable in the user's nbconfig directory.
    sys_prefix : bool
        Enable/disable in the sys.prefix, i.e. environment
    logger : Jupyter logger [optional]
        Logger instance to use
    R&   R   R   R   R'   R   R   R(   (   R   R*   (   R'   R   R   R   R(   R   R   t   bundler(    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   _set_bundler_state_pythone   s    c         C   s   t  t |  | | d | S(   sI  Enables bundlers defined in a Python package.
    
    Returns whether each bundle defined in the packaged was enabled or not.
    
    Parameters
    ----------
    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    user : bool [default: True]
        Whether to enable in the user's nbconfig directory.
    sys_prefix : bool [default: False]
        Whether to enable in the sys.prefix, i.e. environment. Will override
        `user`
    logger : Jupyter logger [optional]
        Logger instance to use
    R(   (   R,   t   True(   R   R   R   R(   (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   enable_bundler_python   s    c         C   s   t  t |  | | d | S(   sJ  Disables bundlers defined in a Python package.
    
    Returns whether each bundle defined in the packaged was enabled or not.
    
    Parameters
    ----------
    module : str
        Importable Python module exposing the
        magic-named `_jupyter_bundlerextension_paths` function
    user : bool [default: True]
        Whether to enable in the user's nbconfig directory.
    sys_prefix : bool [default: False]
        Whether to enable in the sys.prefix, i.e. environment. Will override
        `user`
    logger : Jupyter logger [optional]
        Logger instance to use
    R(   (   R,   R   (   R   R   R   R(   (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   disable_bundler_python   s    t   ToggleBundlerExtensionAppc           B   sY   e  Z d  Z d Z e Z d Z e e d e d d Z	 d	 Z d   Z d   Z d   Z RS(
   s;   A base class for apps that enable/disable bundlerextensionss'   jupyter bundlerextension enable/disables3   Enable/disable a bundlerextension in configuration.t   configt   helps;   Apply the configuration only for the current user (default)c         C   s   d S(   s   The default config file name.t   jupyter_notebook_config(    (   t   self(    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   _config_file_name_default   s    c         C   s:   |  j  r t n t } | | d |  j d |  j d |  j S(   sS  Toggle some extensions in an importable Python module.

        Returns a list of booleans indicating whether the state was changed as
        requested.

        Parameters
        ----------
        module : str
            Importable Python module exposing the
            magic-named `_jupyter_bundlerextension_paths` function
        R   R   R(   (   t   _toggle_valueR.   R/   R   R   t   log(   R4   R   t   toggle(    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   toggle_bundler_python   s    			c         C   sn   |  j  s t j d  n% t |  j   d k r> t j d  n  |  j r^ |  j |  j  d  n t d   d  S(   Ns?   Please specify an bundlerextension/package to enable or disablei   s5   Please specify one bundlerextension/package at a timei    s0   Cannot install bundlers from non-Python packages(   t
   extra_argst   syst   exitt   lent   pythonR9   t   NotImplementedError(   R4   (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   start   s    		N(   t   __name__t
   __module__t   __doc__R&   R   t   versiont   descriptionR   R-   R   R$   R6   R5   R9   R@   (    (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyR0      s   		t   EnableBundlerExtensionAppc           B   s    e  Z d  Z d Z d Z e Z RS(   s%   An App that enables bundlerextensionss   jupyter bundlerextension enables   
    Enable a bundlerextension in frontend configuration.
    
    Usage
        jupyter bundlerextension enable [--system|--sys-prefix]
    (   RA   RB   RC   R&   RE   R-   R6   (    (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyRF      s   t   DisableBundlerExtensionAppc           B   s    e  Z d  Z d Z d Z d Z RS(   s&   An App that disables bundlerextensionss    jupyter bundlerextension disables   
    Disable a bundlerextension in frontend configuration.
    
    Usage
        jupyter bundlerextension disable [--system|--sys-prefix]
    N(   RA   RB   RC   R&   RE   R$   R6   (    (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyRG      s   t   ListBundlerExtensionAppc           B   s2   e  Z d  Z d Z e Z d Z d   Z d   Z RS(   s,   An App that lists and validates nbextensionss   jupyter nbextension lists7   List all nbextensions known by the configuration systemc         C   s'  g  t    D] } t j j | d  ^ q
 } d GHx | D] } d j |  } t } t d |  d |  } | j d  } d | k r7 | s | GHt } n  x | d j	   D]q \ } }	 |	 j d  }
 |	 j d	  } |
 d k s | d k r d
 j | t  } n d j |
 | t  } | GHq Wq7 q7 Wd S(   s   List all the nbextensionsR   s   Known bundlerextensions:u     config dir: {}t   parentR   R	   R
   R   R   u	       {} {}u       "{}" from {} {}N(   R   R   R   R   R   R   R   R%   R-   t   itemsR$   R   R   (   R4   t   pt   config_dirsR   t   headt
   head_shownR)   t   datat
   bundler_idR    R   R   t   msg(    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   list_nbextensions   s&    +	c         C   s   |  j    d S(   s)   Perform the App's functions as configuredN(   RR   (   R4   (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyR@     s    (	   RA   RB   RC   R&   R   RD   RE   RR   R@   (    (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyRH      s   	t   BundlerExtensionAppc           B   s\   e  Z d  Z d Z e Z d Z d Z e d e	 d f d e
 d f d e d	 f  Z d
   Z RS(   s1   Base jupyter bundlerextension command entry points   jupyter bundlerextensions$   Work with Jupyter bundler extensionss  
jupyter bundlerextension list                          # list all configured bundlers
jupyter bundlerextension enable --py <packagename>     # enable all bundlers in a Python package
jupyter bundlerextension disable --py <packagename>    # disable all bundlers in a Python package
t   enables   Enable a bundler extensiont   disables   Disable a bundler extensiont   lists   List bundler extensionsc         C   s@   t  t |   j   d j t |  j   } t j d |  d S(   s)   Perform the App's functions as configureds   , s)   Please supply at least one subcommand: %sN(   t   superRS   R@   R   t   sortedt   subcommandsR;   R<   (   R4   t   subcmds(    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyR@   '  s    (   RA   RB   RC   R&   R   RD   RE   t   examplest   dictRF   RG   RH   RY   R@   (    (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyRS     s   t   __main__(#   R;   R   t
   extensionsR    R   R   R   t   _versionR   t   notebook.config_managerR   t   jupyter_core.pathsR   t   traitlets.utils.importstringR   t	   traitletsR   R"   R#   R   R-   R   R$   R*   R,   R.   R/   R0   RF   RG   RH   RS   t   launch_instancet   mainRA   (    (    (    sA   lib/python2.7/site-packages/notebook/bundler/bundlerextensions.pyt   <module>   s,   "	;+(	