webgen v4.0.1 + mkdirindex on files alpha
This commit is contained in:
parent
e4292b13b1
commit
e56419c409
1 changed files with 44 additions and 0 deletions
44
webgen.py
44
webgen.py
|
@ -21,6 +21,13 @@ xwidth = os.get_terminal_size()[0] - 3
|
||||||
ywidth = os.get_terminal_size()[1] - 3
|
ywidth = os.get_terminal_size()[1] - 3
|
||||||
os.chdir(sourcedir)
|
os.chdir(sourcedir)
|
||||||
|
|
||||||
|
### for module mkdirindex:
|
||||||
|
filedir = "/home/wn/www/i21k.de/files/"
|
||||||
|
indexfilename = "index.html"
|
||||||
|
filedirheadline = "Files"
|
||||||
|
dirindexfile = open(filedir + indexfilename, "w")
|
||||||
|
####
|
||||||
|
|
||||||
# Prepend an hourly tinestamp to the later name of the file
|
# Prepend an hourly tinestamp to the later name of the file
|
||||||
creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:00 ")
|
creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:00 ")
|
||||||
# generate a more precise ctime to be included in the resulting webpage
|
# generate a more precise ctime to be included in the resulting webpage
|
||||||
|
@ -199,4 +206,41 @@ html_out_file.close()
|
||||||
if outfile != sys.stdout:
|
if outfile != sys.stdout:
|
||||||
print(outputfile)
|
print(outputfile)
|
||||||
|
|
||||||
|
|
||||||
|
# Dig the files-directory and generate an index.
|
||||||
|
|
||||||
|
head1 = (
|
||||||
|
'<!DOCTYPE HTML><html><head>\n <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n<title>'
|
||||||
|
+ filedirheadline
|
||||||
|
+ '</title>\n <meta name="syntax" content="markdown">\n <meta name="generator" content="'
|
||||||
|
+ "webgen.py"
|
||||||
|
+ ' markdown2htmlconverter">\n <meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">'
|
||||||
|
)
|
||||||
|
|
||||||
|
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
|
||||||
|
head2 = "</head><body>"
|
||||||
|
body1 = '<a class="Statement" href="../">Back</a><br/><br/><hr>'
|
||||||
|
body1 += '<div class="Statement"> Some files. Maybe useful or not.</div> '
|
||||||
|
body1 += '<table border="0" class="Neutral">'
|
||||||
|
foot = "</table><br/><strong>You can't avoid chaos.</strong><br/><hr></body> </html>\n"
|
||||||
|
|
||||||
|
|
||||||
|
dirindexfile.write(head1 + style_fn + head2 + body1)
|
||||||
|
|
||||||
|
for file in os.listdir(filedir):
|
||||||
|
if not re.match("^\.", file) and not file == indexfilename:
|
||||||
|
size = os.lstat(filedir + file).st_size
|
||||||
|
if size > 100000000000:
|
||||||
|
sizestr = str(int(size / 1073741824)) + " GiB"
|
||||||
|
elif size > 100000000:
|
||||||
|
sizestr = str(int(size / 1048576)) + " MiB"
|
||||||
|
elif size > 10000:
|
||||||
|
sizestr = str(int(size / 1024)) + " KiB"
|
||||||
|
else:
|
||||||
|
sizestr = str(size) + " B"
|
||||||
|
|
||||||
|
line = str('<tr><td><a href="' + str(file) + '">' + str(file) + "</a></td><td> " + sizestr + "</td></tr>")
|
||||||
|
dirindexfile.write(line)
|
||||||
|
|
||||||
|
dirindexfile.write(foot)
|
||||||
# Have a nice time.
|
# Have a nice time.
|
||||||
|
|
Loading…
Reference in a new issue