B
    )`#                 @   sh   d Z ddlmZ ddlm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	 G d	d
 d
e
ZdS )zABase Class of TensorFlow Debugger (tfdbg) Command-Line Interface.    )absolute_import)division)print_functionN)
cli_config)command_parser)debugger_cli_commonc               @   sx   e Zd ZdZdZddgZdZdZddd	Zd
d Z	dddZ
dd ZdddZdd Zdd Zedd ZdddZdS )BaseUIz#Base class of tfdbg user interface.ztfdbg> exitquitzERROR: zINFO: Nc             C   s   || _ t | _t | _| jdg| jtjjg tjj	  |pHt
 | _tjdtjd| _| j }|d}|jdtd |jdtd |d}| jd	| j| j d
gd dS )zConstructor of the base class.

    Args:
      on_ui_exit: (`Callable`) the callback to be called when the UI exits.
      config: An instance of `cli_config.CLIConfig()` carrying user-facing
        configurations.
     zconfig command)descriptionusagesetproperty_name)typeproperty_valueshowconfigcfg)prefix_aliasesN)Z_on_ui_exitr   ZCommandHandlerRegistry_command_handler_registryZTabCompletionRegistry_tab_completion_registryregister_tab_comp_contextCLI_EXIT_COMMANDSZHELP_COMMANDZHELP_COMMAND_ALIASESr   Z	CLIConfig_configargparseArgumentParserSUPPRESS_config_argparseradd_subparsers
add_parseradd_argumentstrregister_command_handler_config_command_handlerformat_help)selfZ
on_ui_exitr   Z
subparsers
set_parser r(   R/home/dcms/DCMS/lib/python3.7/site-packages/tensorflow/python/debug/cli/base_ui.py__init__#   s(    	




zBaseUI.__init__c             C   s   | j j|d dS )zSet an introductory message to the help output of the command registry.

    Args:
      help_intro: (RichTextLines) Rich text lines appended to the beginning of
        the output of the command "help", as introductory information.
    )
help_introN)r   set_help_intro)r&   r+   r(   r(   r)   r,   H   s    zBaseUI.set_help_introc             C   s:   | j j||||d | jd|g |r6| jd| dS )a  A wrapper around CommandHandlerRegistry.register_command_handler().

    In addition to calling the wrapped register_command_handler() method, this
    method also registers the top-level tab-completion context based on the
    command prefixes and their aliases.

    See the doc string of the wrapped method for more details on the args.

    Args:
      prefix: (str) command prefix.
      handler: (callable) command handler.
      help_info: (str) help information.
      prefix_aliases: (list of str) aliases of the command prefix.
    )r   r   N)r   r#   r   Zextend_comp_items)r&   prefixhandlerZ	help_infor   r(   r(   r)   r#   R   s
    zBaseUI.register_command_handlerc             O   s   | j j|| dS )zAWrapper around TabCompletionRegistry.register_tab_comp_context().N)r   r   )r&   argskwargsr(   r(   r)   r   m   s    z BaseUI.register_tab_comp_contextTc             C   s   t ddS )a  Run the UI until user- or command- triggered exit.

    Args:
      init_command: (str) Optional command to run on CLI start up.
      title: (str) Optional title to display in the CLI.
      title_color: (str) Optional color of the title, e.g., "yellow".
      enable_mouse_on_start: (bool) Whether the mouse mode is to be enabled on
        start-up.

    Returns:
      An exit token of arbitrary type. Can be None.
    z%run_ui() is not implemented in BaseUIN)NotImplementedError)r&   Zinit_commandtitleZtitle_colorZenable_mouse_on_startr(   r(   r)   run_uir   s    zBaseUI.run_uic             C   sD   |  }|sdg dfS t|}t|\}}|d |dd |fS )aa  Parse a command string into prefix and arguments.

    Args:
      command: (str) Command string to be parsed.

    Returns:
      prefix: (str) The command prefix.
      args: (list of str) The command arguments (i.e., not including the
        prefix).
      output_file_path: (str or None) The path to save the screen output
        to (if any).
    r   Nr      )stripr   parse_commandZextract_output_file_path)r&   commandZcommand_itemsZoutput_file_pathr(   r(   r)   _parse_command   s    


zBaseUI._parse_commandc             C   sr   |  }|sd}d}d}nN|d}t|dkrBd}|d }d}n&|d }|d }d|dd d }|||fS )aM  Analyze raw input to tab-completer.

    Args:
      text: (str) the full, raw input text to be tab-completed.

    Returns:
      context: (str) the context str. For example,
        If text == "print_tensor softmax", returns "print_tensor".
        If text == "print", returns "".
        If text == "", returns "".
      prefix: (str) the prefix to be tab-completed, from the last word.
        For example, if text == "print_tensor softmax", returns "softmax".
        If text == "print", returns "print".
        If text == "", returns "".
      except_last_word: (str) the input text, except the last word.
        For example, if text == "print_tensor softmax", returns "print_tensor".
        If text == "print_tensor -a softmax", returns "print_tensor -a".
        If text == "print", returns "".
        If text == "", returns "".
    r    r4   r   N)lstripsplitlenjoin)r&   textcontextr-   Zexcept_last_worditemsr(   r(   r)   _analyze_tab_complete_input   s    
z"BaseUI._analyze_tab_complete_inputc             C   s   | j S )z/Obtain the CLIConfig of this `BaseUI` instance.)r   )r&   r(   r(   r)   r      s    zBaseUI.configc             C   sR   ~| j |}t|drDt|drD| j|j|j | jj|jdS | j S dS )z)Command handler for the "config" command.r   r   )Z	highlightN)r   
parse_argshasattrr   r   r   r   Z	summarize)r&   r/   Zscreen_infoparsedr(   r(   r)   r$      s    zBaseUI._config_command_handler)NN)N)NNNT)N)__name__
__module____qualname____doc__Z
CLI_PROMPTr   ZERROR_MESSAGE_PREFIXZINFO_MESSAGE_PREFIXr*   r,   r#   r   r3   r8   rB   propertyr   r$   r(   r(   r(   r)   r      s"   
%
   
*r   )rI   
__future__r   r   r   r   Ztensorflow.python.debug.clir   r   r   objectr   r(   r(   r(   r)   <module>   s   