XSLTools

Annotated tools/demo.py

688:277aa428aaa9
2009-06-22 Paul Boddie Removed Qt-related resources. Added a script and stylesheet for extracting translation keys from templates.
paulb@114 1
#!/usr/bin/env python
paulb@114 2
paulb@114 3
"Start the demonstration program."
paulb@114 4
paulb@114 5
import os, sys
paulb@114 6
paulb@239 7
# Find out where the XSLTools distribution directory is.
paulb@114 8
paulb@239 9
program = sys.argv[0]
paulb@239 10
cwd = os.path.split(program)[0]
paulb@114 11
parts = os.path.split(cwd)
paulb@114 12
if parts[-1] == "tools":
paulb@114 13
    parts = parts[:-1]
paulb@114 14
base = os.path.join(*parts)
paulb@114 15
paulb@239 16
# Set up the environment and obtain the demo resource.
paulb@239 17
paulb@239 18
sys.path.append(base)
paulb@239 19
sys.path.append(os.path.join(base, "examples", "Common"))
paulb@239 20
paulb@589 21
host = "http://localhost:8080" # or another absolute URL
paulb@589 22
paulb@239 23
import DemoApp
paulb@589 24
resource = DemoApp.get_site(host)
paulb@239 25
paulb@239 26
# Try and open the application in a Web browser.
paulb@239 27
# The preferred module is Paul's proposed desktop module - see #1301512 in
paulb@239 28
# the Python SourceForge project: http://www.python.org/sf?id=1301512
paulb@114 29
paulb@239 30
if "--nobrowser" not in sys.argv:
paulb@239 31
    print "Opening a browser to show the application."
paulb@239 32
    print "If this fails, specify --nobrowser to turn it off."
paulb@239 33
    try:
paulb@239 34
        import desktop
paulb@239 35
    except ImportError:
paulb@239 36
        import webbrowser as desktop
paulb@114 37
paulb@589 38
    desktop.open(host)
paulb@239 39
paulb@239 40
# Special magic incantation to start the demo.
paulb@239 41
paulb@239 42
from WebStack.Adapters.BaseHTTPRequestHandler import deploy
paulb@239 43
paulb@239 44
print "Serving..."
paulb@239 45
deploy(resource, handle_errors=0)
paulb@114 46
paulb@114 47
# vim: tabstop=4 expandtab shiftwidth=4