Webware / CGIWrapper / Examples / Directory.py

import os
from operator import itemgetter
from stat import ST_SIZE

print '''%s
        <title>Webware CGI Examples Directory</title>
        <h1 align="center">Webware CGI Examples</h1>
''' % wrapper.docType()

# Create a list of dictionaries, where each dictionary stores information about
# a particular script.
scripts = sorted((dict(pathname=filename,
    shortname=filename[:-3], size=os.stat(filename)[ST_SIZE])
    for filename in os.listdir(os.curdir)
    if len(filename) > 3 and filename.endswith('.py')),

print '''\
        <table cellspacing="0" cellpadding="4" border="1" align="center">
                <th align="right">Size</th>
                <th align="left">Script</th>
                <th align="left">View</th>

for script in scripts:
    print '''\
                <td align=right>%(size)d</td>
                <td><a href="%(shortname)s">%(shortname)s</a></td>
                <td><a href="View?filename=%(shortname)s">view</a></td>
            </tr>''' % script

print '''\
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.