On 17 Sep, 2008, at 18:30 , Noah Kantrowitz wrote:
> You are asking the wrong question. What are _actually_ trying to do?
Well the question is more than right... :-) And is also pretty clear I
thought... I have a normal python class, that has a specific
__metaclass__ which is used to initialize the python object. My class
is doing something similar to the Trac Component and ComponentMeta, to
give you an example.
What I want to do is to be able to access the Trac Environment and
read the configuration file as well as access the database in the
__new__ method of the metaclass of my class. So is like accessing the
Trac Environment from the __new__ of the ComponentMeta. Obviously
being a type is not a "real" instance, and there is no chance I can
pass the environment over...
What I would like to achieve is to have a dynamic type that changes
based on the Trac configured properties and custom fields. I can do in
the __init__ of the instantiated object of course... and is the way I
implemented it right now, but it is not semantically correct, in fact
the changes to the type should occur in the type initialization, in a
static context, to be done once for all the instances of the object.
Looking at the Trac source I didn't found any static method or class
method that returns the Environment currently used, the one in the
context. There is a static method in the package env.py
(open_environment) that if not already present will initialize a new
Environment and return it, but it needs the env_path, which is
normally written in the trac.ini and passed through at the startup of
the server, or better the ComponentManager (alias Environment object).
So my problem is once more:
MyMetaClass(type):
def __new__(cls, name, bases, cdict):
# Need to get the trac env here...
# So I can read the config and set attributes in the __slots__
according to properties set in trac.ini
MyClass(object):
__metaclass__ = MyMetaClass
def __init__(self, *args, **kwargs):
# Here I should find all the attributes for this type...
So is there any way to get from the globals or wherever a pointer
either to the current Environment object or to the env_path so I can
get the Environment using open_environment?
Thanks
> --Noah
ANdreaT
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---