added date and color to SimpleWebPage
This commit is contained in:
@@ -469,15 +469,31 @@ def add_highlight(s,opts):
|
|||||||
return colorify(tagged,opts)
|
return colorify(tagged,opts)
|
||||||
|
|
||||||
def launch(reader,opts,offset):
|
def launch(reader,opts,offset):
|
||||||
""" Launch in a string using tags $!command$!
|
""" Launch in a string using tags $!command$! or $>command$>
|
||||||
Used with highlight
|
Remove empty lines from beginning and end of stdout in $> commands.
|
||||||
Remove empty lines from beginning and end of stdout.
|
Detects URLS and markdown images 
|
||||||
"""
|
"""
|
||||||
if not opts.execute:
|
if not opts.execute:
|
||||||
return
|
return
|
||||||
s=reader.get_current_page()[offset[1]]
|
s=reader.get_current_page()[offset[1]]
|
||||||
if s.find("$!")+s.find("$>")==-2:
|
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', s)
|
||||||
return
|
images = re.findall('!\[[^]]+\]\([^\)]+\)', s)
|
||||||
|
if s.find("$!")==-1 and s.find("$>")==-1 and len(urls)==0 and len(images)==0:
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(urls)>0:
|
||||||
|
# Remove ) at the end of url: [name](link) markdown syntax
|
||||||
|
subprocess.call("xdg-open '%s' &"%(urls[0].rstrip(")"),),
|
||||||
|
stdout=subprocess.PIPE,stderr=subprocess.PIPE,
|
||||||
|
shell=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(images)>0:
|
||||||
|
image = re.sub('.*\(([^\)]+)\).*', "\\1",images[0])
|
||||||
|
subprocess.call("xdg-open '%s' &"%(image,),
|
||||||
|
stdout=subprocess.PIPE,stderr=subprocess.PIPE,
|
||||||
|
shell=True)
|
||||||
|
return
|
||||||
|
|
||||||
run_command=re.match("(.*)\$!(.*)\$!(.*)",s)
|
run_command=re.match("(.*)\$!(.*)\$!(.*)",s)
|
||||||
show_command=re.match("(.*)\$>(.*)\$>(.*)",s)
|
show_command=re.match("(.*)\$>(.*)\$>(.*)",s)
|
||||||
@@ -496,8 +512,6 @@ def launch(reader,opts,offset):
|
|||||||
return
|
return
|
||||||
if run_command != None:
|
if run_command != None:
|
||||||
subprocess.call(run_command.group(2),
|
subprocess.call(run_command.group(2),
|
||||||
#~ stdout=subprocess.PIPE,
|
|
||||||
#~ stderr=subprocess.PIPE,
|
|
||||||
shell=True,executable="/bin/bash")
|
shell=True,executable="/bin/bash")
|
||||||
inkey=getch.get()
|
inkey=getch.get()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
''' A script that creates index.html indexes for a folder.
|
''' A script that creates index.html indexes for a folder.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os,sys
|
import os,sys,time
|
||||||
import urllib
|
import urllib
|
||||||
INDEXFILE='index.html'
|
INDEXFILE='index.html'
|
||||||
|
|
||||||
@@ -54,21 +54,40 @@ def generate_index(opts):
|
|||||||
def get_filelink(path,fname):
|
def get_filelink(path,fname):
|
||||||
fsize=os.path.getsize(os.path.join(path,fname))
|
fsize=os.path.getsize(os.path.join(path,fname))
|
||||||
fsstr=sizeof(fsize)
|
fsstr=sizeof(fsize)
|
||||||
return '<tr><td><a href="'+urllib.quote(fname)+'">'+fname+'</a><td>'+fsstr+'</td></tr>\n'
|
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">'+fdstr+'</td></tr>\n'
|
||||||
|
|
||||||
def get_pathlink(path):
|
def get_pathlink(path):
|
||||||
return '<tr><td><a href="'+urllib.quote(path)+'">'+path+'</a><td></td></tr>\n'
|
fdate=time.localtime(os.path.getmtime(path))
|
||||||
|
fdstr=time.strftime("%Y/%m/%d %H:%M:%S",fdate)
|
||||||
|
return '<tr><td><a href="'+urllib.quote(path)+'">'+path+'</a><td class="right">[DIR]</td><td class="right">'+fdstr+'</td></tr>\n'
|
||||||
|
|
||||||
def get_header(title):
|
def get_header(title):
|
||||||
header='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
header='''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Index of '''+title+'''</title>
|
<title>Index of '''+title+'''</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
background-color: gray;
|
||||||
|
}
|
||||||
|
td, th {
|
||||||
|
text-align: left;
|
||||||
|
background-color: lightgray;
|
||||||
|
padding: 0.5ex;
|
||||||
|
}
|
||||||
|
.right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Index of '''+title+'''</h1>
|
<h1>Index of '''+title+'''</h1>
|
||||||
<table><tr><th>Name</th><th>Size</th></tr>
|
<table><tr><th>Name</th><th class="right">Size</th><th class="right">Modified</th></tr>
|
||||||
'''
|
'''
|
||||||
return header
|
return header
|
||||||
|
|
||||||
@@ -78,11 +97,11 @@ def get_footer():
|
|||||||
return footer
|
return footer
|
||||||
|
|
||||||
def sizeof(num):
|
def sizeof(num):
|
||||||
for x in ['bytes','KB','MB','GB','TB']:
|
for x in [' B','KB','MB','GB','TB']:
|
||||||
if num < 1024.0:
|
if num < 1024.0:
|
||||||
if x=='bytes':
|
if x==' B':
|
||||||
return "%d %s" % (num, x)
|
return "%d %s" % (num, x)
|
||||||
return "%3.1f %s" % (num, x)
|
return "%3.1f %s" % (num, x)
|
||||||
num /= 1024.0
|
num /= 1024.0
|
||||||
|
|
||||||
opts=setup()
|
opts=setup()
|
||||||
|
|||||||
Reference in New Issue
Block a user