|
From: Michael F. <fuz...@vo...> - 2009-07-13 14:52:23
|
Robert Šmol wrote:
> Hi,
>
> thanks for help. Can you advise me since when it is supported?
It's probably a 4.6 feature. You can try just omitting the '_inspec'
keyword. There is a slight issue with the parsing of commas in
configspecs prior to version 4.6 - but in most cases it 'just works'.
I hope this is helpful.
All the best,
Michael
> I have
> python-configobj 4.5.2-1 installed, I am getting:
> rsmol@rsmol-laptop:~/Code/xdrmove$ python src/xdrmove/__init__.py -c
> data/test-config.nin start
> Traceback (most recent call last):
> File "src/xdrmove/__init__.py", line 453, in <module>
> main()
> File "src/xdrmove/__init__.py", line 449, in main
> terminator = XDRSwitch()
> File "src/xdrmove/__init__.py", line 163, in __init__
> self.config = self.init_settings(configFile)
> File "src/xdrmove/__init__.py", line 393, in init_settings
> _inspec=True)
> File "/var/lib/python-support/python2.5/configobj.py", line 1265, in __init__
> raise TypeError('Unrecognised option "%s".' % entry)
> TypeError: Unrecognised option "_inspec".
>
> This is excerpt from the file.
>
> configSpec = ConfigObj(_configspec,
> interpolation=False,
> list_values=False,
> _inspec=True)
>
> I am sorry if this is newbie question.
>
> On Sat, Jul 4, 2009 at 9:36 PM, Michael Foord<fuz...@vo...> wrote:
>
>> Robert Šmol wrote:
>>
>>> Hi,
>>> response is unbelievable quick enough if compared to our R&D ;)
>>>
>>>
>>>
>> Hmmm... I think interpolation should be switched off by default in
>> configspec reading - but that would be a backwards incompatible change.
>> Here is a workaround:
>>
>> >>> config = ConfigObj(configFile, configspec=ConfigObj(_configspec,
>> interpolation=False, _inspec=True, list_values=False))
>> >>> results = config.validate(validator)
>>
>> All the best,
>>
>> Michael Foord
>>
>>
>>
>>> Here is the code to reproduce the problem:
>>>
>>>
>>> from configobj import ConfigObj, flatten_errors
>>> from validate import Validator
>>>
>>> #some defaults
>>> _pidFile = '/var/run/xdr.pid'
>>> _defaultLogFormat = '%(asctime)s - %(levelname)s - %(message)s'
>>>
>>> #configspec is used to validate configuration file
>>> _configspec = ('''
>>> [general]
>>> pid_file = string(min=1, max=100, default=%s)
>>>
>>> [logging]
>>> level= option('INFO','DEBUG','CRITICAL','ERROR', default='INFO')
>>> log_format = string(min=1, max=100, default=%s)
>>> ''' % (_pidFile, _defaultLogFormat)).split('\n')
>>>
>>> #dummy config file
>>> configFile = ''
>>>
>>>
>>> #main loop, if called as a program start main
>>> if __name__ == '__main__':
>>> validator = Validator()
>>> config = ConfigObj(configFile,configspec=_configspec)
>>> results = config.validate(validator)
>>> <<<<<<<<<<<<<<<<
>>>
>>> The problem is, config['log_format'] should be '%(asctime)s -
>>> %(levelname)s - %(message)s'
>>> and the values 'asctime' are interpolated when using logging facility,
>>> but they are evaluated during validation. Perhaps I just need to
>>> somehow properly escape?
>>>
>>> Thanks,
>>>
>>> Robert
>>>
>>>
>>> On Thu, Jul 2, 2009 at 4:51 PM, Michael Foord<fuz...@vo...> wrote:
>>>
>>>
>>>> Robert Šmol wrote:
>>>>
>>>>
>>>>> Hi,
>>>>> I have following for my config spec:
>>>>>
>>>>> _defaultLogFormat = '%(asctime)s - %(levelname)s - %(message)s'
>>>>> _configspec = ('''
>>>>> [general]
>>>>> log_format = string(min=1, max=100, default=%s)
>>>>> ''' % (_defaultLogFormat)).split('\n')
>>>>>
>>>>> When I execute I get the MissingInterpolationError
>>>>> ...
>>>>> ..
>>>>> File "/var/lib/python-support/python2.5/configobj.py", line 368, in
>>>>> recursive_interpolate
>>>>> k, v, s = self._parse_match(match)
>>>>> File "/var/lib/python-support/python2.5/configobj.py", line 454, in
>>>>> _parse_match
>>>>> value, section = self._fetch(key)
>>>>> File "/var/lib/python-support/python2.5/configobj.py", line 424, in _fetch
>>>>> raise MissingInterpolationOption(key)
>>>>> configobj.MissingInterpolationOption: missing option "asctime" in interpolation.
>>>>>
>>>>> How do I get round this?
>>>>>
>>>>>
>>>>>
>>>> Sorry for the slow response I'm currently at EuroPython. Can you send me
>>>> a config file and *full* code to reproduce this.
>>>>
>>>> Thanks
>>>>
>>>> Michael
>>>>
>>>>
>>>>
>>>>> ------------------------------------------------------------------------------
>>>>> _______________________________________________
>>>>> Configobj-develop mailing list
>>>>> Con...@li...
>>>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>>>>
>>>>>
>>>>>
>>>> --
>>>> http://www.ironpythoninaction.com/
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> _______________________________________________
>>>> Configobj-develop mailing list
>>>> Con...@li...
>>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>>>
>>>>
>>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Configobj-develop mailing list
>>> Con...@li...
>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>>
>>>
>> --
>> http://www.ironpythoninaction.com/
>> http://www.voidspace.org.uk/blog
>>
>>
>>
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Configobj-develop mailing list
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>
>>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/blackberry
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
|