+def web(dir, url=None):
+ """
+ Attempts to determine the URL a directory would be web-accessible at.
+ If ``url`` is specified, automatically use it. Returns a generator which
+ produces a list of candidate urls.
+
+ This function implements a plugin interface named :ref:`wizard.deploy.web`.
+ """
+ if url:
+ if isinstance(url, str):
+ url = urlparse.urlparse(url)
+ logging.info("wizard.deploy.web: Using default URL %s", url)
+ yield url
+ return
+
+ for entry in pkg_resources.iter_entry_points("wizard.deploy.web"):
+ logging.debug("wizard.deploy.web: Processing %s", entry)
+ f = entry.load()
+ for r in f(dir):
+ if isinstance(r, str):
+ r = urlparse.urlparse(r)
+ logging.info("wizard.deploy.web: Using plugin-supplied URL %s", r)
+ yield r
+
+ # try the environment
+ host = os.getenv("WIZARD_WEB_HOST")
+ path = os.getenv("WIZARD_WEB_PATH")
+ if host is not None and path is not None:
+ r = urlparse.ParseResult(
+ "http",
+ host,
+ path.rstrip('/'),
+ "", "", "")
+ logging.info("wizard.deploy.web: Using environment URL %s", r)
+ yield r
+
+ logging.info("wizard.deploy.web: Exhausted URLs")
+