diff options
| author | Marc Abramowitz <marc@marc-abramowitz.com> | 2015-01-20 10:44:37 -0800 |
|---|---|---|
| committer | Marc Abramowitz <marc@marc-abramowitz.com> | 2015-01-20 13:57:55 -0800 |
| commit | 8dd970873a58e1f017c8bce7be62409b313f74e1 (patch) | |
| tree | 7232ef52dfd5a2c518d6cc15b2299dc7cc9ba438 | |
| parent | 64f9cfaf331310cf54285c49d705098aa3d07944 (diff) | |
| download | pyramid-8dd970873a58e1f017c8bce7be62409b313f74e1.tar.gz pyramid-8dd970873a58e1f017c8bce7be62409b313f74e1.tar.bz2 pyramid-8dd970873a58e1f017c8bce7be62409b313f74e1.zip | |
Give pserve the ability top open server in browser
E.g.:
pserve app.ini --browser
or:
pserve app.ini -b
| -rw-r--r-- | CHANGES.txt | 3 | ||||
| -rw-r--r-- | pyramid/scripts/pserve.py | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 150ca85b3..0a28dc248 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -68,6 +68,9 @@ Features possible to return bytes or unicode. See https://github.com/Pylons/pyramid/pull/1417 +- ``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 + Bug Fixes --------- 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 |
