import os
import logging
import sqlalchemy
+import warnings
import wizard
from wizard import scripts, shell, util
def dsn_callback(options):
if not isinstance(options.dsn, sqlalchemy.engine.url.URL):
options.dsn = sqlalchemy.engine.url.make_url(options.dsn)
+ # perform some sanity checks on the database
+ database = options.dsn.database
+ options.dsn.database = None
+ engine = sqlalchemy.create_engine(options.dsn)
+ # 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
# XXX: This is in the wrong place
def fetch(options, path, post=None):
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):
"""
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')
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", name)
+ 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):