Edgewall Software
Modify

Opened 8 years ago

Last modified 14 months ago

#9967 new enhancement

Allow setting option values through Option objects

Reported by: Sebastian Krysmanski <sebastian@…> Owned by:
Priority: normal Milestone: next-major-releases
Component: general Version: 0.12.1
Severity: normal Keywords: config patch
Cc: Jun Omae
Release Notes:
API Changes:

Description

Trac currently allows the user to read an option's value through a Option object, like in the following code:

class MyComponent(Component):
  my_option = Option('my_section', 'my_option')
  
  def my_func(self):
    # retrieving option value
    my_option_value = self.my_option

When calling my_func(), my_option_value will be filled with the current option values (as specified in trac.ini).

Now, while retrieving works this way, one can't set the option value this way.

class MyComponent(Component):
  my_option = Option('my_section', 'my_option')
  
  def my_func(self):
    # setting option value
    # will raise an AttributeError
    self.my_option = 'test'
    self.config.save()

I've created a patch that enables this functionality. I've done some tests with it and it seems to work for Option and all of its subclasses.

Attachments (1)

config.diff (7.5 KB ) - added by Sebastian Krysmanski <sebastian@…> 8 years ago.
Patch against Trac 0.12.1

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by Sebastian Krysmanski <sebastian@…>

Attachment: config.diff added

Patch against Trac 0.12.1

comment:1 Changed 8 years ago by Christian Boos

Keywords: config patch added
Milestone: next-major-0.1X

Interesting. You may want to revise the patch once #7378 is finalized.

comment:2 Changed 4 years ago by Jun Omae

Cc: Jun Omae added

comment:3 Changed 14 months ago by Ryan J Ollos

It might be good to delegate to the setter code that checks valid values, such as: LoggingAdminPanel.render_admin_panel.

Related, it would be nice if TracAdmin config set raised an error when setting an invalid value, at least for options defined in ExtensionOption and OrderedExtensionOption. Similarly, when enabling/disabling components with TracAdmin, we autocomplete the components:

> config set components tracopt.versioncontrol.
tracopt.versioncontrol.git.git_fs.csetpropertyrenderer
tracopt.versioncontrol.git.git_fs.gitconnector
tracopt.versioncontrol.git.git_fs.gitwebprojectsrepositoryprovider
tracopt.versioncontrol.svn.svn_fs.subversionconnector
tracopt.versioncontrol.svn.svn_prop.subversionmergepropertydiffrenderer
tracopt.versioncontrol.svn.svn_prop.subversionmergepropertyrenderer
tracopt.versioncontrol.svn.svn_prop.subversionpropertyrenderer

It would be nice to raise an error when attempting to enable/disable a invalid component.

Last edited 14 months ago by Ryan J Ollos (previous) (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set.
The owner will be changed from (none) to anonymous.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.