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: //usr/lib/python3/dist-packages/landscape/lib/__pycache__/config.cpython-312.pyc
�

y)�]�0���ddlmZddlmZddlmZddlZddlZddlZddl	m
Z
mZddlm
ZddlmZdd�ZGd	�d
e�ZGd�de�Zdd
�Zy)�)�absolute_import)�	getLogger)�OptionParserN)�	ConfigObj�ConfigObjError)�
StringType)�clic�`�d}|�|dj|�z
}|jddd||��y)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--config�FILE)�metavar�default�help)�format�
add_option)�parser�filename�cfgfilehelps   �6/usr/lib/python3/dist-packages/landscape/lib/config.py�add_cli_optionsrsC��?�K����)�0�0��:�:��
���d�J���&��(�c��eZdZiZdd�Zd�Zy)�ConfigSpecOptionParserNc�0�tj||�y�N)r�__init__)�self�unsaved_optionss  rrzConfigSpecOptionParser.__init__s�����d�O�4rc��tj|g|��i|��}tt|��t|j	��|Sr)rr�print�dir�get_opt_string)r�args�kwargs�options    rrz!ConfigSpecOptionParser.add_option s>���(�(��?��?��?��
�c�&�k��
�f�#�#�%�&��
rr)�__name__�
__module__�__qualname__�_config_spec_definitionsrr�rrrrs��!��5�rrc���eZdZdZdZdZdZdZdZdZ	d�Z
d�Zd�Zdd�Z
�fd�Zd	�Zdd
�Zd�Zd�Zd
�Zdd�Zd�Zdd�Zd�Zd�Z�xZS)�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.
    Nr)c��i|_g|_i|_d|_i|_|j�|_|jjj�|_	|jjj�yr)�_set_options�_command_line_args�_command_line_options�_config_filename�_config_file_options�make_parser�_parser�defaults�copy�_command_line_defaults�clear�rs rrzBaseConfiguration.__init__=sm�����"$���%'��"� $���$&��!��'�'�)���&*�l�l�&;�&;�&@�&@�&B��#�	
�����#�#�%rc��|j|j|j|jfD]
}||vs�||}n=|jjd|j
dd�z�rd}nt|��t|t�rB|jjd|j
dd�z�}|�|jd|�}|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/r1r6r3�
has_option�replace�AttributeError�
isinstance�
basestring�
get_option�
convert_value)r�name�options�valuer$s     r�__getattr__zBaseConfiguration.__getattr__Is����)�)��2�2��1�1��3�3�5�G��w����
���
5��|�|�&�&�t�d�l�l�3��.D�'D�E���$�T�*�*��e�Z�(��\�\�,�,�T�D�L�L��c�4J�-J�K�F��!��,�,�T�5�9���rc��|j�}|jj�|_|jj�|_|j|_|j
j�|_|S)zX
        Return a new configuration object, with the same settings as this one.
        )�	__class__r-r5r/r0r1)r�configs  r�clonezBaseConfiguration.cloneish�����!��"�/�/�4�4�6���'+�'A�'A�'F�'F�'H��$�"&�"7�"7���&*�&?�&?�&D�&D�&F��#��
rc�H�	|j|�S#t$r|cYSwxYw)z5Return the value of the C{name} option or C{default}.)rFr>)rrCr
s   r�getzBaseConfiguration.getts,��	��#�#�D�)�)���	��N�	�s��!�!c�p��|jd�rtt|�||�y||j|<y)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-)rrCrErHs   �rrPzBaseConfiguration.__setattr__{s3����?�?�3���#�T�6�t�U�C�&+�D���d�#rc�:�|j|j�y)zhReload options using the configured command line arguments.

        @see: L{load_command_line}
        N)�loadr.r8s r�reloadzBaseConfiguration.reload�s��
	
�	�	�$�)�)�*rc�J�|j|�|jr|jg}d}n|j}|}|D]Y}tjj|�s�#tj|tj�s�H|j|�n1|s.t|�dk(r	d|dz}nd}tj|�|j�|jD];}t||�r�tjd|jdd��d	|�d
���=y)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 readzerror: must specify --r:r;z	 or the 'z' directive in the config file.N)�load_command_linerI�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_config�config_filenames�
allow_missing�config_filename�messager$s        rrRzBaseConfiguration.load�s���	
���t�$��;�;� $���}��!�M�#�<�<��=�M�/�O�������/��	�	�/�2�7�7�3��,�,�_�=��
 0�!��'�(�A�-�=�(��+�,��D�G�����!��#�#�%��+�+�F��4��(����"�N�N�3��4�f�>�?�,rc��y)z<Hook for loading options from elsewhere (e.g. for --import).Nr)r8s rraz(BaseConfiguration._load_external_options�s�rc�n�||_|jj|�d}t|�|_y)z4Load configuration data from the given command line.rN)r.r3�
parse_args�varsr/)rr"�valuess   rrVz#BaseConfiguration.load_command_line�s/��"&������(�(��.�q�1��%)�&�\��"rc�z�||_|j�}	||j|_y#t$rYywxYw)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)r0�_get_config_object�config_sectionr1�KeyError)rr�
config_objs   rr]z)BaseConfiguration.load_configuration_file�sD��!)����,�,�.�
�	�(2�4�3F�3F�(G�D�%���	��	�s�.�	:�:c���|xs|j�}	t|ddd��}|S#t$r;}t�}|j	t|��|j}Yd}~|Sd}~wwxYw)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)�list_values�raise_errors�write_empty_valuesN)�get_config_filenamerrr�warn�strrI)r�alternative_config�
config_sourcerr�e�loggers      rroz$BaseConfiguration._get_config_object�sp��+�H�d�.F�.F�.H�
�	"�"�=�e�05�$�P�J�����	"��[�F��K�K��A������J����	"�s�'�	A+�0A&�&A+c��|j�}|j�}|j|vri||j<|jj	�}|j|j�|j|j�||j}|j�D]|\}}|dk7s�||jvs�||jj|�k(r?||jvr1||jvr#|||jvs�g||j|=�x|||<�~|||j<||_|j�y)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}.
        rIN)rwrorpr1r5�updater/r-�itemsrr6rLr�write)rrrr�all_options�sectionrCrEs       rr�zBaseConfiguration.write�sD�� �+�+�-���,�,�.�
����j�0�.0�J�t�*�*�+��/�/�4�4�6�����4�5�5�6����4�,�,�-��T�0�0�1��&�,�,�.�K�D�%��x��D��0D�0D�$D��T�8�8�<�<�T�B�B��� 9� 9�9��� :� :�:��z�$�*=�*=�>�>�&�t�':�':�;�D�A�$)�G�D�M�/�+2�
�4�&�&�'�&�
�����rc�`�t|j��}tj|||�|S)z�Parser factory for supported options.

        @return: An OptionParser preset with options that all
            programs commonly accept. These include
              - config
              - data_path
        )�version)rr�r	r)r�cfgfile�datadirrs    rr2zBaseConfiguration.make_parsers)���d�l�l�3�����F�G�W�5��
