diff --git a/webgen.py b/webgen.py
index 39baad3..76f09eb 100755
--- a/webgen.py
+++ b/webgen.py
@@ -13,7 +13,6 @@ sourcedir = os.path.expanduser("~/python/webgen/")
filesdir = webbasedir + "files/"
indexfilename = "index.html"
filesdirheadline = "Files"
-dirindexfile = open(filesdir + indexfilename, "w")
####
fileending = ""
@@ -111,6 +110,49 @@ def selectfile():
return sourcefile, targetfile, headline
+def mkdirindex(filesdir, indexfilename, filesdirheadline):
+ """Dig the files-directory and generate an index."""
+
+ head1 = (
+ '
\n \n'
+ + filesdirheadline
+ + '\n \n \n '
+ )
+
+ style_fn = ''
+ head2 = ""
+ body1 = 'Back
'
+ body1 += ' Some files. Maybe useful or not.
'
+ body1 += '
You can't avoid chaos.
\n"
+ linecounter=0
+
+ dirindexfile = open(filesdir + indexfilename, "w")
+
+ dirindexfile.write(head1 + style_fn + head2 + body1)
+
+ for file in os.listdir(filesdir):
+ if not re.match("^\.", file) and not file == indexfilename:
+ size = os.lstat(filesdir + 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('' + str(file) + " | " + sizestr + " |
")
+ dirindexfile.write(line)
+ linecounter+=1
+
+ dirindexfile.write(foot)
+ return linecounter
+
+
# Parse arguments "--html", "--stdout" and "Some Headline"
# there are 3 parameters. if --html is given, the fileending will be .html.
@@ -206,42 +248,8 @@ html_out_file.close()
if outfile != sys.stdout:
print(outputfile)
-
# Dig the files-directory and generate an index.
-
-head1 = (
- '\n \n'
- + filesdirheadline
- + '\n \n \n '
-)
-
-style_fn = ''
-head2 = ""
-body1 = 'Back
'
-body1 += ' Some files. Maybe useful or not.
'
-body1 += '
You can't avoid chaos.
\n"
-
-
-dirindexfile.write(head1 + style_fn + head2 + body1)
-
-for file in os.listdir(filesdir):
- if not re.match("^\.", file) and not file == indexfilename:
- size = os.lstat(filesdir + 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('' + str(file) + " | " + sizestr + " |
")
- dirindexfile.write(line)
-
-dirindexfile.write(foot)
+linecounter=mkdirindex(filesdir, indexfilename, filesdirheadline)
+print("LC=",linecounter)
# Have a nice time.