summaryrefslogtreecommitdiff
path: root/pyramid/scripts/pserve.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyramid/scripts/pserve.py')
-rw-r--r--pyramid/scripts/pserve.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py
index ea125a0dd..314efd839 100644
--- a/pyramid/scripts/pserve.py
+++ b/pyramid/scripts/pserve.py
@@ -21,9 +21,11 @@ import textwrap
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
@@ -122,6 +124,11 @@ class PServeCommand(object):
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',
dest='show_status',
@@ -334,6 +341,17 @@ class PServeCommand(object):
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