Edgewall Software
Modify

Opened 13 years ago

Last modified 7 years 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 Branch:
Release Notes:
API Changes:
Internal 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@…> 13 years ago.
Patch against Trac 0.12.1

Download all attachments as: .zip

Change History (4)

by Sebastian Krysmanski <sebastian@…>, 13 years ago

Attachment: config.diff added

Patch against Trac 0.12.1

comment:1 by Christian Boos, 13 years ago

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

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

comment:2 by Jun Omae, 9 years ago

Cc: Jun Omae added

comment:3 by Ryan J Ollos, 7 years ago

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 7 years 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. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


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