HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/config.cpython-312.pyc
�

�~�en1���ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd�ZGd	�d
e�ZGd�d�Zdd
�Zy)�N)�	getLogger)�OptionParser)�	ConfigObj)�ConfigObjError)�
StringType)�clic�J�d}|�	|d|�d�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: �)z-cz--config�FILE)�metavar�default�help)�
add_option)�parser�filename�cfgfilehelps   �6/usr/lib/python3/dist-packages/landscape/lib/config.py�add_cli_optionsr
sI��	4������X�L��2�2��
�������
���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__Bsm�����"$���%'��"� $���$&��!��'�'�)���&*�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.r0r5r2�
has_option�replace�AttributeError�
isinstancer�
get_option�
convert_value)r�name�options�valuer#s     r�__getattr__zBaseConfiguration.__getattr__Ns���
����&�&��%�%��'�'�	
�
	+�G��w����
���
	+��|�|�&�&�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,r4r.r/r0)r�configs  r�clonezBaseConfiguration.clonepsh�����!��"�/�/�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}.)rDr=)rrAr
s   r�getzBaseConfiguration.get{s,��	��#�#�D�)�)���	��N�	�s��!�!c�h��|jd�rt�|�	||�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.
        r9N)�
startswith�super�__setattr__r,)rrArCrFs   �rrNzBaseConfiguration.__setattr__�s0����?�?�3���G���e�,�&+�D���d�#rc�:�|j|j�y)zhReload options using the configured command line arguments.

        @see: L{load_command_line}
        N)�loadr-r7s r�reloadzBaseConfiguration.reload�s��
	
�	�	�$�)�)�*rc	�^�|j|�|jr|jg}d}n|j}|}|D]Y}tjj|�s�#tj|tj�s�H|j|�n2|s/t|�dk(r
d|d�d�}nd}tj|�|j�|jD]D}t||�r�tjdj|j!dd	�|���Fy
)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�zerror: config file rz can't be readz#error: no config file could be readzBerror: must specify --{} or the '{}' directive in the config file.r9r:N)�load_command_linerG�default_config_filenames�os�path�isfile�access�R_OK�load_configuration_file�len�sys�exit�_load_external_options�required_options�getattr�formatr<)rr!�!accept_nonexistent_default_config�config_filenames�
allow_missing�config_filename�messager#s        rrPzBaseConfiguration.load�s"��	
���t�$��;�;� $���}��!�M�#�<�<��=�M�/�	"�O��w�w�~�~�o�.�2�9�9�����4�
�,�,�_�=��	"�!��'�(�A�-�-�.>�q�.A�-B�C(�(��
D�G�����!��#�#�%��+�+�	�F��4��(����@�@F�����s�C�0��A��	rc��y)z<Hook for loading options from elsewhere (e.g. for --import).Nr(r7s rr_z(BaseConfiguration._load_external_options�s�rc�n�||_|jj|�d}t|�|_y)z4Load configuration data from the given command line.rN)r-r2�
parse_args�varsr.)rr!�valuess   rrTz#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)r/�_get_config_object�config_sectionr0�KeyError)rr�
config_objs   rr[z)BaseConfiguration.load_configuration_file�sD��!)����,�,�.�
�	�(2�4�3F�3F�(G�D�%���	��	�s�.�	:�:c��|xs|j�}	t|dddt|dd���}|S#t$rK}t	�}|jdj
|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�encodingN)�list_values�raise_errors�write_empty_valuesrszERROR at {}: {})	�get_config_filenamerrarr�warnrb�strrG)r�alternative_config�
config_sourcerq�e�loggers      rrnz$BaseConfiguration._get_config_object�s���+�H�d�.F�.F�.H�
�	"�"��!�"�#'� ��z�4�8��J�����	"��[�F��K�K�)�0�0���A��G�H����J����	"�s�3�	B�AB�Bc��|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}.
        rGN)rwrnror0r4�updater.r,�itemsrr5rJr�write)rrrq�all_options�sectionrArCs       rr�zBaseConfiguration.write�sI�� �+�+�-���,�,�.�
����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��D�$=�$=�=��D�$>�$>�>��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�rr)r�cfgfile�datadirrs    rr1zBaseConfiguration.make_parser,s)���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)rGr/rUrVrYrZ)r�potential_config_files  rrwz%BaseConfiguration.get_config_filename8sx���;�;��;�;��� � ��(�(�(��(�(�)-�)F�)F�
1�%��9�9�2�B�G�G�<�0�0�
1��0�0��3�3�rc��|jS)zWGet currently loaded command line options.

        @see: L{load_command_line}
        )r.r7s r�get_command_line_optionsz*BaseConfiguration.get_command_line_optionsKs��
�)�)�)rr)F)NN)r$r%r&�__doc__r�r`rrU�default_data_dirrorrDrHrJrNrQrPr_rTr[rnr�r1rwr��
__classcell__)rFs@rr*r*,s{�����G����O�!�����N�
&� �D	��	,�+�2�hK�2���@,�\
��&*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=rVrW�dirname�abspathr]�argv)rGr�s  r�
get_bindirr�SsY��������~��������������!��!=�>���M��	�����s�A�A-�,A-r)�os.pathrVr]�loggingr�optparser�	configobjrr�twisted.python.compatr�
landscape.librrrr*r�r(rr�<module>r�s@���
��!��$�,���"�\��d*�d*�N	r