SimpleWebPage with includes
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
import os,sys,time
|
import os,sys,time
|
||||||
import urllib
|
import urllib
|
||||||
|
from glob import fnmatch
|
||||||
|
|
||||||
VERSION = "20181206"
|
VERSION = "20181206"
|
||||||
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
|
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
|
||||||
@@ -27,9 +28,22 @@ def setup():
|
|||||||
help="Do no print .. link for parent folder.")
|
help="Do no print .. link for parent folder.")
|
||||||
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",
|
||||||
|
action="store",
|
||||||
|
dest="includes",
|
||||||
|
default=['*'],
|
||||||
|
help="Glob match for files to be included in the table. ex. *.jpg. You can pass several includes.",
|
||||||
|
nargs = '*'
|
||||||
|
)
|
||||||
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(
|
||||||
help="Root path of the index")
|
"path",
|
||||||
|
type=str,
|
||||||
|
action="store",
|
||||||
|
default=os.path.abspath('.'),
|
||||||
|
nargs='?',
|
||||||
|
help="Root path of the index"
|
||||||
|
)
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
options.path = os.path.abspath(options.path)
|
options.path = os.path.abspath(options.path)
|
||||||
@@ -75,6 +89,7 @@ def generate_index(opts):
|
|||||||
print(opts.filename + " exists, and not generated with SimpleWebPage. Exiting.")
|
print(opts.filename + " exists, and not generated with SimpleWebPage. Exiting.")
|
||||||
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)
|
||||||
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(".")]
|
||||||
@@ -550,6 +565,17 @@ def is_imagefile(fname):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def match_files(files, glob_list):
|
||||||
|
matched = []
|
||||||
|
for f in files:
|
||||||
|
for g in glob_list:
|
||||||
|
if fnmatch.fnmatch(f,g):
|
||||||
|
matched.append(f)
|
||||||
|
break
|
||||||
|
return matched
|
||||||
|
|
||||||
|
|
||||||
def sizeof(num):
|
def sizeof(num):
|
||||||
for x in [' B','KB','MB','GB','TB']:
|
for x in [' B','KB','MB','GB','TB']:
|
||||||
if num < 1024.0:
|
if num < 1024.0:
|
||||||
|
|||||||
Reference in New Issue
Block a user