[Grok-dev] Allow to list a directory.

Hector Blanco white.lists at gmail.com
Wed Mar 2 20:13:22 EST 2011


Hello list!

I have created a little application and now I want to put an egg... in
a folder.

I'd like to know how can I allow listings to that directory (so I can
use it as an egg repository).

I have setup a grokproject (or a grokserver, however you prefer) in a
folder named "server". The tree structure looks (more or less) like:

server/
   + bin/
   + eggs/
   + log/
   + src/
       + server/
           + static/

The "eggs" directory is the one I want to list (because I'm going to
put my egg in there)

I set it up with the fanstatic thing... It's really great...

Just in case (maybe someone has a better advice or this helps somebody
else), to "serve" a directory:

1) Create the directory.
2) Add it to server/src/server/resource.py so it will look like:

   from fanstatic import Library, Resource

   library = Library('server', 'static')
   eggs = Library('eggs', '../../eggs')
   # or: eggs = Library('eggs', '/home/hbr/server/eggs/')
   style = Resource(library, 'style.css')

3) Add the entry point into the server/setup.py

      entry_points={
          'fanstatic.libraries': [
              'server = server.resource:library',
              'eggs = server.resource:eggs',
          ]
      })

4) Re-run buildout

If I put a "test.txt" file under the server/eggs/ folder, I can
properly access it in a (super cool) very easy way:
    http://127.0.0.1:8080/fanstatic/eggs/test.txt

But when I try to list the directory (access the directory itself with
my browser: http://127.0.0.1:8080/fanstatic/eggs/), I get a nasty "403
Forbidden" error.

I would like to allow that "eggs" directory (and only that one, not
the "src/server/static/" one) to be listed so I can use it as an egg
repository) Is that possible? I can always create an "eggs" view in my
app.py, which access the folder, list its contents and generates the
same html (with the hrefs for each element found in the folder and all
that stuff) that a regular directory listing would generate. But that
doesn't seem too "professional", right?

Thanks in advance!


More information about the Grok-dev mailing list