~en1ddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddZGd d eZGd d Zdd Zy)N) getLogger) OptionParser) ConfigObj)ConfigObjError) StringType)clicJd}| |d|dz }|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--configFILE)metavardefaulthelp) add_option)parserfilename cfgfilehelps 6/usr/lib/python3/dist-packages/landscape/lib/config.pyadd_cli_optionsr sI 4XL22     ceZdZiZddZdZy)ConfigSpecOptionParserNc0tj||yN)r__init__)selfunsaved_optionss rrzConfigSpecOptionParser.__init__"sdO4rctj|g|i|}tt|t|j |Sr)rrprintdirget_opt_string)rargskwargsoptions rrz!ConfigSpecOptionParser.add_option%s>((??? c&k f##%& rr)__name__ __module__ __qualname___config_spec_definitionsrrrrrrs!5rrceZdZdZdZdZdZdZdZdZ dZ dZ dZ ddZ fdZd Zdd Zd Zd Zd ZddZdZddZdZdZxZS)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(ci|_g|_i|_d|_i|_|j |_|j jj|_ |j jjyr) _set_options_command_line_args_command_line_options_config_filename_config_file_options make_parser_parserdefaultscopy_command_line_defaultsclearrs rrzBaseConfiguration.__init__Bsm"$%'" $$&!'') &*ll&;&;&@&@&B# ##%rc|j|j|j|jfD] }||vs||}n=|jj d|j ddzrd}n t|t|trB|jjd|j ddz}||jd|}|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.r0r5r2 has_optionreplaceAttributeError isinstancer get_option convert_value)rnameoptionsvaluer#s r __getattr__zBaseConfiguration.__getattr__Ns     & &  % %  ' '  +G w  +||&&tdll3.D'DE$T** eZ (\\,,TDLLc4J-JKF!,,T59 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)rconfigs rclonezBaseConfiguration.clonepsh!"//446'+'A'A'F'F'H$"&"7"7&*&?&?&D&D&F# rcH |j|S#t$r|cYSwxYw)z5Return the value of the C{name} option or C{default}.)rDr=)rrAr s rgetzBaseConfiguration.get{s, ##D) ) N s  !!ch|jdrt| ||y||j|<y)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. r9N) startswithsuper __setattr__r,)rrArCrFs rrNzBaseConfiguration.__setattr__s0 ??3  G e ,&+D  d #rc:|j|jy)zhReload options using the configured command line arguments. @see: L{load_command_line} N)loadr-r7s rreloadzBaseConfiguration.reloads $))*rc ^|j||jr|jg}d}n|j}|}|D]Y}tjj |s#tj |tjsH|j|n2|s/t|dk(r d|dd}nd}tj||j|jD]D}t||rtjdj|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. Fzerror: 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_linerGdefault_config_filenamesospathisfileaccessR_OKload_configuration_filelensysexit_load_external_optionsrequired_optionsgetattrformatr<)rr!!accept_nonexistent_default_configconfig_filenames allow_missingconfig_filenamemessager#s rrPzBaseConfiguration.loads" t$ ;; $ } !M#<< =M/ "Oww~~o.2994 ,,_= "!'(A--.>q.A-BC(( DG! ##%++ F4(@@FsC0A rcy)z$>> z$*=*=>>&t':':;DA$)GDM *+2 4&&'& rc`t|j}tj||||S)zParser factory for supported options. @return: An OptionParser preset with options that all programs commonly accept. These include - config - data_path )version)rrrr)rcfgfiledatadirrs rr1zBaseConfiguration.make_parser,s)dll3 FGW5 rc |jr |jS|jr |jS|jrH|jD]*}tj|tj s(|cS|jdSy)zPick 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)rpotential_config_files rrwz%BaseConfiguration.get_config_filename8sx ;;;;   (( (  ( ()-)F)F 1%992BGG<00 1003 3rc|jS)zWGet currently loaded command line options. @see: L{load_command_line} )r.r7s rget_command_line_optionsz*BaseConfiguration.get_command_line_optionsKs )))rr)F)NN)r$r%r&__doc__rr`rrUdefault_data_dirrorrDrHrJrNrQrPr_rTr[rnrr1rwr __classcell__)rFs@rr*r*,s{ GO!N & D  ,+2hK2 @,\ &*rr*c |j}|Mtjj tjj t jd}|S#t$rd}Y^wxYw)zReturn 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=rVrWdirnameabspathr]argv)rGrs r get_bindirrSsY ~!!=> M s A A-,A-r)os.pathrVr]loggingroptparser configobjrrtwisted.python.compatr landscape.librrrr*rr(rrrs@ !$," \ d*d*N r