1 #!/usr/bin/env python 2 3 "Start the demonstration program." 4 5 import os, sys 6 7 # Configuration. 8 9 app_url = "http://localhost:8080" # No trailing "/"! 10 secret_key = "horses" 11 12 # Find out where WebStack's distribution directory is. 13 14 program = sys.argv[0] 15 cwd = os.path.split(program)[0] 16 parts = os.path.split(cwd) 17 if parts[-1] == "tools": 18 parts = parts[:-1] 19 base = os.path.join(*parts) 20 21 # Set up the environment and obtain the demo resource. 22 23 sys.path.append(base) 24 sys.path.append(os.path.join(base, "examples", "Common")) 25 26 import DemoApp 27 resource = DemoApp.get_site(app_url, secret_key) 28 29 # Try and open the application in a Web browser. 30 # The preferred module is Paul's desktop module: 31 # http://www.python.org/pypi/desktop 32 33 if "--nobrowser" not in sys.argv: 34 print "Opening a browser to show the application." 35 print "If this fails, specify --nobrowser to turn it off." 36 try: 37 import desktop 38 except ImportError: 39 import webbrowser as desktop 40 41 desktop.open(app_url) 42 43 # Special magic incantation to start the demo. 44 45 from WebStack.Adapters.BaseHTTPRequestHandler import deploy 46 47 # Or try other implementations... 48 49 #from WebStack.Adapters.WSGI import deploy_with_wsgiref as deploy 50 #from WebStack.Adapters.Twisted import deploy 51 52 print "Serving..." 53 deploy(resource, handle_errors=1) 54 55 # vim: tabstop=4 expandtab shiftwidth=4