I'm attempting to create what I believe should be a very simple Trac plugin. All I want to do is set the database string from an environmental variable.
I've been playing around with this for a bit now, and I can't figure out the way I ought to do this.
I'm under the impression that I want to do something like the following:
self.config.set('trac', 'database', os.environ.get('DATABASE_URL'))
But I'm not sure where. Or how.
Thanks for any help,
~Drew Carey Buglione
In theory , yes . Nevertheless DB string is supposed to be configured in trac.ini . I'm not sure if your approach will work , but I wonder why is it that config is not enough for you ? Maybe what you need is not exactly a plugin but an external script ?
Heroku provides the database string as an environmental variable, though, so if anyone has any idea how I can go about resolving my problem th e way I'd like to, I'd really appreciate some pointers.
~Drew Carey Buglione
My reason for desiring to do things this way is simple: I'm running Trac on Heroku, where there is a convention of keeping all private or environment-specific data in config variables.
I can not deploy any files to Heroku without checking them into version control, and I'd like to avoid checking my database string into version control.
Heroku provides the database string as an environmental variable, though, so if anyone has any idea how I can go about resolving my problem the way I'd like to, I'd really appreciate some pointers.
> There's definitely no well supported way to do this, and a plugin wouldn'tConsidering that there's a real use case for this , question is : is
> really be the right approach for the reason Olemis mentioned (chicken/egg).
>
it a good idea to request for this enhancement by creating a ticket in
t.e.o issue tracker ?
So, I gave up on doing things within Trac, and combined the two approaches suggested earlier. My setup is documented here: https://github.com/drewbug/heroku-trac#protect-database-string
As for changes to the configuration file not persisting: I'm not too worried at the moment, but I'm not exactly able to come up with an idea on what the worst-case scenario would be. Ideas?
So, I gave up on doing things within Trac, and combined the two approaches suggested earlier. My setup is documented here: https://github.com/drewbug/heroku-trac#protect-database-stringThis is really cool, thanks for sharing it.
As for changes to the configuration file not persisting: I'm not too worried at the moment, but I'm not exactly able to come up with an idea on what the worst-case scenario would be. Ideas?Well .. changing which plugins/components are active through the web interface is probably the biggest // most likely problem. If you do change that through the web UI and then Heroku decides to wipe out your changes, I guess you could conceivably end up with a broken site, or at least one that does not behave at all how you expect it to.
A couple of other (probably minor) things that can be changed TTW and therefore might reset unexpectedly would be the project name, url, default timezone and language, and logging configuration.The other thing that seems both likely and major (at least from my own usage) would be custom ticket fields or ticket workflow changes, but those are both only editable through the web via plugins (CustomFieldAdminPlugin and TracWorkflowAdminPlugin) so if you don't have those installed you're probably pretty OK.Similarly if you have IniAdminPlugin installed all bets are off.And of course it's hard to pin down exactly what through-the-web edits will result in config changes once you get into plugin-land.
I wonder if the entire Configuration implementation needs to be swappable