refurbished css for webpage generator

This commit is contained in:
q
2018-12-06 10:30:10 +02:00
parent ca8439dc4c
commit 5f4a3c9015
2 changed files with 143 additions and 80 deletions

View File

@@ -12,7 +12,7 @@ def get_options():
action = "store_false", action = "store_false",
dest = "move", dest = "move",
default = True, default = True,
help = "Copy file instead of copying", help = "Copy file instead of moving",
) )
parser.add_argument( parser.add_argument(
'-d', '-d',
@@ -112,10 +112,7 @@ if __name__ == "__main__":
else: else:
new_name = get_version_name(opts.file) new_name = get_version_name(opts.file)
if not opts.quiet: if not opts.quiet:
print("%s -> %s"%( print(new_name)
opts.file,
new_name
))
test_existing(new_name, opts.force) test_existing(new_name, opts.force)
if opts.move: if opts.move:
os.rename(opts.file, new_name) os.rename(opts.file, new_name)

View File

@@ -5,7 +5,8 @@
import os,sys,time import os,sys,time
import urllib import urllib
VERSION="20160116"
VERSION = "20181206"
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff'] IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
def setup(): def setup():
@@ -27,6 +28,7 @@ def setup():
parser.add_argument("--version",action='version', version=VERSION) parser.add_argument("--version",action='version', version=VERSION)
parser.add_argument("path",type=str,action="store",default=os.path.abspath('.'),nargs='?', parser.add_argument("path",type=str,action="store",default=os.path.abspath('.'),nargs='?',
help="Root path of the index") help="Root path of the index")
options = parser.parse_args() options = parser.parse_args()
options.path = os.path.abspath(options.path) options.path = os.path.abspath(options.path)
if options.title == None: if options.title == None:
@@ -97,15 +99,28 @@ def get_filelink(path,fname,images=False):
fname_str = get_imagestr(fname) fname_str = get_imagestr(fname)
else: else:
fname_str = fname fname_str = fname
return '<tr><td><a href="'+urllib.quote(fname)+'">'+fname_str+'</a><td class="right">'+fsstr+'</td><td class="right bytes">'+fsstrb+'</td><td class="right">'+fdstr+'</td></tr>\n' return '<tr><td><a class="link_file" href="%s">%s</a><td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'%(
urllib.quote(fname),
fname_str,
fsstr,
fsstrb,
fdstr
)
def get_imagestr(fname): def get_imagestr(fname):
return '<img src="'+urllib.quote(fname)+'" title="'+fname+'"/>' return '<img src="%s" title="%s"/>'%(
urllib.quote(fname),
fname
)
def get_pathlink(path,dname): def get_pathlink(path,dname):
fdate = time.localtime(os.path.getmtime(os.path.join(path, dname))) fdate = time.localtime(os.path.getmtime(os.path.join(path, dname)))
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate) fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
return '<tr><td><a href="'+urllib.quote(dname)+'">'+dname+'</a><td class="right">[DIR]</td><td class="right bytes">0</td><td class="right">'+fdstr+'</td></tr>\n' return '<tr><td><a class="link_dir" href="%s">&#8627;&nbsp;%s/</a><td class="right">[DIR]</td><td class="right bytes">0</td><td class="right">%s</td></tr>\n'%(
urllib.quote(dname),
dname,
fdstr
)
def get_header(opts): def get_header(opts):
header='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> header='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
@@ -114,21 +129,71 @@ def get_header(opts):
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="SimpleWebPage ''' + VERSION + '''" /> <meta name="generator" content="SimpleWebPage ''' + VERSION + '''" />
''' + setup2HTML(opts) + ''' ''' + setup2HTML(opts) + '''
<title>Index of '''+opts.title+'''</title> <title>''' + opts.title + '''</title>
<style> <style>
* {
padding: 0;
margin: 0;
}
body { body {
font-family: monospace; color: #222;
font: 14px monospace;
padding: 20px;
background: #CCC;
}
h1 {
text-align: center;
padding: 20px 0 12px 0;
margin: 0;
font-family: sans-serif;
}
.container {
box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
position: relative;
background: #eee;
} }
table { table {
background-color: gray; background-color: #F3F3F3;
border-collapse: collapse;
width: 100%;
margin: 15px 0;
} }
td, th { th {
text-align: left; background-color: #EB6000;
background-color: lightgray; color: #FFF;
padding: 0.5ex; cursor: pointer;
padding: 5px 10px;
}
td {
padding-right: 5px;
}
a {
text-decoration: none;
}
td a {
color: #EB6000;
display: block;
padding: 5px 10px;
}
th a {
padding-left: 0
}
td:first-of-type a {
padding-left: 5px;
}
th:first-of-type {
padding-left: 5px;
}
tr:nth-of-type(odd) {
background-color: #DDD;
}
tr:hover td {
background-color:#BBB;
}
tr:hover td a {
color: #222;
} }
th { cursor: hand; }
th:a { text-decoration: none; }
.right { .right {
text-align: right; text-align: right;
} }
@@ -461,15 +526,15 @@ function alternate(table) {
</script> </script>
</head> </head>
<body> <body>
<h1>Index of '''+opts.title+'''</h1> <div class="container">
<h1>''' + opts.title + '''</h1>
<table class="sortable" id="fileList"><thead><tr><th>Name</th><th class="right">Size</th><th class="right">Size B</th><th class="right">Modified</th></tr></thead><tbody> <table class="sortable" id="fileList"><thead><tr><th>Name</th><th class="right">Size</th><th class="right">Size B</th><th class="right">Modified</th></tr></thead><tbody>
''' '''
return header return header
def get_footer(): def get_footer():
footer='''</tbody></table> return '''</tbody></table></div>
</body></html>''' </body></html>'''
return footer
def is_imagefile(fname): def is_imagefile(fname):
for ext in IMAGE_EXTENSIONS: for ext in IMAGE_EXTENSIONS:
@@ -485,5 +550,6 @@ def sizeof(num):
return "%3.1f&nbsp;%s" % (num, x) return "%3.1f&nbsp;%s" % (num, x)
num /= 1024.0 num /= 1024.0
if __name__ == "__main__":
opts = setup() opts = setup()
generate_index(opts) generate_index(opts)