Search code examples
configurationtrac

How to remove a value from the config in Trac


The config api within Trac is a pretty straight forward way of storing and loading settings from the config file. However, I haven't yet found a method to delete a line, or to delete all lines from a category that have no value assigned. So far I can only set the values to False or an empty string to deactivate them.

What I want to do is remove all values from my plugin's category that were set manually in the file and are not accepted by my script, or were set to False or no value by the script. In both ways, the whole line should be removed from the config so that it doesn't contain a lot of lines that look like this:

some_setting = 

Edit
I just found out that I can assign None as value, which comments the setting, and the next time Trac writes to the config file it removes the commented line. This is a possible workaround, but I'm still interested in whether a direct method exists.


Solution

  • You can use Configuration.remove(...). Within a Component class call self.config.remove('section', 'key').