o c0@sddlmZddlmZddlmZddlZddlZddlZddl m Z m Z ddl m ZddlmZddd ZGd d d eZGd d d eZdddZdS))absolute_import) getLogger) OptionParserN) ConfigObjConfigObjError) StringType)clicCs2d}|dur |d|7}|jddd||ddS)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--configFILE)metavardefaulthelp)format add_option)parserfilename cfgfilehelpr6/usr/lib/python3/dist-packages/landscape/lib/config.pyadd_cli_optionss   rc@s"eZdZiZdddZddZdS)ConfigSpecOptionParserNcCst||dSN)r__init__)selfunsaved_optionsrrrrszConfigSpecOptionParser.__init__cOs4tj|g|Ri|}tt|t||Sr)rrprintdirget_opt_string)rargskwargsoptionrrrr s  z!ConfigSpecOptionParser.add_optionr)__name__ __module__ __qualname___config_spec_definitionsrrrrrrrs  rcseZdZdZdZdZdZdZdZdZ ddZ ddZ dd Z d#d d Z fd d ZddZd$ddZddZddZddZd#ddZddZd%ddZdd Zd!d"ZZS)&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_parserdefaultscopy_command_line_defaultsclearrrrrr=s zBaseConfiguration.__init__cCs|j|j|j|jfD] }||vr||}nq |jd|ddr&d}nt|t|t rE|j d|dd}|durE| d|}|S)aFind 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+ has_optionreplaceAttributeError isinstance basestring get_option convert_value)rnameoptionsvaluerrrr __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))rconfigrrrcloneis    zBaseConfiguration.clonecCs$z||WSty|YSw)z5Return the value of the C{name} option or C{default}.)r=r5)rr:r rrrgetts   zBaseConfiguration.getcs.|drtt|||dS||j|<dS)zSet a configuration parameter. If the name begins with C{_}, it will only be set on this object and not stored in the configuration file. r1N) startswithsuperr$ __setattr__r%)rr:r<r>rrrD{s zBaseConfiguration.__setattr__cCs||jdS)zhReload options using the configured command line arguments. @see: L{load_command_line} N)loadr&r0rrrreloadszBaseConfiguration.reloadFcCs|||jr|jg}d}n|j}|}|D]}tj|r,t|tjr,||nq|sCt |dkrs