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@239 | 21 | import DemoApp |
paulb@239 | 22 | resource = DemoApp.get_site() |
paulb@239 | 23 | |
paulb@239 | 24 | # Try and open the application in a Web browser. |
paulb@239 | 25 | # The preferred module is Paul's proposed desktop module - see #1301512 in |
paulb@239 | 26 | # the Python SourceForge project: http://www.python.org/sf?id=1301512 |
paulb@114 | 27 | |
paulb@239 | 28 | if "--nobrowser" not in sys.argv: |
paulb@239 | 29 | print "Opening a browser to show the application." |
paulb@239 | 30 | print "If this fails, specify --nobrowser to turn it off." |
paulb@239 | 31 | try: |
paulb@239 | 32 | import desktop |
paulb@239 | 33 | except ImportError: |
paulb@239 | 34 | import webbrowser as desktop |
paulb@114 | 35 | |
paulb@239 | 36 | desktop.open("http://localhost:8080") |
paulb@239 | 37 | |
paulb@239 | 38 | # Special magic incantation to start the demo. |
paulb@239 | 39 | |
paulb@239 | 40 | from WebStack.Adapters.BaseHTTPRequestHandler import deploy |
paulb@239 | 41 | |
paulb@239 | 42 | print "Serving..." |
paulb@239 | 43 | deploy(resource, handle_errors=0) |
paulb@114 | 44 | |
paulb@114 | 45 | # vim: tabstop=4 expandtab shiftwidth=4 |