]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/deploy.py
Properly register salt values as random.
[wizard.git] / wizard / deploy.py
index 6d3ec6702f6ec3bef6520483eb1d1134cb23b52c..27a1bb30bbb6d8b4d0712666f725bb1819f1f490 100644 (file)
@@ -14,9 +14,11 @@ import time
 import traceback
 import shutil
 import errno
+import pkg_resources
+import urlparse
 
 import wizard
-from wizard import app, git, old_log, scripts, shell, sql, util
+from wizard import app, git, old_log, shell, sql, util
 
 ## -- Global Functions --
 
@@ -73,6 +75,35 @@ def parse_install_lines(show, versions_store, yield_errors = False, user = None)
         # yield
         yield d
 
+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 whic
+    produces a list of candidate urls.
+
+    This function implements a plugin interface named :ref:`wizard.deploy.web`.
+    """
+    if url:
+        yield url
+        return
+
+    for entry in pkg_resources.iter_entry_points("wizard.deploy.web"):
+        f = entry.load()
+        for r in f(dir):
+            if isinstance(r, str):
+                r = urlparse.urlparse(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:
+        yield urlparse.ParseResult(
+                    "http",
+                    host,
+                    path.rstrip('/'),
+                    "", "", "")
+
 ## -- Model Objects --
 
 @decorator.decorator
@@ -106,6 +137,7 @@ class Deployment(object):
         self._old_log = None
         self._dsn = None
         self._url = None
+        self._urlGen = None
     def invalidateCache(self):
         """
         Invalidates all cached variables.  This currently applies to
@@ -299,22 +331,22 @@ class Deployment(object):
     def dsn(self):
         """The :class:`sqlalchemy.engine.url.URL` for this deployment."""
         if not self._dsn:
-            self._dsn = sql.fill_url(self.application.dsn(self))
+            self._dsn = sql.auth(self.application.dsn(self))
         return self._dsn
     @property
     def url(self):
         """The :class:`urlparse.ParseResult` for this deployment."""
-        if not self._url:
-            self._url = scripts.fill_url(self.location, self.application.url(self))
-        if not self._url:
-            raise UnknownWebPath
+        if not self._urlGen:
+            self._urlGen = web(self.location, self.application.url(self))
+            self.nextUrl()
         return self._url
-    def enableOldStyleUrls(self):
-        """
-        Switches to using http://user.scripts.mit.edu/~user/app URLs.
-        No effect if they have an explicit .scripts/url override.
-        """
-        self._url = scripts.fill_url(self.location, self.application.url(self), old_style = True)
+    def nextUrl(self):
+        """"""
+        try:
+            self._url = self._urlGen.next() # pylint: disable-msg=E1101
+            return self._url
+        except StopIteration:
+            raise UnknownWebPath
     @staticmethod
     def parse(line):
         """
@@ -418,10 +450,18 @@ class ProductionCopy(Deployment):
             raise DatabaseVerificationError
     def verifyWeb(self):
         """
-        Checks if the autoinstall is viewable from the web.
+        Checks if the autoinstall is viewable from the web.  If you do not run
+        this, there is no guarantee that the url returned by this application
+        is the correct one.
         """
-        if not self.application.checkWeb(self):
-            raise WebVerificationError
+        while True:
+            if not self.application.checkWeb(self):
+                try:
+                    self.nextUrl()
+                except UnknownWebPath:
+                    raise WebVerificationError
+            else:
+                break
     def fetch(self, path, post=None):
         """
         Performs a HTTP request on the website.