Here is a suggestion for improvement of the function
findDirectoryIndex in the Application.py module.

The problem is that this function ignores cascading extensions.

For instance, if you have a configuration like this one:
'DirectoryFile': ['index','main'],
'UseCascadingExtensions': 1,
'ExtensionCascadeOrder':['.py','.html'],

Webware 0.8.1 will output an error if you have
an index.html and an index.py file.

I assume this has simply been forgotten when cascading extensions where
introduced and I have added the functionality in the findDirectoryIndex
function (see attachment).

Of course, DirectoryFile has precedence over ExtensionCascadeOrder.
So in the above case, 'index.html' would be prefered over 'main.py'.

Gtx
Christoph Zwerschke
patch of Application.py module:

---- findDirectoryIndex as in Webware 0.8.1 ----

# Handle directories
if debug: print '>> directory = %s' % repr(ssPath)
for dirFilename in self.setting('DirectoryFile'):
    filenames = self.filenamesForBaseName(os.path.join(ssPath, dirFilename))
    num = len(filenames)
    if num==1:
        break  # we found a file to handle the directory
    elif num>1:
        print 'WARNING: the directory is %s which contains more than 1 directory file: 
%s' % (ssPath, filenames)
        return None
if num==0:
    if debug: print 'WARNING: For %s, the directory contains no directory file.' % 
(ssPath)
    return None
ssPath = filenames[0] # our path now includes the filename within the directory
if debug: print '>> discovered directory file = %s' % repr(ssPath)
return ssPath

---- findDirectoryIndex improved version ----

# Handle directories
if debug: print '>> directory = %s' % repr(ssPath)
for dirFilename in self.setting('DirectoryFile'):
    basename = os.path.join(ssPath, dirFilename)
    filenames = self.filenamesForBaseName(basename)
    num = len(filenames)
    if num>1:
        if self.setting('UseCascadingExtensions'):
            for ext in self.setting('ExtensionCascadeOrder'):
                if (basename + ext) in filenames:
                    filenames = [basename + ext]
                    num = 1
                    break
    if num==1:
        break  # we found a file to handle the directory
    if num>1:
        print 'WARNING: the directory is %s which contains more than 1 directory file: 
%s' % (ssPath, filenames)
        return None
if num==0:
    if debug: print 'WARNING: For %s, the directory contains no directory file.' % 
(ssPath)
    return None
ssPath = filenames[0] # our path now includes the filename within the directory
if debug: print '>> discovered directory file = %s' % repr(ssPath)
return ssPath

----

Reply via email to