Hello list,
First of all, thanks for this great software!.
I'm working on a personal project that use Trac architecture and I found a
thing that can be improved in components implementation.
When we use 'ExtensionOption' or 'OrderedExtensionOption' from config module
as component option, all components that declare implement certain interface
are instantiated if wasn't before. This means that components that are not
declared as desired extension are initialized anyway.
Some components maybe needs check for resources to work. That checks can be
done in intialization of that component. But if all components are initialized
even if we don't want to use that component, these resources are checked (or
taked).
Simple use case for clarification: a session component that optionaly use
differents backends to store data.
class ISessionStore(Interface):
def load(self, session_id):
"Retreive session object"
def save(self, session_object):
"Store session object"
class SessionComponent(Component):
session_backend = ExtensionOption('sessions', 'backend', ISessionStore,
'MemorySessionStore', """Session backend to store data.""")
def process_request(self, request):
sess = self.session_backend.load(request.session_id)
# ... do something with sess object
self.session_backend.save(sess)
class MemorySessionStore(Component):
implements(ISessionStore)
def __init__(self): # initialization
self._data = {}
def load(self, session_id):
return self._data.get(session_id, None)
def save(self, session_object):
self._data[session_object.id] = session_object
class FilesystemSessionStore(Component):
implements(ISessionStore)
def __init__(self): # initialization
# ... check write permission on filesystem
def load(self, session_id):
# ... load session from filesytem
def save(self, session_object):
# ... save session to filesytem
class DatabaseSessionStore(Component):
implements(ISessionStore)
def __init__(self): # initialization
# ... check connection to specified database and connect
def load(self, session_id):
# ... use previously opened connection and load session
def save(self, session_object):
# ... use previously opened connection and save session
and then in the configuration file we can have:
[sessions]
backend = FilesystemSessionStore # I don't have database server :(
thus DatabaseSessionStore.__init__() is never called because I know that we
have not database server.
This can be done with current implementation if we add some extra code for
initializations things, but this is unnatural when we have __init__() method
for those things.
I have elaborated a little patch that fix this, initializing only components
that are used. This patch is delicated because touch some important files in
the project (trac/core.py and trac/config.py).
Before open a ticket in Trac trac I want to know your opinions about this.
Sorry for my basic english.
Best Regards,
-- Augusto
--
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en.