refurbished css for webpage generator
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
import os,sys,time
|
import os,sys,time
|
||||||
import urllib
|
import urllib
|
||||||
VERSION="20160116"
|
|
||||||
IMAGE_EXTENSIONS=['png','gif','jpg','jpeg','tif','tiff']
|
VERSION = "20181206"
|
||||||
|
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
''' Setup the command line options '''
|
''' Setup the command line options '''
|
||||||
@@ -27,10 +28,11 @@ 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.path=os.path.abspath(options.path)
|
options = parser.parse_args()
|
||||||
if options.title==None:
|
options.path = os.path.abspath(options.path)
|
||||||
options.title=os.path.basename(options.path)
|
if options.title == None:
|
||||||
|
options.title = os.path.basename(options.path)
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def setup2HTML(opts):
|
def setup2HTML(opts):
|
||||||
@@ -42,18 +44,18 @@ def setup2HTML(opts):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def HTML2setup(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:
|
try:
|
||||||
for l in f.readlines():
|
for l in f.readlines():
|
||||||
if l.find('name="SimpleWebPageSetup"')>-1:
|
if l.find('name="SimpleWebPageSetup"') > -1:
|
||||||
content=l[l.find('name="SimpleWebPageSetup"'):]
|
content = l[l.find('name="SimpleWebPageSetup"'):]
|
||||||
for s in content.split('"')[3].split(";"):
|
for s in content.split('"')[3].split(";"):
|
||||||
(k,v)=s.split('=',1)
|
(k,v) = s.split('=',1)
|
||||||
if k=='hidden': opts.hidden=v=="True"
|
if k == 'hidden': opts.hidden = v == "True"
|
||||||
if k=='parent': opts.parent=v=="True"
|
if k == 'parent': opts.parent = v == "True"
|
||||||
if k=='title': opts.title=urllib.unquote(v)
|
if k == 'title': opts.title = urllib.unquote(v)
|
||||||
if k=='images': opts.images=v=="True"
|
if k == 'images': opts.images = v == "True"
|
||||||
print("Reading options from existing "+opts.filename)
|
print("Reading options from existing " + opts.filename)
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -65,70 +67,133 @@ def generate_index(opts):
|
|||||||
if not opts.overwrite:
|
if not opts.overwrite:
|
||||||
print(opts.filename+" exists")
|
print(opts.filename+" exists")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
opts=HTML2setup(opts)
|
opts = HTML2setup(opts)
|
||||||
files = [ f for f in files if f != opts.filename]
|
files = [ f for f in files if f != opts.filename]
|
||||||
if not opts.hidden:
|
if not opts.hidden:
|
||||||
files = [ f for f in files if not f.startswith(".")]
|
files = [ f for f in files if not f.startswith(".")]
|
||||||
dirs = [ d for d in dirs if not d.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()
|
dirs.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
f.write(get_header(opts))
|
f.write(get_header(opts))
|
||||||
if opts.parent:
|
if opts.parent:
|
||||||
f.write(get_pathlink(path,'..'))
|
f.write(get_pathlink(path, '..'))
|
||||||
for di in dirs:
|
for di in dirs:
|
||||||
f.write(get_pathlink(path,di))
|
f.write(get_pathlink(path, di))
|
||||||
for fi in files:
|
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.write(get_footer())
|
||||||
f.close()
|
f.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_filelink(path,fname,images=False):
|
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)):
|
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")
|
(fsize, fsstr, fsstrb, fdstr)=(0, "NA", "NA", "NA")
|
||||||
else:
|
else:
|
||||||
fsize=os.path.getsize(os.path.join(path,fname))
|
fsize = os.path.getsize(os.path.join(path, fname))
|
||||||
fsstr=sizeof(fsize)
|
fsstr = sizeof(fsize)
|
||||||
fsstrb=str(fsize)
|
fsstrb = str(fsize)
|
||||||
fdate=time.localtime(os.path.getmtime(os.path.join(path,fname)))
|
fdate = time.localtime(os.path.getmtime(os.path.join(path, fname)))
|
||||||
fdstr=time.strftime("%Y/%m/%d %H:%M:%S",fdate)
|
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
||||||
if images and is_imagefile(fname):
|
if images and is_imagefile(fname):
|
||||||
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">↳ %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">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<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 %s" % (num, x)
|
return "%3.1f %s" % (num, x)
|
||||||
num /= 1024.0
|
num /= 1024.0
|
||||||
|
|
||||||
opts=setup()
|
if __name__ == "__main__":
|
||||||
generate_index(opts)
|
opts = setup()
|
||||||
|
generate_index(opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user