B
    )`N                 @   sr   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlm	Z	 ddl
mZ e	jZG dd	 d	eZdS )
zGConfigurations for TensorFlow Debugger (TFDBG) command-line interfaces.    )absolute_import)division)print_functionN)debugger_cli_common)gfilec               @   s`   e Zd ZdZdZddgZdddZdd	 Zd
d Zdd Z	dd Z
dd ZdddZdd ZdS )	CLIConfigz?Client-facing configurations for TFDBG command-line interfaces.z.tfdbg_config)Zgraph_recursion_depth   )Z
mouse_modeTNc             C   sb   |p
|   | _t| j| _t| jrP|  }x|	 D ]\}}|| j|< q:W | 
  i | _d S )N)_default_config_file_path_config_file_pathcollectionsOrderedDict_DEFAULT_CONFIG_configr   ZExists_load_from_fileitems_save_to_file_set_callbacks)selfZconfig_file_pathconfigkeyvalue r   U/home/dcms/DCMS/lib/python3.7/site-packages/tensorflow/python/debug/cli/cli_config.py__init__(   s    
zCLIConfig.__init__c             C   s    || j krtd| | j | S )Nz %s is not a valid property name.)r   KeyError)r   property_namer   r   r   get4   s    
zCLIConfig.getc             C   s   || j krtd| | j | }t|trpt|trf| dkrFd}qn| dkrXd}qntd| qt|}n8t|trt|}n$t|trt|}ntdt	| || j |< | 
  || jkr| j| | j  dS )	a  Set the value of a property.

    Supports limitd property value types: `bool`, `int` and `str`.

    Args:
      property_name: Name of the property.
      property_val: Value of the property. If the property has `bool` type and
        this argument has `str` type, the `str` value will be parsed as a `bool`

    Raises:
      ValueError: if a `str` property_value fails to be parsed as a `bool`.
      KeyError: if `property_name` is an invalid property name.
    z %s is not a valid property name.)1truetyesyonT)0falsefnonoffFz&Invalid string value for bool type: %szUnsupported property type: %sN)r   r   
isinstanceboolstrlower
ValueErrorint	TypeErrortyper   r   )r   r   Zproperty_valZorig_valr   r   r   set9   s*    










zCLIConfig.setc             C   s4   || j krtd| t|s&td|| j|< dS )a  Set a set-callback for given property.

    Args:
      property_name: Name of the property.
      callback: The callback as a `callable` of signature:
          def cbk(config):
        where config is the config after it is set to the new value.
        The callback is invoked each time the set() method is called with the
        matching property_name.

    Raises:
      KeyError: If property_name does not exist.
      TypeError: If `callback` is not callable.
    z %s is not a valid property name.z-The callback object provided is not callable.N)r   r   callabler/   r   )r   r   callbackr   r   r   set_callbackc   s
    
zCLIConfig.set_callbackc             C   s   t jt jd| jS )N~)ospathjoin
expanduser_CONFIG_FILE_NAME)r   r   r   r   r	   x   s    z#CLIConfig._default_config_file_pathc          	   C   sF   y,t | jd}t| j| W d Q R X W n tk
r@   Y nX d S )Nw)r   Openr
   jsondumpr   IOError)r   config_filer   r   r   r   {   s
    zCLIConfig._save_to_filec             C   s   t ddt dg}xj| j D ]\\}}||kr2dnd}t d}|t |d|g7 }|t d7 }|t t||d7 }|| qW t|S )	zGet a text summary of the config.

    Args:
      highlight: A property name to highlight in the output.

    Returns:
      A `RichTextLines` output.
    zCommand-line configuration:Zbold Nz  Z	underlinez: )Z	font_attr)RLr   r   r+   appendr   Z#rich_text_lines_from_rich_line_list)r   Z	highlightlinesnamevalZhighlight_attrliner   r   r   	summarize   s    	zCLIConfig.summarizec          	   C   sr   yRt | jd:}t|}t }x t| D ]}|| ||< q2W |S Q R X W n t	t
fk
rl   t S X d S )Nr)r   r<   r
   r=   loadr   r   sortedkeysr?   r-   dict)r   r@   Zconfig_dictr   r   r   r   r   r      s    
zCLIConfig._load_from_file)N)N)__name__
__module____qualname____doc__r:   r   r   r   r1   r4   r	   r   rH   r   r   r   r   r   r      s   
*
r   )rQ   
__future__r   r   r   r   r=   r6   Ztensorflow.python.debug.clir   Ztensorflow.python.platformr   ZRichLinerB   objectr   r   r   r   r   <module>   s   