
    BVh                     f    d 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e
      Zy)zGConfigurations for TensorFlow Debugger (TFDBG) command-line interfaces.    N)debugger_cli_common)gfilec                   P    e Zd ZdZdZddgZddZd Zd Zd	 Z	d
 Z
d ZddZd Zy)	CLIConfigz?Client-facing configurations for TFDBG command-line interfaces.z.tfdbg_config)graph_recursion_depth   )
mouse_modeTNc                 X   |xs | j                         | _        t        j                  | j                        | _        t        j                  | j                        r7| j                         }|j                         D ]  \  }}|| j
                  |<    | j                          i | _        y N)_default_config_file_path_config_file_pathcollectionsOrderedDict_DEFAULT_CONFIG_configr   Exists_load_from_fileitems_save_to_file_set_callbacks)selfconfig_file_pathconfigkeyvalues        V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/debug/cli/cli_config.py__init__zCLIConfig.__init__$   s    . ?"<<> 	**4+?+?@DL||D**+##%f "*#u!S"D    c                 X    || j                   vrt        d|z        | j                   |   S )N %s is not a valid property name.)r   KeyError)r   property_names     r   getzCLIConfig.get0   s.    DLL(7-GHH<<&&r   c                 Z   || j                   vrt        d|z        | j                   |   }t        |t              rTt        |t              r8|j                         dv rd}n~|j                         dv rd}nit        d|z        t        |      }nOt        |t              rt        |      }n3t        |t              rt	        |      }nt        dt        |      z        || j                   |<   | j                          || j                  v r  | j                  |   | j                          yy)	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.
    r    )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"   property_valorig_vals       r   setzCLIConfig.set5   s    DLL(7-GHH||M*H(D!	L#	&#GG,!%JJ,6EG G L)	Hc	"&l	Hc	"&l5XFGG".DLL +++(d-(6 ,r   c                     || j                   vrt        d|z        t        |      st        d      || j                  |<   y)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.
    r    z-The callback object provided is not callable.N)r   r!   callabler7   r   )r   r"   callbacks      r   set_callbackzCLIConfig.set_callback_   sE     DLL(7-GHHHEFF)1D&r   c                     t         j                  j                  t         j                  j                  d      | j                        S )N~)ospathjoin
expanduser_CONFIG_FILE_NAME)r   s    r   r   z#CLIConfig._default_config_file_patht   s,    77<<**3/1G1GHHr   c                     	 t        j                  | j                  d      5 }t        j                  | j
                  |       d d d        y # 1 sw Y   y xY w# t        $ r Y y w xY w)Nw)r   Openr   jsondumpr   IOError)r   config_files     r   r   zCLIConfig._save_to_filew   sU    ::d,,c2 -k		$,,,- - - 
s.    A !AA AA A 	A$#A$c                 X   t        dd      t        d      g}| j                  j                         D ]b  \  }}||k(  rdnd}t        d      }|t        |d|g      z  }|t        d      z  }|t        t        |      |      z  }|j	                  |       d t        j                  |      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:bold Nz  	underlinez: )	font_attr)RLr   r   r3   appendr   #rich_text_lines_from_rich_line_list)r   	highlightlinesnamevalhighlight_attrlines          r   	summarizezCLIConfig.summarize~   s     -v62?E\\'') 	c!%!2vnXd
b^455d
bhd
bS^44dll4 BB5IIr   c                 P   	 t        j                  | j                  d      5 }t        j                  |      }t        j                         }t        |j                               D ]
  }||   ||<    |cd d d        S # 1 sw Y   y xY w# t        t        f$ r t               cY S w xY w)Nr)r   rI   r   rJ   loadr   r   sortedkeysrL   r5   dict)r   rM   config_dictr   r   s        r   r   zCLIConfig._load_from_file   s    
::d,,c2 kii,((*+**,- 	)C#C(&+	)   Z   Vms/    B	 AA=3	B	 =BB	 B	 	B%$B%r   )__name__
__module____qualname____doc__rF   r   r   r#   r;   r?   r   r   r\   r    r   r   r   r      sE    G% $/

'
(7T2*IJ&r   r   )rg   r   rJ   rB   tensorflow.python.debug.clir   tensorflow.python.platformr   RichLinerS   objectr   rh   r   r   <module>rm      s3    N   	 ; ,!!B Br   