SimpleWbPage with recursive file listing
This commit is contained in:
@@ -7,7 +7,7 @@ import os,sys,time
|
|||||||
import urllib
|
import urllib
|
||||||
from glob import fnmatch
|
from glob import fnmatch
|
||||||
|
|
||||||
VERSION = "20181206"
|
VERSION = "20200427"
|
||||||
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
|
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
@@ -26,6 +26,8 @@ def setup():
|
|||||||
help="Output filename (Default: index.html)")
|
help="Output filename (Default: index.html)")
|
||||||
parser.add_argument("-p",action="store_false",dest="parent",default=True,
|
parser.add_argument("-p",action="store_false",dest="parent",default=True,
|
||||||
help="Do no print .. link for parent folder.")
|
help="Do no print .. link for parent folder.")
|
||||||
|
parser.add_argument("-r",action="store_true",dest="recursive",default=False,
|
||||||
|
help="Include all files recursively in the list. Do not include any folders.")
|
||||||
parser.add_argument("--images",action="store_true",dest="images",default=False,
|
parser.add_argument("--images",action="store_true",dest="images",default=False,
|
||||||
help="Show images with <img> tags")
|
help="Show images with <img> tags")
|
||||||
parser.add_argument("--include","-i",
|
parser.add_argument("--include","-i",
|
||||||
@@ -80,8 +82,34 @@ def HTML2setup(opts):
|
|||||||
except:
|
except:
|
||||||
return (opts, False)
|
return (opts, False)
|
||||||
|
|
||||||
|
def get_files_and_folders(opts):
|
||||||
|
|
||||||
|
if opts.recursive:
|
||||||
|
rdirs = []
|
||||||
|
rfiles = []
|
||||||
|
rpath = None
|
||||||
|
for path, dirs, files in os.walk(opts.path):
|
||||||
|
if rpath == None:
|
||||||
|
rpath = path
|
||||||
|
if not opts.hidden:
|
||||||
|
files = [ f for f in files if not f.startswith(".")]
|
||||||
|
dirs[:] = [ d for d in dirs if not d.startswith(".")]
|
||||||
|
files = [os.path.join(os.path.relpath(path, opts.path), f) for f in files]
|
||||||
|
files = [f[2:] if f.startswith("./") else f for f in files ]
|
||||||
|
rfiles.extend(files)
|
||||||
|
|
||||||
|
return rdirs, rfiles, rpath
|
||||||
|
|
||||||
|
else:
|
||||||
|
for path, dirs, files in os.walk(opts.path):
|
||||||
|
if not opts.hidden:
|
||||||
|
files = [ f for f in files if not f.startswith(".")]
|
||||||
|
dirs = [ d for d in dirs if not d.startswith(".")]
|
||||||
|
return dirs, files, path
|
||||||
|
|
||||||
|
|
||||||
def generate_index(opts):
|
def generate_index(opts):
|
||||||
for path,dirs, files in os.walk(opts.path):
|
dirs, files, path = get_files_and_folders(opts)
|
||||||
existing_config = False
|
existing_config = False
|
||||||
if opts.filename in files:
|
if opts.filename in files:
|
||||||
opts, existing_config = HTML2setup(opts)
|
opts, existing_config = HTML2setup(opts)
|
||||||
@@ -90,11 +118,9 @@ def generate_index(opts):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
files = [ f for f in files if f != opts.filename]
|
files = [ f for f in files if f != opts.filename]
|
||||||
files = match_files(files, opts.includes)
|
files = match_files(files, opts.includes)
|
||||||
if not opts.hidden:
|
|
||||||
files = [ f for f in files if not f.startswith(".")]
|
|
||||||
dirs = [ d for d in dirs if not d.startswith(".")]
|
|
||||||
dirs.sort()
|
dirs.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
|
files.sort(key = lambda x: x.find("/") > 0)
|
||||||
with open(os.path.join(path,opts.filename), 'wt') as f:
|
with open(os.path.join(path,opts.filename), 'wt') as f:
|
||||||
f.write(get_header(opts))
|
f.write(get_header(opts))
|
||||||
if opts.parent:
|
if opts.parent:
|
||||||
@@ -107,6 +133,7 @@ def generate_index(opts):
|
|||||||
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user