added date and color to SimpleWebPage

This commit is contained in:
Ville Rantanen
2015-06-25 09:16:35 +03:00
parent 57f924d94c
commit fe5ac26e53
2 changed files with 49 additions and 16 deletions

View File

@@ -3,7 +3,7 @@
''' A script that creates index.html indexes for a folder.
'''
import os,sys
import os,sys,time
import urllib
INDEXFILE='index.html'
@@ -54,21 +54,40 @@ def generate_index(opts):
def get_filelink(path,fname):
fsize=os.path.getsize(os.path.join(path,fname))
fsstr=sizeof(fsize)
return '<tr><td><a href="'+urllib.quote(fname)+'">'+fname+'</a><td>'+fsstr+'</td></tr>\n'
fdate=time.localtime(os.path.getmtime(os.path.join(path,fname)))
fdstr=time.strftime("%Y/%m/%d %H:%M:%S",fdate)
return '<tr><td><a href="'+urllib.quote(fname)+'">'+fname+'</a><td class="right">'+fsstr+'</td><td class="right">'+fdstr+'</td></tr>\n'
def get_pathlink(path):
return '<tr><td><a href="'+urllib.quote(path)+'">'+path+'</a><td></td></tr>\n'
fdate=time.localtime(os.path.getmtime(path))
fdstr=time.strftime("%Y/%m/%d %H:%M:%S",fdate)
return '<tr><td><a href="'+urllib.quote(path)+'">'+path+'</a><td class="right">[DIR]</td><td class="right">'+fdstr+'</td></tr>\n'
def get_header(title):
header='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of '''+title+'''</title>
<style>
body {
font-family: monospace;
}
table {
background-color: gray;
}
td, th {
text-align: left;
background-color: lightgray;
padding: 0.5ex;
}
.right {
text-align: right;
}
</style>
</head>
<body>
<h1>Index of '''+title+'''</h1>
<table><tr><th>Name</th><th>Size</th></tr>
<table><tr><th>Name</th><th class="right">Size</th><th class="right">Modified</th></tr>
'''
return header
@@ -78,11 +97,11 @@ def get_footer():
return footer
def sizeof(num):
for x in ['bytes','KB','MB','GB','TB']:
for x in ['&nbsp;B','KB','MB','GB','TB']:
if num < 1024.0:
if x=='bytes':
return "%d %s" % (num, x)
return "%3.1f %s" % (num, x)
if x=='&nbsp;B':
return "%d&nbsp;%s" % (num, x)
return "%3.1f&nbsp;%s" % (num, x)
num /= 1024.0
opts=setup()