HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/landscape/lib/__pycache__/config.cpython-38.pyc
U

y)�]�0�@s�ddlmZddlmZddlmZddlZddlZddlZddl	m
Z
mZddlm
ZddlmZddd	�ZGd
d�de�ZGdd
�d
e�Zddd�ZdS)�)�absolute_import)�	getLogger)�OptionParserN)�	ConfigObj�ConfigObjError)�
StringType)�clicCs2d}|dk	r|d�|�7}|jddd||d�dS)z>Add common config-related CLI options to the given arg parser.zUUse config from this file (any command line options override settings from the file).Nz (default: {!r})z-cz--configZFILE)�metavar�default�help)�format�
add_option)�parser�filenameZcfgfilehelp�r�6/usr/lib/python3/dist-packages/landscape/lib/config.py�add_cli_optionss�rc@s"eZdZiZddd�Zdd�ZdS)�ConfigSpecOptionParserNcCst�||�dS�N)r�__init__)�self�unsaved_optionsrrrrszConfigSpecOptionParser.__init__cOs.tj|f|�|�}tt|��t|���|Sr)rr
�print�dirZget_opt_string)r�args�kwargs�optionrrrr
 sz!ConfigSpecOptionParser.add_option)N)�__name__�
__module__�__qualname__Z_config_spec_definitionsrr
rrrrrs
rcs�eZdZdZdZdZdZdZdZdZ	dd�Z
dd�Zdd	�Zd#d
d�Z
�fdd
�Zdd�Zd$dd�Zdd�Zdd�Zdd�Zd%dd�Zdd�Zd&dd�Zdd �Zd!d"�Z�ZS)'�BaseConfigurationaSBase class for configuration implementations.

    @cvar required_options: Optionally, a sequence of key names to require when
        reading or writing a configuration.
    @cvar unsaved_options: Optionally, a sequence of key names to never write
        to the configuration file.  This is useful when you want to provide
        command-line options that should never end up in a configuration file.
    @cvar default_config_filenames: A sequence of filenames to check when
        reading or writing a configuration.

    Default values for supported options are set as in make_parser.
    NrcCsFi|_g|_i|_d|_i|_|��|_|jj��|_	|jj�
�dSr)�_set_options�_command_line_args�_command_line_options�_config_filename�_config_file_options�make_parser�_parser�defaults�copy�_command_line_defaults�clear�rrrrr=s
zBaseConfiguration.__init__cCs�|j|j|j|jfD]}||kr||}qTq|j�d|�dd��rLd}nt|��t|t	�r�|j�
d|�dd��}|dk	r�|�d|�}|S)a�Find and return the value of the given configuration parameter.

        The following sources will be searched:
          - The attributes that were explicitly set on this object,
          - The parameters specified on the command line,
          - The parameters specified in the configuration file, and
          - The defaults.

        If no values are found and the parameter does exist as a possible
        parameter, C{None} is returned.

        Otherwise C{AttributeError} is raised.
        z--�_�-N)r!r#r%r*r'Z
has_option�replace�AttributeError�
isinstance�
basestringZ
get_optionZ
convert_value)r�name�options�valuerrrr�__getattr__Is �
zBaseConfiguration.__getattr__cCs8|��}|j��|_|j��|_|j|_|j��|_|S)zX
        Return a new configuration object, with the same settings as this one.
        )�	__class__r!r)r#r$r%)r�configrrr�cloneiszBaseConfiguration.clonecCs*z|�|�WStk
r$|YSXdS)z5Return the value of the C{name} option or C{default}.N)r6r0)rr3r
rrr�gettszBaseConfiguration.getcs,|�d�rtt|��||�n
||j|<dS)z�Set a configuration parameter.

        If the name begins with C{_}, it will only be set on this object and
        not stored in the configuration file.
        r-N)�
startswith�superr �__setattr__r!)rr3r5�r7rrr={s
zBaseConfiguration.__setattr__cCs|�|j�dS)zhReload options using the configured command line arguments.

        @see: L{load_command_line}
        N)�loadr"r,rrr�reload�szBaseConfiguration.reloadFcCs�|�|�|jr|jg}d}n
