Could you submit
this as a patch to Sourceforge?
Note that there is
already similar code in ServletFactory that will add the __init__.py if
necessary when importing a servlet. That apparently doesn't help you if
you forgot to put the __init__.py into the main context directory because it
tries to import all contexts right at the beginning. But, if you add
subdirectories of your context directory, the __init__.py will be created in
each subdirectory automatically the first time you access a servlet in that
subdirectory.
-
Geoff
-----Original Message-----Dear webware community
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 29, 2003 5:56 PM
To: webware-devel
Subject: [Webware-devel] __init__ context requirment
a recent email by Lothar Scholz, points out an interesting question/problem which has bitten me at least a few times. when you make a new context, if you fortet to add the required __init__.py file to it the context will fail to load correctly. This can cause problems especially for folks new to webkit if they do not realise that a context is loaded like a standart python module. To correct this I added the folloing code my the addContext function in the application.py file:
orginal code:
def addContext(self, name, dir):
if self._contexts.has_key(name):
print 'WARNING: Overwriting context %s (=%s) with %s' % (
repr(name), repr(self._contexts[name]), repr(dir))
__contextInitialized = 1 # Assume already initialized.
else:
__contextInitialized = 0
.....
Modified code:
def addContext(self, name, dir):
# Code added by Jose
# __init__ check file code
# this code will check for the __init__ file and add it if necessary
if not os.path.exists(os.path.join(dir, '__init__.py')):
# __init__.py file is missing creat it
print '__init__ file is missing, creating __init__ file now'
init = file(os.path.join(dir, '__init__.py'), 'w')
init.write('# Auto generated __init__ file\n')
init.close()
# end __init__ file check code
# end Code added by Jose
if self._contexts.has_key(name):
print 'WARNING: Overwriting context %s (=%s) with %s' % (
repr(name), repr(self._contexts[name]), repr(dir))
__contextInitialized = 1 # Assume already initialized.
else:
__contextInitialized = 0
......
Note that I am not doing anything special other then checking to see if the file is present proir to your loading the context, if it is present I do nothing, otherwise I make one with a single comment line in the file. I think its a nice feature to add as we move to 0.9
Jose
------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 _______________________________________________ Webware-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/webware-devel