# HG changeset patch # User paulb # Date 1128184038 0 # Node ID ec1517bd5667299b017324f6027fd7a8c7c4d564 # Parent 490c349903620a2c8a81ccf00dfe8f2ae1bdae46 [project @ 2005-10-01 16:27:18 by paulb] Moved the demonstration and made it generic. Adopted the new-style WebStack demonstration launcher. diff -r 490c34990362 -r ec1517bd5667 tools/demo.py --- a/tools/demo.py Sat Oct 01 16:26:27 2005 +0000 +++ b/tools/demo.py Sat Oct 01 16:27:18 2005 +0000 @@ -4,23 +4,42 @@ import os, sys -# Find out where XSLTools' distribution directory is. +# Find out where the XSLTools distribution directory is. -cwd = os.getcwd() +program = sys.argv[0] +cwd = os.path.split(program)[0] parts = os.path.split(cwd) if parts[-1] == "tools": parts = parts[:-1] base = os.path.join(*parts) -# Set up the environment and run the demo program. +# Set up the environment and obtain the demo resource. + +sys.path.append(base) +sys.path.append(os.path.join(base, "examples", "Common")) + +import DemoApp +resource = DemoApp.get_site() + +# Try and open the application in a Web browser. +# The preferred module is Paul's proposed desktop module - see #1301512 in +# the Python SourceForge project: http://www.python.org/sf?id=1301512 -pythonpath = os.environ.get("PYTHONPATH") -if pythonpath: - pythonpath = pythonpath + os.pathsep -else: - pythonpath = "" +if "--nobrowser" not in sys.argv: + print "Opening a browser to show the application." + print "If this fails, specify --nobrowser to turn it off." + try: + import desktop + except ImportError: + import webbrowser as desktop -os.environ["PYTHONPATH"] = "%s%s%s%s" % (pythonpath, base, os.pathsep, os.path.join(base, "examples", "Common")) -os.system("%s %s" % (sys.executable, os.path.join(base, "examples", "BaseHTTPRequestHandler", "DemoApp.py"))) + desktop.open("http://localhost:8080") + +# Special magic incantation to start the demo. + +from WebStack.Adapters.BaseHTTPRequestHandler import deploy + +print "Serving..." +deploy(resource, handle_errors=0) # vim: tabstop=4 expandtab shiftwidth=4