|j}|}|D],}tj�|�r,t�|tj�r,|�|�q�q,|s�t	|�dkrxd|d}nd}t
�|�|��|j
D](}t||�s�t
�d|�dd�|f�q�d	S)
a
        Load configuration data from command line arguments and a config file.

        @param accept_nonexistent_default_config: If True, don't complain if
            default configuration files aren't found

        @raise: A SystemExit if the arguments are bad.

        F�z#error: config file %s can't be readrz#error: no config file could be readzBerror: must specify --%s or the '%s' directive in the config file.r-r.N)�load_command_liner8�default_config_filenames�os�path�isfile�access�R_OK�load_configuration_file�len�sys�exit�_load_external_options�required_options�getattrr/)rr�!accept_nonexistent_default_configZconfig_filenamesZ
allow_missingZconfig_filename�messagerrrrr?�s4

�
��


�zBaseConfiguration.loadcCsdS)z<Hook for loading options from elsewhere (e.g. for --import).Nrr,rrrrM�sz(BaseConfiguration._load_external_optionscCs$||_|j�|�d}t|�|_dS)z4Load configuration data from the given command line.rN)r"r'�
parse_args�varsr#)rr�valuesrrrrB�sz#BaseConfiguration.load_command_linecCs8||_|��}z||j|_Wntk
r2YnXdS)z�Load configuration data from the given file name.

        If any data has already been set on this configuration object,
        then the old data will take precedence.
        N)r$�_get_config_object�config_sectionr%�KeyError)rr�
config_objrrrrI�sz)BaseConfiguration.load_configuration_filec
Csb|p
|��}zt|dddd�}Wn<tk
r\}zt�}|�t|��|j}W5d}~XYnX|S)z�Create a L{ConfigObj} consistent with our preferences.

        @param config_source: Optional readable source to read from instead of
            the default configuration file.
        FT)Zlist_valuesZraise_errorsZwrite_empty_valuesN)�get_config_filenamerrr�warn�strr8)rZalternative_configZ
config_sourcerX�e�loggerrrrrU�s�
z$BaseConfiguration._get_config_objectcCs�|��}|��}|j|kr$i||j<|j��}|�|j�|�|j�||j}|��D]b\}}|dkrX||j	krX||j
�|�kr�||jkr�||jkr�|||jkr�||j|=qX|||<qX|||j<||_|�
�dS)a�Write back configuration to the configuration file.

        Values which match the default option in the parser won't be saved.

        Options are considered in the following precedence:

          1. Manually set options (C{config.option = value})
          2. Options passed in the command line
          3. Previously existent options in the configuration file

        The filename picked for saving configuration options is the one
        returned by L{get_config_filename}.
        r8N)rYrUrVr%r)�updater#r!�itemsrr*r:r�write)rrrXZall_optionsZsectionr3r5rrrr`�s*



��

zBaseConfiguration.writecCst|jd�}t�|||�|S)z�Parser factory for supported options.

        @return: An OptionParser preset with options that all
            programs commonly accept. These include
              - config
              - data_path
        )�version)rrarr)rZcfgfileZdatadirrrrrr&szBaseConfiguration.make_parsercCsN|jr|jS|jr|jS|jrJ|jD]}t�|tj�r$|Sq$|jdSdS)z�Pick the proper configuration file.

        The picked filename is:
          1. C{self.config}, if defined
          2. The last loaded configuration file, if any
          3. The first filename in C{self.default_config_filenames}
        rN)r8r$rCrDrGrH)rZpotential_config_filerrrrY%s


z%BaseConfiguration.get_config_filenamecCs|jS)zWGet currently loaded command line options.

        @see: L{load_command_line}
        )r#r,rrr�get_command_line_options8sz*BaseConfiguration.get_command_line_options)N)F)N)NN)rrr�__doc__rarNrrC�default_data_dirrVrr6r9r:r=r@r?rMrBrIrUr`r&rYrb�
__classcell__rrr>rr 's,
 

.
-
r cCsJz
|j}Wntk
r"d}YnX|dkrFtj�tj�tjd��}|S)z�Return the directory path where the client binaries are.

    If the config is None, it doesn't have a "bindir" attribute, or its
    value is None, then sys.argv[0] is returned.
    Nr)�bindirr0rDrE�dirname�abspathrK�argv)r8rfrrr�
get_bindir@s

rj)N)N)�
__future__r�loggingr�optparserrDZos.pathrKZ	configobjrr�twisted.python.compatrr2Z
landscape.librrr�objectr rjrrrr�<module>s