Marc Abramowitz
2015-01-20 760495fadfa1afe5513fe8addde884efdc88018d
Give pserve the ability to open server in browser

E.g.:

pserve app.ini --browser

or:

pserve app.ini -b
2 files modified
21 ■■■■■ changed files
CHANGES.txt 3 ●●●●● patch | view | raw | blame | history
pyramid/scripts/pserve.py 18 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -10,6 +10,9 @@
  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)
pyramid/scripts/pserve.py
@@ -21,9 +21,11 @@
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
@@ -121,6 +123,11 @@
        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',
@@ -334,6 +341,17 @@
                    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