tsvkit installer, SimpleWebPage with image support
This commit is contained in:
11
rc
11
rc
@@ -10,18 +10,27 @@ PATH=$( echo $PATH | awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) printf("%s:
|
||||
export PATH
|
||||
|
||||
. "$TOOLSPATH"/qcd_function
|
||||
[[ -f "$TOOLSPATH"/tsv/tsvkit.sh ]] && . "$TOOLSPATH"/tsv/tsvkit.sh
|
||||
|
||||
function _self_update() {
|
||||
touch "$TOOLSPATH"/.lastupdate
|
||||
pushd "$TOOLSPATH" > /dev/null
|
||||
[[ "$1" = "-u" ]] && {
|
||||
hg pull -u https://bitbucket.org/MoonQ/tools
|
||||
_update_tsvkit
|
||||
} || {
|
||||
timeout 5 hg pull -u hg pull https://bitbucket.org/MoonQ/tools > /dev/null 2>&1
|
||||
}
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function _update_tsvkit() {
|
||||
mkdir -p "$TOOLSPATH"/tsv/lib
|
||||
wget -qO "$TOOLSPATH"/tsv/tsvkit.sh https://bitbucket.org/anduril-dev/anduril/raw/anduril2/lang/bash/tsvkit.sh
|
||||
wget -qO "$TOOLSPATH"/tsv/lib/tsvhead https://bitbucket.org/anduril-dev/anduril/raw/anduril2/lang/bash/lib/tsvhead
|
||||
wget -qO "$TOOLSPATH"/tsv/lib/tsvtail https://bitbucket.org/anduril-dev/anduril/raw/anduril2/lang/bash/lib/tsvtail
|
||||
}
|
||||
|
||||
function _change_hg_repo() {
|
||||
[[ -w "$TOOLSPATH"/.hg ]] || return
|
||||
[[ -w "$TOOLSPATH"/.hg/hgrc ]] || return
|
||||
@@ -58,6 +67,6 @@ unset -f _change_hg_repo
|
||||
TOOLS_LASTUPDATE=$(( $( date +%s ) - $( stat -c %Y "$TOOLSPATH"/.lastupdate ) ))
|
||||
[[ "$TOOLS_LASTUPDATE" -gt 604800 ]] && _self_update
|
||||
unset TOOLS_LASTUPDATE
|
||||
unset -f _self_update
|
||||
unset -f _self_update _update_tsvkit
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import os,sys,time
|
||||
import urllib
|
||||
VERSION="20160116"
|
||||
IMAGE_EXTENSIONS=['png','gif','jpg','jpeg','tif','tiff']
|
||||
|
||||
def setup():
|
||||
''' Setup the command line options '''
|
||||
@@ -21,6 +22,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("--images",action="store_true",dest="images",default=False,
|
||||
help="Show images with <img> tags")
|
||||
parser.add_argument("--version",action='version', version=VERSION)
|
||||
parser.add_argument("path",type=str,action="store",default=os.path.abspath('.'),nargs='?',
|
||||
help="Root path of the index")
|
||||
@@ -34,7 +37,8 @@ def setup2HTML(opts):
|
||||
return '<meta name="SimpleWebPageSetup" content="%s"/>'%";".join([
|
||||
'hidden=%s'%opts.hidden,
|
||||
'parent=%s'%opts.parent,
|
||||
'title=%s'%urllib.quote(opts.title)
|
||||
'title=%s'%urllib.quote(opts.title),
|
||||
'images=%s'%opts.images
|
||||
])
|
||||
|
||||
def HTML2setup(opts):
|
||||
@@ -48,6 +52,7 @@ def HTML2setup(opts):
|
||||
if k=='hidden': opts.hidden=v=="True"
|
||||
if k=='parent': opts.parent=v=="True"
|
||||
if k=='title': opts.title=urllib.unquote(v)
|
||||
if k=='images': opts.images=v=="True"
|
||||
print("Reading options from existing "+opts.filename)
|
||||
break
|
||||
except:
|
||||
@@ -74,18 +79,25 @@ def generate_index(opts):
|
||||
for di in dirs:
|
||||
f.write(get_pathlink(path,di))
|
||||
for fi in files:
|
||||
f.write(get_filelink(path,fi))
|
||||
f.write(get_filelink(path,fi,opts.images))
|
||||
f.write(get_footer())
|
||||
f.close()
|
||||
return
|
||||
|
||||
def get_filelink(path,fname):
|
||||
def get_filelink(path,fname,images=False):
|
||||
fsize=os.path.getsize(os.path.join(path,fname))
|
||||
fsstr=sizeof(fsize)
|
||||
fsstrb=str(fsize)
|
||||
fdate=time.localtime(os.path.getmtime(os.path.join(path,fname)))
|
||||
fdstr=time.strftime("%Y/%m/%d %H:%M:%S",fdate)
|
||||
return '<tr><td><a href="'+urllib.quote(fname)+'">'+fname+'</a><td class="right">'+fsstr+'</td><td class="right bytes">'+fsstrb+'</td><td class="right">'+fdstr+'</td></tr>\n'
|
||||
if images and is_imagefile(fname):
|
||||
fname_str=get_imagestr(fname)
|
||||
else:
|
||||
fname_str=fname
|
||||
return '<tr><td><a href="'+urllib.quote(fname)+'">'+fname_str+'</a><td class="right">'+fsstr+'</td><td class="right bytes">'+fsstrb+'</td><td class="right">'+fdstr+'</td></tr>\n'
|
||||
|
||||
def get_imagestr(fname):
|
||||
return '<img src="'+urllib.quote(fname)+'" title="'+fname+'"/>'
|
||||
|
||||
def get_pathlink(path,dname):
|
||||
fdate=time.localtime(os.path.getmtime(os.path.join(path,dname)))
|
||||
@@ -456,6 +468,12 @@ def get_footer():
|
||||
</body></html>'''
|
||||
return footer
|
||||
|
||||
def is_imagefile(fname):
|
||||
for ext in IMAGE_EXTENSIONS:
|
||||
if fname.lower().endswith(ext):
|
||||
return True
|
||||
return False
|
||||
|
||||
def sizeof(num):
|
||||
for x in [' B','KB','MB','GB','TB']:
|
||||
if num < 1024.0:
|
||||
|
||||
Reference in New Issue
Block a user