| | |
| | | loadapp, |
| | | loadserver, |
| | | ) |
| | | from paste.deploy.loadwsgi import ( |
| | | SERVER, |
| | | loadcontext, |
| | | ) |
| | | |
| | | from pyramid.compat import PY2 |
| | | from pyramid.compat import configparser |
| | |
| | | '-b', '--browser', |
| | | dest='browser', |
| | | action='store_true', |
| | | help="Open a web browser to server url") |
| | | help=("Open a web browser to the server url. The server url is " |
| | | "determined from the 'open_url' setting in the 'pserve' " |
| | | "section of the configuration file.")) |
| | | parser.add_argument( |
| | | '-v', '--verbose', |
| | | default=default_verbosity, |
| | |
| | | loadapp = staticmethod(loadapp) # testing |
| | | loadserver = staticmethod(loadserver) # testing |
| | | |
| | | open_url = None |
| | | |
| | | _scheme_re = re.compile(r'^[a-z][a-z]+:', re.I) |
| | | |
| | | def __init__(self, argv, quiet=False): |
| | |
| | | self.args.verbose = 0 |
| | | if self.args.reload: |
| | | self.worker_kwargs = {'argv': argv, "quiet": quiet} |
| | | self.watch_files = [] |
| | | self.watch_files = set() |
| | | |
| | | def out(self, msg): # pragma: no cover |
| | | if self.args.verbose > 0: |
| | |
| | | try: |
| | | items = dict(config.items('pserve')) |
| | | except configparser.NoSectionError: |
| | | return |
| | | items = {} |
| | | |
| | | watch_files = aslist(items.get('watch_files', ''), flatten=False) |
| | | |
| | |
| | | file = resolver.resolve(file).abspath() |
| | | elif not os.path.isabs(file): |
| | | file = os.path.join(here, file) |
| | | self.watch_files.append(os.path.abspath(file)) |
| | | self.watch_files.add(os.path.abspath(file)) |
| | | |
| | | open_url = items.get('open_url') |
| | | if open_url: |
| | | self.open_url = open_url |
| | | |
| | | def run(self): # pragma: no cover |
| | | if not self.args.config_uri: |
| | |
| | | |
| | | # do not open the browser on each reload so check hupper first |
| | | if self.args.browser and not hupper.is_active(): |
| | | def open_browser(): |
| | | context = loadcontext( |
| | | SERVER, app_spec, name=server_name, relative_to=base, |
| | | global_conf=vars) |
| | | url = 'http://127.0.0.1:{port}/'.format(**context.config()) |
| | | time.sleep(1) |
| | | webbrowser.open(url) |
| | | t = threading.Thread(target=open_browser) |
| | | t.setDaemon(True) |
| | | t.start() |
| | | self.pserve_file_config(config_path, global_conf=vars) |
| | | url = self.open_url |
| | | if not url: |
| | | self.out('WARNING: could not determine the server\'s url to ' |
| | | 'open the browser. To fix this set the "open_url" ' |
| | | 'setting in the [pserve] section of the ' |
| | | 'configuration file.') |
| | | |
| | | else: |
| | | def open_browser(): |
| | | time.sleep(1) |
| | | webbrowser.open(url) |
| | | t = threading.Thread(target=open_browser) |
| | | t.setDaemon(True) |
| | | t.start() |
| | | |
| | | if self.args.reload and not hupper.is_active(): |
| | | if self.args.verbose > 1: |
| | |
| | | if config_path: |
| | | setup_logging(config_path, global_conf=vars) |
| | | self.pserve_file_config(config_path, global_conf=vars) |
| | | self.watch_files.append(config_path) |
| | | self.watch_files.add(config_path) |
| | | |
| | | if hupper.is_active(): |
| | | reloader = hupper.get_reloader() |
| | | reloader.watch_files(self.watch_files) |
| | | reloader.watch_files(list(self.watch_files)) |
| | | |
| | | server = self.loadserver( |
| | | server_spec, name=server_name, relative_to=base, global_conf=vars) |