rc��|jr|jS|jr|jS|jrH|jD]*}tj|tj
�s�(|cS|jdSy)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)rIr0rWrXr[r\)r�potential_config_files  rrwz%BaseConfiguration.get_config_filename%st���;�;��;�;��� � ��(�(�(��(�(�)-�)F�)F�%��9�9�2�B�G�G�<�0�0�*G��0�0��3�3�rc��|jS)zWGet currently loaded command line options.

        @see: L{load_command_line}
        )r/r8s r�get_command_line_optionsz*BaseConfiguration.get_command_line_options8s��
�)�)�)rr)F)NN)r%r&r'�__doc__r�rbrrW�default_data_dirrprrFrJrLrPrSrRrarVr]ror�r2rwr��
__classcell__)rHs@rr+r+'sz�����G����O�!�����N�
&��@	��	,�+�,?�\K�2���6+�Z
��&*rr+c���	|j}|�Mtjj	tjjtjd��}|S#t$rd}Y�^wxYw)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)�bindirr>rXrY�dirname�abspathr_�argv)rIr�s  r�
get_bindirr�@sY��������~��������������!��!=�>���M��	�����s�A�A-�,A-r)�
__future__r�loggingr�optparserrX�os.pathr_�	configobjrr�twisted.python.compatrr@�
landscape.libr	rr�objectr+r�r)rr�<module>r�sE��&��!�	��
�/�:��(��\��V*��V*�rr