-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.pyhtml
executable file
·68 lines (68 loc) · 2.42 KB
/
list.pyhtml
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<%!
import cgi, os, time, mimetypes, datetime, re
%>
<%
mimetypes.init()
fArray = []
for fileString in os.listdir(filename[0:-12]):
fArray.append(fileString)
def sizeof(num):
if num < 1024.0:
return str(num) + "B"
for x in ['B','K','M','G','T']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0
%>
<html>
<head>
<link rel="stylesheet" href="/style.css" />
<title>No index.pyhtml</title>
<style>
list {background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;}
table {margin-left: 12px;}
th, td {font: 90% monospace; text-align: left;}
th {font-weight: bold; padding-right: 14px; padding-bottom: 3px;}
td {padding-right: 14px;}
tr, td, th {padding-bottom:0px;margin-bottom:0px;}
.s {text-align: right;}
</style>
</head>
<body>
<h2>Directory listing for ${cgi.escape(uri)}</h2>
<div id="content">
<h3>The file <span style="background-color:lightgrey;border:1px solid grey;border-radius:4px;">${cgi.escape(uri)}</span> could not be found</h3>
This is a directory listing
<hr />
<div class="list">
<table>
<thead>
<tr>
<th>Name</th>
<th>Last modified</th>
<th>Size</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr><td><a href="${uri[0:-13-(len(re.split('\/',uri[0:-12])[-2]))]}">Parent Directory</a>/</td><td>${datetime.datetime.strptime(time.ctime(os.path.getmtime(filename[0:-12]+"/..")),"%a %b %d %H:%M:%S %Y").strftime("%Y-%b-%d %H:%M:%S")}</td><td class="s">- </td><td>Directory</td> <!-- If you can make sense of this line, god help you -->
% for fileString in fArray:
<tr>
% if os.path.isdir(filename[0:-12] + fileString):
<td><a href="${cgi.escape(uri[0:-12]+fileString)}">${cgi.escape(fileString)}</a>/</td>
<td>${datetime.datetime.strptime(time.ctime(os.path.getmtime(filename[0:-12]+"/"+fileString)),"%a %b %d %H:%M:%S %Y").strftime("%Y-%b-%d %H:%M:%S")}</td>
<td class="s">- </td>
<td>Directory</td>
% else:
<td><a href="${cgi.escape(uri[0:-12] + fileString)}">${cgi.escape(fileString)}</a></td>
<td>${datetime.datetime.strptime(time.ctime(os.path.getmtime(filename[0:-12]+"/"+fileString)),"%a %b %d %H:%M:%S %Y").strftime("%Y-%b-%d %H:%M:%S")}</td>
<td class="s">${sizeof(os.path.getsize(filename[0:-12]+"/"+fileString))}</td>
<td>${mimetypes.guess_type(filename[0:-12]+"/"+fileString)[0]}</td>
% endif
</tr>
% endfor
</tbody></table></div>
</div>
<div id="foot" onClick="window.location = 'http://makotemplates.org'">Mako template engine.</div>
</body>
</html>