Merge branch 'master' of ssh://bitbucket.org/MoonQ/q-tools
This commit is contained in:
@@ -7,7 +7,7 @@ import os,sys,time
|
||||
import urllib
|
||||
from glob import fnmatch
|
||||
|
||||
VERSION = "20181206"
|
||||
VERSION = "20200427"
|
||||
IMAGE_EXTENSIONS = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff']
|
||||
|
||||
def setup():
|
||||
@@ -26,6 +26,8 @@ def setup():
|
||||
help="Output filename (Default: index.html)")
|
||||
parser.add_argument("-p",action="store_false",dest="parent",default=True,
|
||||
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,
|
||||
help="Show images with <img> tags")
|
||||
parser.add_argument("--include","-i",
|
||||
@@ -80,8 +82,34 @@ def HTML2setup(opts):
|
||||
except:
|
||||
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):
|
||||
for path,dirs, files in os.walk(opts.path):
|
||||
dirs, files, path = get_files_and_folders(opts)
|
||||
existing_config = False
|
||||
if opts.filename in files:
|
||||
opts, existing_config = HTML2setup(opts)
|
||||
@@ -90,11 +118,9 @@ def generate_index(opts):
|
||||
sys.exit(1)
|
||||
files = [ f for f in files if f != opts.filename]
|
||||
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()
|
||||
files.sort()
|
||||
files.sort(key = lambda x: x.find("/") > 0)
|
||||
with open(os.path.join(path,opts.filename), 'wt') as f:
|
||||
f.write(get_header(opts))
|
||||
if opts.parent:
|
||||
@@ -104,9 +130,11 @@ def generate_index(opts):
|
||||
for fi in files:
|
||||
f.write(get_filelink(path, fi, opts.images))
|
||||
f.write(get_footer())
|
||||
f.write(get_wget_lines(files))
|
||||
f.close()
|
||||
return
|
||||
|
||||
|
||||
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)):
|
||||
(fsize, fsstr, fsstrb, fdstr)=(0, "NA", "NA", "NA")
|
||||
@@ -128,6 +156,16 @@ def get_filelink(path,fname,images=False):
|
||||
fdstr
|
||||
)
|
||||
|
||||
|
||||
def get_wget_lines(files):
|
||||
wget = "\n<!--\n"
|
||||
for f in files:
|
||||
wget += "#FILE %s\n"%(urllib.quote(f),)
|
||||
wget += "#WGET URL=[insert URL] && curl $URL | grep '^#FILE ' | cut -c7- | sed \"s,^,$URL,\" | xargs -n1 wget\n"
|
||||
wget += "-->\n"
|
||||
return wget
|
||||
|
||||
|
||||
def get_imagestr(fname):
|
||||
return '<img src="%s" title="%s"/>'%(
|
||||
urllib.quote(fname),
|
||||
|
||||
Reference in New Issue
Block a user