2 # -*- coding: utf-8 -*-
4 Index automatique des dossiers et sous-dossiers et liens sur les fichiers.
5 (Page de téléchargement pour les documents de la CRE en Asie-Pacifique.)
7 Copyright : Agence universitaire de la Francophonie
8 Licence : GNU General Public Licence, version 2
9 Auteur : Jean Christophe André
10 Date de création : 25 mars 2009
19 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
22 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
24 <style type="text/css">
25 body { background: url('Bamboo2.png') #80FF80; }
26 a { color: black; text-decoration: none; }
27 a:hover { color: black; text-decoration: underline; }
28 a:visited { color: black; text-decoration: underline; }
29 li { padding: 3pt; list-style: none; font-weight: bold; font-family: sans; }
30 li em { color: black; font-size: 70%%; }
31 .hidden { display: none; }
32 .visible { display: inline; }
34 <script type="text/javascript">
36 elt = document.getElementById(id)
37 if (elt.className == 'hidden') {
38 elt.className = 'visible';
40 elt.className = 'hidden';
54 if size
<= 1: return "%s octet" % size
55 if size
< 1024: return "%s octets" % size
57 if size
< 1024: return "%s Kio" % size
59 if size
< 1024: return "%s Mio" % size
61 if size
< 1024: return "%s Gio" % size
63 return "%s Tio" % size
65 def my_cmp(name1
, name2
):
66 m1
= re
.match('[0-9]{1,8}', name1
)
67 m2
= re
.match('[0-9]{1,8}', name2
)
69 return cmp(name1
, name2
)
73 return cmp(name1
[m1
.end():], name2
[m2
.end():])
77 path
= os
.path
.join(os
.environ
["PWD"], dir)
78 names
= os
.listdir(path
)
79 dirs
= [x
for x
in names
if os
.path
.isdir(os
.path
.join(path
, x
))]
81 files
= [x
for x
in names
if os
.path
.isfile(os
.path
.join(path
, x
))]
82 files
.sort(cmp=my_cmp
)
86 path
= os
.path
.join(os
.environ
["PWD"], file)
87 return os
.path
.getsize(path
)
89 def dir_content(root
, level
=0):
92 dirs
, files
= my_listdir(root
)
93 content
= space
+ u
"""<div id="l%s" class="%s"><ul>\n""" \
94 % (id_number
, level
== 0 and "visible" or "hidden")
97 content
+= space
+ u
"""<li>"""
98 content
+= u
"""<a href="javascript:void(0)" onclick="sw('l%s')">%s</a>""" \
99 % (id_number
, dir.decode('utf-8').replace('_',' '))
100 content
+= u
"""</li>\n"""
101 content
+= dir_content(os
.path
.join(root
, dir), level
+ 1)
104 content
+= space
+ u
"""<li>"""
105 content
+= u
"""<a href="%s">%s</a> <em>(%s)</em>""" \
106 % (urllib
.quote(root
+'/'+file),
107 file.decode('utf-8').replace('_',' '),
108 human_size(my_getsize(os
.path
.join(root
, file))) )
109 content
+= u
"""</li>\n"""
110 content
+= space
+ u
"""</ul></div>\n"""
113 def handler(request
):
114 html
= HTML
% {'content': dir_content(".")}
115 request
.content_type
= "text/html; charset=utf-8"
116 request
.write(html
.encode('utf-8'))
117 return mod_python
.apache
.OK