coding utf8 from mod_python import apache import os HOST server def in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf8 -*-
from mod_python import apache
import os
HOST='server'
def index(req,dir=None):
def out(txt):
req.write(str(txt)+'\n')
req.content_type='text/html'
fcwd=os.path.dirname(__file__)
lister=os.path.basename(__file__)
if dir:
os.chdir(dir)
else:
os.chdir(fcwd)
cwd=os.getcwd()
out('Current working dir: %s<br><br>' %cwd)
lst_objects=os.listdir(cwd)
### Displaying directories
out('[D] <a href="http://%(hst)s/%(lst)s?dir=..">UP</a><br><br>' %{'hst':HOST,'lst':lister})
for object in lst_objects:
if os.path.isdir(object):
out('[D] <a href="http://%(hst)s/%(lst)s?dir=%(obj)s">%(obj)s</a><br>' %{'hst':HOST,'lst':lister,'obj':object})
out('<br>')
### Displaying files
for object in lst_objects:
if os.path.isfile(object):
out('[F] <a href=%(obj)s>%(obj)s</a><br>' %{'obj':object})