B t `ëã@stdZddlZddlmZmZmZmZmZm Z ddl m Z m Z m Z Gdd„deƒZGdd„deƒZGd d „d eƒZdS) a This package defines the Configuration class, which provides a generic interface for reading/writing configuration files. This class uses a simple model for configuration data: section -> option -> value A key role of this class is to support initialization of Option objects. éN)Ú PluginErrorÚ InterfaceÚPluginÚExtensionPointÚ implementsÚIOptionDataProvider)ÚIOptionÚ IFileOptionÚIUpdatedOptionsActionc@seZdZdZdS)ÚConfigurationErrorzEException raised when a value in the configuration file is not valid.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrúK/tmp/pip-unpacked-wheel-cqckmaqz/pyutilib/component/config/configuration.pyr sr c@s eZdZdZdd„Zdd„ZdS)ÚIConfigurationzdDefine an interface for classes that are used by Configuration to read/write configuration data.cCsdS)z4Returns a list of tuples: [ (section,option,value) ]Nr)ÚselfÚfilenamerrrÚloadszIConfiguration.loadcCsdS)z5Save configuration information to the specified file.Nr)rrÚconfigrrrÚsave"szIConfiguration.saveN)r r rrrrrrrrrsrc@s^eZdZdZddd„Zdd„Zdd „Zd d „Zd d „Zddd„Z ddd„Z dd„Z dd„Z dS)Ú Configurationa*This class manages configuration data. Further, this configuration I/O is coordinated with Option objects. When configuration data is read in, associated Option plugins are populated. Similarly, when configuration data is writen, the configuration data is taken from Option data.NÚ ConfigParsercCsJd|_||_ttƒ|_ttƒ|_ttƒ|_tt ƒ|_ tt ƒ|_ |  ¡dS)zËConstructor. @param filename - The associated configuration file. @param parser - Specify the name of the parser used to read/write configuration files. ZConfiguration_ConfigParserN)Ú parser_typerrrÚparsersrÚoption_pluginsrÚoption_data_pluginr Úpathoption_pluginsr Úpostconfig_actionsÚclear)rrÚparserrrrÚ__init__-s     zConfiguration.__init__cCsg|_i|_g|_dS)zClear local data.N)rÚdataÚsection)rrrrr ?szConfiguration.clearcCs ||jkS)zWReturn whether the configuration contains a section of the given name. )r#)rÚnamerrrÚ __contains__EszConfiguration.__contains__cCs$||jkrtd|dƒ‚|j|S)z9Return the configuration section with the specified name.z No section z in data)r#r )rr%rrrÚ __getitem__Ks zConfiguration.__getitem__cCst|j ¡ƒS)zW|j  |j ¡  |j¡|_ i|_ g|_xd|j D]Z\}}}||j kr°|j |¡i|j |<||j |krÌg|j ||<|j || |¡q†Wx¢|jD]˜}g}x"|jD]}| |¡rü| |¡qüWxj|j |D]\}d} x6|D].}| |¡r2|  ||j ||¡p\| } q2W| s$td|j||fƒ‚q$WqìWx|jD]}| ¡qWdS)zLoad configuration from a file.rz(No IConfiguration parsers are registeredNzCannot load without a filenameFzCProblem loading file %r. Option %r in section %r is not recognized!)Úlenrr rrZset_dirÚosÚpathÚdirnameÚservicerrrr#r$ÚappendrÚmatches_sectionÚ matches_namerZreset_after_updates) rrÚoptionÚsÚoÚvÚsecÚpluginsÚpluginÚflagrrrrUsF           zConfiguration.loadc CsP|dk r||_|jdkr tdƒ‚| ¡|j ¡ ¡|_t|j ¡ƒ|_ |j   ¡d}d}xÀ|j D]¶}g}x"|j D]}|  |¡rr|  |¡qrWt|j| ¡ƒ}|  ¡xn|D]f}x`|D]X}| |¡r¸|j||dk rú|j||} |j  ||| f¡nd}|d||f}Pq¸Wq®WqbW|r,|d}nd}|j |j¡ |j|j|¡dS)zSave configuration to a file.NzCannot save without a filenameFz\ Note: the following configuration options have been omitted because their value is 'None': Tz section=%r option=%r Ú )rr r rr/Úget_datar#r(r)r$Úsortrr1r0r2rrrr) rrr:Úheaderr7r8r9Úoptionsr3Úvalrrrrˆs@          zConfiguration.savecCs8d}x&|jD]\}}}|d|||f7}q Wt|ƒdS)z1Print a simple summary of the configuration data.Úz [%s] %s = %s N)rÚprint)rÚtextr4r5r6rrrÚpprint´szConfiguration.pprintcCsøi}x"|jD]}|| |ji¡|j<q Wt| ¡ƒ}| ¡x¶|D]®}td|dƒtdƒt|| ¡ƒ}| ¡xp|D]h}td|||jƒtd|||jj ƒtd|||  ¡ƒtd|||j ƒtdƒq|WtdƒqBWdS) zSummarize optionsú[ú]rAz Option: z Type: z Default: z Doc: N) rÚ setdefaultr$r%r(r)r=rBÚ __class__r Z default_strr)rÚtmpr3r)ÚkeyZokeysZokeyrrrÚ summarize»s"     zConfiguration.summarize)Nr)N)N) r r rrr"r r&r'r*rrrDrKrrrrr&s  3 ,r)rÚos.pathr,Zpyutilib.component.corerrrrrrZ!pyutilib.component.config.optionsrr r r rrrrrrÚs