
    wiZ                     j    d Z ddlZddlZddlmZmZmZ  G d d          Zdad	dee	         defdZ
dS )
z+
Configuration handling for Perth library.
    N)DictAnyOptionalc            	           e Zd ZdZdddddddd	dd
dZddee         fdZdeddfdZdeddfdZ	ddedede
de
fdZdedede
ddfdZdedeee
f         fdZdefdZdS )Configz
    Configuration management for Perth.
    
    Handles loading, saving, and accessing configuration settings for the library.
    perthT)default_watermarkerverbosecpuimplicitN)devicerun_name
models_diriD  )default_sample_rate	normalize)generalr   audioconfig_pathc           	         i | _         | j                                        D ]!\  }}|                                | j         |<   "t          j                            t          j                            t          j                            t          j                            t                                        ddd          | j         d         d<   |r6t          j        
                    |          r|                     |           dS dS dS )z
        Initialize configuration with default values and optional user config.
        
        Args:
            config_path: Path to a YAML configuration file to load
        r   	perth_net
pretrainedr   N)_config	_defaultsitemscopyospathjoindirnameabspath__file__existsload)selfr   sectionvaluess       \/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/perth/config.py__init__zConfig.__init__&   s     #~3355 	2 	2OGV$*KKMMDL!! /1gllGOOBGOOBGOOH,E,EFFGG[,/
 /
Wl+  	#27>>+66 	#IIk"""""	# 	# 	# 	#    returnc                 ~   	 t          |d          5 }t          j        |          }ddd           n# 1 swxY w Y   |rN|                                D ];\  }}|| j        v r!| j        |                             |           /|| j        |<   :dS dS # t          $ r }t          d| d|            Y d}~dS d}~ww xY w)z
        Load configuration from a YAML file.
        
        Args:
            config_path: Path to a YAML configuration file
        rNz$Warning: Could not load config from z: )openyaml	safe_loadr   r   update	Exceptionprint)r$   r   fuser_configr%   r&   es          r'   r#   zConfig.load<   sF   	Mk3'' 01"nQ//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  7'2'8'8':': 7 7OGV$,..W-44V<<<<06W--7 77 7
  	M 	M 	MKKKKKLLLLLLLLL	Ms3   B 3B 7B 7AB 
B<B77B<c                 0   t          j        t           j                            t           j                            |                    d           t          |d          5 }t          j        | j        |d           ddd           dS # 1 swxY w Y   dS )z
        Save current configuration to a YAML file.
        
        Args:
            config_path: Path to save the configuration to
        T)exist_okwFdefault_flow_styleN)	r   makedirsr   r   r    r-   r.   dumpr   )r$   r   r3   s      r'   savezConfig.saveQ   s     	BGOOBGOOK$@$@AADQQQQ+s## 	AqIdlA%@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As   !BBBr%   keydefaultc                 \    || j         v r"|| j         |         v r| j         |         |         S |S )a  
        Get a configuration value.
        
        Args:
            section: Configuration section
            key: Configuration key
            default: Default value to return if key is not found
            
        Returns:
            Configuration value or default
        r   )r$   r%   r>   r?   s       r'   getz
Config.get\   s9     dl""sdl7.C'C'C<(--r)   valuec                 L    || j         vr
i | j         |<   || j         |         |<   dS )z
        Set a configuration value.
        
        Args:
            section: Configuration section
            key: Configuration key
            value: Value to set
        NrA   )r$   r%   r>   rC   s       r'   setz
Config.setl   s4     $,&&$&DL!%*Wc"""r)   c                 \    | j                             |i                                           S )z
        Get an entire configuration section.
        
        Args:
            section: Configuration section name
            
        Returns:
            Dictionary of configuration values for the section
        )r   rB   r   )r$   r%   s     r'   get_sectionzConfig.get_sectiony   s(     |,,11333r)   c                 8    t          j        | j        d          S )z4Return a string representation of the configuration.Fr9   )r.   r<   r   )r$   s    r'   __str__zConfig.__str__   s    y%@@@@r)   N)__name__
__module____qualname____doc__r   r   strr(   r#   r=   r   rB   rE   r   rG   rI    r)   r'   r   r   	   s         $+
 
 "
 
 $)
 
 I*# #HSM # # # #,M M M M M M*	A 	A 	A 	A 	A 	A 3 S 3 #     +3 +S + + + + + +
43 
44S> 
4 
4 
4 
4A A A A A A Ar)   r   r   r*   c                 v    t           t          |           a n| rt                               |            t           S )z
    Get the global configuration instance.
    
    Args:
        config_path: Optional path to a configuration file to load
        
    Returns:
        Config instance
    )_config_instancer   r#   )r   s    r'   
get_configrS      s=     !+..	 +k***r)   rJ   )rN   r   r.   typingr   r   r   r   rR   rO   rS   rP   r)   r'   <module>rU      s     
			  & & & & & & & & & &~A ~A ~A ~A ~A ~A ~A ~AD   HSM V      r)   