]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/install/__init__.py
Convert ad hoc shell calls to singleton instance; fix upgrade bug.
[wizard.git] / wizard / install / __init__.py
index 2cac842bcdf43642db572e48de04df91ccec5b6f..8ca40a30103e6a8250473fda9b7c39fb4eb0b456 100644 (file)
@@ -23,6 +23,7 @@ allow applications to refer to them as a single name.
 import os
 import logging
 import sqlalchemy
+import warnings
 
 import wizard
 from wizard import scripts, shell, util
@@ -34,8 +35,10 @@ def dsn_callback(options):
     database = options.dsn.database
     options.dsn.database = None
     engine = sqlalchemy.create_engine(options.dsn)
-    # generates warnings yeah yeah
-    engine.execute("CREATE DATABASE IF NOT EXISTS `%s`" % database)
+    # generates warnings http://groups.google.com/group/sqlalchemy/browse_thread/thread/b7123fefb7dd83d5
+    with warnings.catch_warnings():
+        warnings.simplefilter("ignore")
+        engine.execute("CREATE DATABASE IF NOT EXISTS `%s`" % database)
     options.dsn.database = database
     # XXX: another good thing to check might be that the database is empty
 
@@ -126,12 +129,14 @@ class ScriptsWebStrategy(Strategy):
         self.dir = dir
     def prepare(self):
         """Uses :func:`wizard.scripts.get_web_host_and_path`."""
-        self._tuple = scripts.get_web_host_and_path(self.dir)
-        if not self._tuple:
+        self._url = scripts.fill_url(self.dir, None)
+        if not self._url:
             raise StrategyFailed
     def execute(self, options):
         """No-op."""
-        options.web_host, options.web_path = self._tuple
+        options.web_host = self._url.netloc # pylint: disable-msg=E1101
+        options.web_path = self._url.path   # pylint: disable-msg=E1101
+        options.web_inferred = True # hacky: needed to see if we need a .scripts/url file
 
 class ScriptsMysqlStrategy(Strategy):
     """
@@ -148,7 +153,7 @@ class ScriptsMysqlStrategy(Strategy):
         if self.application.database != "mysql":
             raise StrategyFailed
         try:
-            self._triplet = shell.Shell().eval("/mit/scripts/sql/bin/get-password").split()
+            self._triplet = shell.eval("/mit/scripts/sql/bin/get-password").split()
         except shell.CallError:
             raise StrategyFailed
         self._username = os.getenv('USER')
@@ -156,11 +161,10 @@ class ScriptsMysqlStrategy(Strategy):
             raise StrategyFailed
     def execute(self, options):
         """Creates a new database for the user using ``get-next-database`` and ``create-database``."""
-        sh = shell.Shell()
         host, username, password = self._triplet
         # race condition
-        database = self._username + '+' + sh.eval("/mit/scripts/sql/bin/get-next-database", os.path.basename(self.dir))
-        sh.call("/mit/scripts/sql/bin/create-database", database)
+        database = self._username + '+' + shell.eval("/mit/scripts/sql/bin/get-next-database", os.path.basename(self.dir))
+        shell.call("/mit/scripts/sql/bin/create-database", database)
         options.dsn = sqlalchemy.engine.url.URL("mysql", username=username, password=password, host=host, database=database)
 
 class ScriptsEmailStrategy(Strategy):