Give pserve the ability to open server in browser
E.g.:
pserve app.ini --browser
or:
pserve app.ini -b
| | |
| | | output by showing the module instead of just ``__repr__``. |
| | | See: https://github.com/Pylons/pyramid/pull/1542 |
| | | |
| | | - ``pserve`` can now take a ``-b`` or ``--browser`` option to open the server |
| | | URL in a web browser. See https://github.com/Pylons/pyramid/pull/1533 |
| | | |
| | | .. _changes_1.5.2: |
| | | |
| | | 1.5.2 (2014-11-09) |
| | |
| | | import threading |
| | | import time |
| | | import traceback |
| | | import webbrowser |
| | | |
| | | from paste.deploy import loadserver |
| | | from paste.deploy import loadapp |
| | | from paste.deploy.loadwsgi import loadcontext, SERVER |
| | | |
| | | from pyramid.compat import PY3 |
| | | from pyramid.compat import WIN |
| | |
| | | dest='monitor_restart', |
| | | action='store_true', |
| | | help="Auto-restart server if it dies") |
| | | parser.add_option( |
| | | '-b', '--browser', |
| | | dest='browser', |
| | | action='store_true', |
| | | help="Open a web browser to server url") |
| | | parser.add_option( |
| | | '--status', |
| | | action='store_true', |
| | |
| | | msg = '' |
| | | self.out('Exiting%s (-v to see traceback)' % msg) |
| | | |
| | | if self.options.browser: |
| | | def open_browser(): |
| | | context = loadcontext(SERVER, app_spec, name=app_name, relative_to=base, |
| | | global_conf=vars) |
| | | url = 'http://{host}:{port}/'.format(**context.config()) |
| | | time.sleep(1) |
| | | webbrowser.open(url) |
| | | t = threading.Thread(target=open_browser) |
| | | t.setDaemon(True) |
| | | t.start() |
| | | |
| | | serve() |
| | | |
| | | def loadapp(self, app_spec, name, relative_to, **kw): # pragma: no cover |