+ def dsn(self, deployment):
+ """
+ Returns the deployment specific database URL. Uses the override file
+ in :file:`.wizard` if it exists, and otherwise attempt to extract the
+ variables from the source files.
+
+ Under some cases, the database URL will contain only the database
+ property, and no other values. This indicates that the actual DSN
+ should be determined from the environment.
+
+ This function might return ``None``.
+
+ .. note::
+
+ We are allowed to batch these two together, because the full precedence
+ chain for determining the database of an application combines these
+ two together. If this was not the case, we would have to call
+ :meth:`databaseUrlFromOverride` and :meth:`databaseUrlFromExtract` manually.
+ """
+ url = self.dsnFromOverride(deployment)
+ if url:
+ return url
+ return self.dsnFromExtract(deployment)
+ def dsnFromOverride(self, deployment):
+ """
+ Extracts database URL from an explicit dsn override file.
+ """
+ try:
+ return sqlalchemy.engine.url.make_url(open(deployment.dsn_file).read().strip())
+ except IOError:
+ return None
+ def dsnFromExtract(self, deployment):
+ """
+ Extracts database URL from a deployment, and returns them as
+ a :class:`sqlalchemy.engine.url.URL`. Returns ``None`` if we
+ can't figure it out: i.e. the conventional variables are not defined
+ for this application.
+ """
+ if not self.database:
+ return None
+ vars = self.extract(deployment)
+ names = ("WIZARD_DBSERVER", "WIZARD_DBUSER", "WIZARD_DBPASSWORD", "WIZARD_DBNAME")
+ host, user, password, database = (shlex.split(vars[x])[0] if vars[x] is not None else None for x in names)
+ # XXX: You'd have to put support for an explicit different database
+ # type here
+ return sqlalchemy.engine.url.URL(self.database, username=user, password=password, host=host, database=database)
+ def url(self, deployment):
+ """
+ Returns the deployment specific web URL. Uses the override file
+ in :file:`.wizard` if it exists, and otherwise attempt to extract
+ the variables from the source files.
+
+ This function might return ``None``, which indicates we couldn't figure
+ it out.
+ """
+ url = self.urlFromOverride(deployment)
+ if url:
+ return url
+ return self.urlFromExtract(deployment)
+ def urlFromOverride(self, deployment):
+ """
+ Extracts URL from explicit url override file.
+ """
+ try:
+ return urlparse.urlparse(open(deployment.url_file).read().strip())
+ except IOError:
+ return None
+ def urlFromExtract(self, deployment):
+ """
+ Extracts URL from a deployment, and returns ``None`` if we can't
+ figure it out. Default implementation is to fail; we might
+ do something clever with extractable variables in the future.
+ """
+ return None