Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8d7144ab29
Fetching contributors…

Cannot retrieve contributors at this time

executable file 75 lines (56 sloc) 2.179 kb
#!/usr/bin/env python
#
"""
giframe: Display file (or HTML from stdin) in inline iframe
"""
import mimetypes
import os
import random
import sys
import time
from optparse import OptionParser
import gtermapi
usage = "usage: %prog [file|URL]"
parser = OptionParser(usage=usage)
parser.add_option("", "--opacity", dest="opacity", default=1.0,
help="Feed opacity (default: 1.0)")
parser.add_option("-f", "--fullscreen",
action="store_true", dest="fullscreen", default=False,
help="Fullscreen display")
parser.add_option("-n", "--nofooter", action="store_true", dest="nofooter", default=False,
help="Suppress footer")
(options, args) = parser.parse_args()
if args:
if args[0].startswith("http:") or args[0].startswith("https:"):
iframe_url = args[0]
else:
if gtermapi.Export_host:
iframe_url = gtermapi.create_blob(from_file=args[0])
else:
iframe_url = gtermapi.get_file_url(args[0], relative=True, exists=True)
if not iframe_url:
print >> sys.stderr, "File %s not found" % args[0]
sys.exit(1)
else:
try:
content = sys.stdin.read()
except (EOFError, KeyboardInterrupt):
content = None
if not content:
print >> sys.stderr, "Error in reading from stdin"
sys.exit(1)
iframe_url = gtermapi.create_blob(content, content_type="text/html")
headers = {"opacity": options.opacity}
if not options.fullscreen:
headers["autosize"] = True
frameId = "giframe%09d" % random.randrange(0, 10**9)
frameHeight = 'height="%d%%%%"' % (100 if options.nofooter else 95,) if options.fullscreen else ''
IFRAMEFORMAT = '<iframe id="'+frameId+'" class="gterm-iframe" src="%s" width="100%%" '+frameHeight+'"></iframe>'
if not options.nofooter:
IFRAMEFORMAT = '<span class="gterm-iframeclose gterm-iframeheader">&#215;</span>' + IFRAMEFORMAT
gtermapi.write_html(IFRAMEFORMAT % iframe_url, display=("fullscreen" if options.fullscreen else "block"), add_headers=headers)
try:
while options.fullscreen:
time.sleep(1)
except KeyboardInterrupt:
gtermapi.write_blank()
Jump to Line
Something went wrong with that request. Please try again.