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
< 1024: return "%s octets" % size
56 if size
< 1024: return "%s Kio" % size
58 if size
< 1024: return "%s Mio" % size
60 if size
< 1024: return "%s Gio" % size
62 return "%s Tio" % size
64 def my_cmp(name1
, name2
):
65 m1
= re
.match('[0-9]+', name1
)
66 m2
= re
.match('[0-9]+', name2
)
68 return cmp(name1
, name2
)
72 return cmp(name1
[m1
.end():], name2
[m2
.end():])
76 path
= os
.path
.join(os
.environ
["PWD"], dir)
77 names
= os
.listdir(path
)
78 dirs
= [x
for x
in names
if os
.path
.isdir(os
.path
.join(path
, x
))]
80 files
= [x
for x
in names
if os
.path
.isfile(os
.path
.join(path
, x
))]
81 files
.sort(cmp=my_cmp
)
85 path
= os
.path
.join(os
.environ
["PWD"], file)
86 return os
.path
.getsize(path
)
88 def dir_content(root
, level
=0):
91 dirs
, files
= my_listdir(root
)
92 content
= space
+ u
"""<div id="l%s" class="%s"><ul>\n""" \
93 % (id_number
, level
== 0 and "visible" or "hidden")
96 content
+= space
+ u
"""<li>"""
97 content
+= u
"""<a href="javascript:void(0)" onclick="sw('l%s')">%s</a>""" \
98 % (id_number
, dir.decode('utf-8'))
99 content
+= u
"""</li>\n"""
100 content
+= dir_content(os
.path
.join(root
, dir), level
+ 1)
103 content
+= space
+ u
"""<li>"""
104 content
+= u
"""<a href="%s">%s</a> <em>(%s)</em>""" \
105 % (urllib
.quote(root
+'/'+file), file.decode('utf-8'),
106 human_size(my_getsize(os
.path
.join(root
, file))) )
107 content
+= u
"""</li>\n"""
108 content
+= space
+ u
"""</ul></div>\n"""
111 def handler(request
):
112 html
= HTML
% {'content': dir_content(".")}
113 request
.content_type
= "text/html; charset=utf-8"
114 request
.write(html
.encode('utf-8'))
115 return mod_python
.apache
.OK