1.1 --- a/tools/demo.py Sat Oct 01 16:26:27 2005 +0000
1.2 +++ b/tools/demo.py Sat Oct 01 16:27:18 2005 +0000
1.3 @@ -4,23 +4,42 @@
1.4
1.5 import os, sys
1.6
1.7 -# Find out where XSLTools' distribution directory is.
1.8 +# Find out where the XSLTools distribution directory is.
1.9
1.10 -cwd = os.getcwd()
1.11 +program = sys.argv[0]
1.12 +cwd = os.path.split(program)[0]
1.13 parts = os.path.split(cwd)
1.14 if parts[-1] == "tools":
1.15 parts = parts[:-1]
1.16 base = os.path.join(*parts)
1.17
1.18 -# Set up the environment and run the demo program.
1.19 +# Set up the environment and obtain the demo resource.
1.20 +
1.21 +sys.path.append(base)
1.22 +sys.path.append(os.path.join(base, "examples", "Common"))
1.23 +
1.24 +import DemoApp
1.25 +resource = DemoApp.get_site()
1.26 +
1.27 +# Try and open the application in a Web browser.
1.28 +# The preferred module is Paul's proposed desktop module - see #1301512 in
1.29 +# the Python SourceForge project: http://www.python.org/sf?id=1301512
1.30
1.31 -pythonpath = os.environ.get("PYTHONPATH")
1.32 -if pythonpath:
1.33 - pythonpath = pythonpath + os.pathsep
1.34 -else:
1.35 - pythonpath = ""
1.36 +if "--nobrowser" not in sys.argv:
1.37 + print "Opening a browser to show the application."
1.38 + print "If this fails, specify --nobrowser to turn it off."
1.39 + try:
1.40 + import desktop
1.41 + except ImportError:
1.42 + import webbrowser as desktop
1.43
1.44 -os.environ["PYTHONPATH"] = "%s%s%s%s" % (pythonpath, base, os.pathsep, os.path.join(base, "examples", "Common"))
1.45 -os.system("%s %s" % (sys.executable, os.path.join(base, "examples", "BaseHTTPRequestHandler", "DemoApp.py")))
1.46 + desktop.open("http://localhost:8080")
1.47 +
1.48 +# Special magic incantation to start the demo.
1.49 +
1.50 +from WebStack.Adapters.BaseHTTPRequestHandler import deploy
1.51 +
1.52 +print "Serving..."
1.53 +deploy(resource, handle_errors=0)
1.54
1.55 # vim: tabstop=4 expandtab shiftwidth=4