refurbished css for webpage generator
This commit is contained in:
@@ -12,7 +12,7 @@ def get_options():
|
||||
action = "store_false",
|
||||
dest = "move",
|
||||
default = True,
|
||||
help = "Copy file instead of copying",
|
||||
help = "Copy file instead of moving",
|
||||
)
|
||||
parser.add_argument(
|
||||
'-d',
|
||||
@@ -112,10 +112,7 @@ if __name__ == "__main__":
|
||||
else:
|
||||
new_name = get_version_name(opts.file)
|
||||
if not opts.quiet:
|
||||
print("%s -> %s"%(
|
||||
opts.file,
|
||||
new_name
|
||||
))
|
||||
print(new_name)
|
||||
test_existing(new_name, opts.force)
|
||||
if opts.move:
|
||||
os.rename(opts.file, new_name)
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
|
||||
import os,sys,time
|
||||
import urllib
|
||||
VERSION="20160116"
|
||||
IMAGE_EXTENSIONS=['png','gif','jpg','jpeg','tif','tiff']
|
||||
|
||||
VERSION = "20181206"
|
||||
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
|
||||
|
||||
def setup():
|
||||
''' Setup the command line options '''
|
||||
@@ -27,10 +28,11 @@ def setup():
|
||||
parser.add_argument("--version",action='version', version=VERSION)
|
||||
parser.add_argument("path",type=str,action="store",default=os.path.abspath('.'),nargs='?',
|
||||
help="Root path of the index")
|
||||
options=parser.parse_args()
|
||||
options.path=os.path.abspath(options.path)
|
||||
if options.title==None:
|
||||
options.title=os.path.basename(options.path)
|
||||
|
||||
options = parser.parse_args()
|
||||
options.path = os.path.abspath(options.path)
|
||||
if options.title == None:
|
||||
options.title = os.path.basename(options.path)
|
||||
return options
|
||||
|
||||
def setup2HTML(opts):
|
||||
@@ -42,18 +44,18 @@ def setup2HTML(opts):
|
||||
])
|
||||
|
||||
def HTML2setup(opts):
|
||||
f=open(os.path.join(opts.path,opts.filename), 'rt')
|
||||
f = open(os.path.join(opts.path,opts.filename), 'rt')
|
||||
try:
|
||||
for l in f.readlines():
|
||||
if l.find('name="SimpleWebPageSetup"')>-1:
|
||||
content=l[l.find('name="SimpleWebPageSetup"'):]
|
||||
if l.find('name="SimpleWebPageSetup"') > -1:
|
||||
content = l[l.find('name="SimpleWebPageSetup"'):]
|
||||
for s in content.split('"')[3].split(";"):
|
||||
(k,v)=s.split('=',1)
|
||||
if k=='hidden': opts.hidden=v=="True"
|
||||
if k=='parent': opts.parent=v=="True"
|
||||
if k=='title': opts.title=urllib.unquote(v)
|
||||
if k=='images': opts.images=v=="True"
|
||||
print("Reading options from existing "+opts.filename)
|
||||
(k,v) = s.split('=',1)
|
||||
if k == 'hidden': opts.hidden = v == "True"
|
||||
if k == 'parent': opts.parent = v == "True"
|
||||
if k == 'title': opts.title = urllib.unquote(v)
|
||||
if k == 'images': opts.images = v == "True"
|
||||
print("Reading options from existing " + opts.filename)
|
||||
break
|
||||
except:
|
||||
pass
|
||||
@@ -65,70 +67,133 @@ def generate_index(opts):
|
||||
if not opts.overwrite:
|
||||
print(opts.filename+" exists")
|
||||
sys.exit(1)
|
||||
opts=HTML2setup(opts)
|
||||
opts = HTML2setup(opts)
|
||||
files = [ f for f in files if f != opts.filename]
|
||||
if not opts.hidden:
|
||||
files = [ f for f in files if not f.startswith(".")]
|
||||
dirs = [ d for d in dirs if not d.startswith(".")]
|
||||
f=open(os.path.join(path,opts.filename),'wt')
|
||||
f = open(os.path.join(path,opts.filename),'wt')
|
||||
dirs.sort()
|
||||
files.sort()
|
||||
f.write(get_header(opts))
|
||||
if opts.parent:
|
||||
f.write(get_pathlink(path,'..'))
|
||||
f.write(get_pathlink(path, '..'))
|
||||
for di in dirs:
|
||||
f.write(get_pathlink(path,di))
|
||||
f.write(get_pathlink(path, di))
|
||||
for fi in files:
|
||||
f.write(get_filelink(path,fi,opts.images))
|
||||
f.write(get_filelink(path, fi, opts.images))
|
||||
f.write(get_footer())
|
||||
f.close()
|
||||
return
|
||||
|
||||
def get_filelink(path,fname,images=False):
|
||||
if os.path.islink(os.path.join(path,fname)) and not os.path.exists(os.path.join(path,fname)):
|
||||
(fsize,fsstr,fsstrb,fdstr)=(0,"NA","NA","NA")
|
||||
if os.path.islink(os.path.join(path, fname)) and not os.path.exists(os.path.join(path, fname)):
|
||||
(fsize, fsstr, fsstrb, fdstr)=(0, "NA", "NA", "NA")
|
||||
else:
|
||||
fsize=os.path.getsize(os.path.join(path,fname))
|
||||
fsstr=sizeof(fsize)
|
||||
fsstrb=str(fsize)
|
||||
fdate=time.localtime(os.path.getmtime(os.path.join(path,fname)))
|
||||
fdstr=time.strftime("%Y/%m/%d %H:%M:%S",fdate)
|
||||
fsize = os.path.getsize(os.path.join(path, fname))
|
||||
fsstr = sizeof(fsize)
|
||||
fsstrb = str(fsize)
|
||||
fdate = time.localtime(os.path.getmtime(os.path.join(path, fname)))
|
||||
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
||||
if images and is_imagefile(fname):
|
||||
fname_str=get_imagestr(fname)
|
||||
fname_str = get_imagestr(fname)
|
||||
else:
|
||||
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'
|
||||
fname_str = fname
|
||||
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):
|
||||
return '<img src="'+urllib.quote(fname)+'" title="'+fname+'"/>'
|
||||
return '<img src="%s" title="%s"/>'%(
|
||||
urllib.quote(fname),
|
||||
fname
|
||||
)
|
||||
|
||||
def get_pathlink(path,dname):
|
||||
fdate=time.localtime(os.path.getmtime(os.path.join(path,dname)))
|
||||
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'
|
||||
fdate = time.localtime(os.path.getmtime(os.path.join(path, dname)))
|
||||
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
||||
return '<tr><td><a class="link_dir" href="%s">↳ %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):
|
||||
header='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="generator" content="SimpleWebPage '''+VERSION+'''" />
|
||||
'''+setup2HTML(opts)+'''
|
||||
<title>Index of '''+opts.title+'''</title>
|
||||
<meta name="generator" content="SimpleWebPage ''' + VERSION + '''" />
|
||||
''' + setup2HTML(opts) + '''
|
||||
<title>''' + opts.title + '''</title>
|
||||
<style>
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
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 {
|
||||
background-color: gray;
|
||||
background-color: #F3F3F3;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin: 15px 0;
|
||||
}
|
||||
td, th {
|
||||
text-align: left;
|
||||
background-color: lightgray;
|
||||
padding: 0.5ex;
|
||||
th {
|
||||
background-color: #EB6000;
|
||||
color: #FFF;
|
||||
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 {
|
||||
text-align: right;
|
||||
}
|
||||
@@ -461,15 +526,15 @@ function alternate(table) {
|
||||
</script>
|
||||
</head>
|
||||
<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>
|
||||
'''
|
||||
return header
|
||||
|
||||
def get_footer():
|
||||
footer='''</tbody></table>
|
||||
return '''</tbody></table></div>
|
||||
</body></html>'''
|
||||
return footer
|
||||
|
||||
def is_imagefile(fname):
|
||||
for ext in IMAGE_EXTENSIONS:
|
||||
@@ -485,5 +550,6 @@ def sizeof(num):
|
||||
return "%3.1f %s" % (num, x)
|
||||
num /= 1024.0
|
||||
|
||||
opts=setup()
|
||||
generate_index(opts)
|
||||
if __name__ == "__main__":
|
||||
opts = setup()
|
||||
generate_index(opts)
|
||||
|
||||
Reference in New Issue
Block a user