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