import warnings
import wizard
-from wizard import scripts, shell, util
+from wizard import scripts, shell, sql, util
def dsn_callback(options):
if not isinstance(options.dsn, sqlalchemy.engine.url.URL):
options.dsn = sqlalchemy.engine.url.make_url(options.dsn)
+ # do some guessing with sql
+ options.dsn = sql.fill_url(options.dsn)
# perform some sanity checks on the database
database = options.dsn.database
options.dsn.database = None
"""
return util.fetch(options.web_host, options.web_path, path, post)
-def preloads():
- """
- Retrieves a dictionary of string names to precanned :class:`ArgSet` objects.
- """
- return {
- 'web': WebArgSet(),
- 'db': DbArgSet(),
- 'admin': AdminArgSet(),
- 'email': EmailArgSet(),
- 'title': TitleArgSet(),
- }
-
class Strategy(object):
"""
Represents a strategy for calculating arg values without user input.
self.dir = dir
def prepare(self):
"""Uses :func:`wizard.scripts.get_web_host_and_path`."""
+ if self.dir is None:
+ raise StrategyFailed
self._url = scripts.fill_url(self.dir, None)
if not self._url:
raise StrategyFailed
self._triplet = shell.eval("/mit/scripts/sql/bin/get-password").split()
except shell.CallError:
raise StrategyFailed
+ if len(self._triplet) != 3:
+ raise StrategyFailed
self._username = os.getenv('USER')
if self._username is None:
raise StrategyFailed
"""Uses :envvar:`USER` and assumes you are an MIT affiliate."""
# XXX: should double-check that you're on a scripts server
# and fail if you're not.
+ # XXX: This might be buggy, because locker might be set to USER
self._user = os.getenv("USER")
if self._user is None:
raise StrategyFailed
prompt="Please decide on a title for your new website."),
]
+def preloads():
+ """
+ Retrieves a dictionary of string names to precanned :class:`ArgSet` objects.
+ """
+ return {
+ 'web': WebArgSet(),
+ 'db': DbArgSet(),
+ 'admin': AdminArgSet(),
+ 'email': EmailArgSet(),
+ 'title': TitleArgSet(),
+ }
+
class ArgSchema(object):
"""
Schema container for arguments.
Valid identifiers for subclasses of :class:`ArgSet` are:
- * ``mysql``, which populates the options ``mysql_host``, ``mysql_db``,
- ``mysql_user`` and ``mysql_password``.
+ * ``db``, which populates the option ``dsn``, which is a SQLAlchemy
+ database source name, with properties for ``drivername``,
+ ``username``, ``password``, ``host``, ``port``, ``database`` and
+ ``query``.
* ``admin``, which populates the options ``admin_name`` and
``admin_password``.
* ``email``, which populates the option ``email``.
Example::
- parser = ArgHandler("mysql", "admin", "email")
+ parser = ArgHandler("db", "admin", "email")
parser.add(Arg("title", help="Title of the new application"))
"""
#: Dictionary of argument names to :class:`Arg` objects in schema.
def add(self, arg):
"""Adds an argument to our schema."""
self.args[arg.name] = arg
- def commit(self, application, dir):
+ def commit(self, application, dir, web_stub_path):
"""Populates :attr:`strategies` and :attr:`provides`"""
self.strategies = []
self.provides = set()
raw_strategies = [
EnvironmentStrategy(self),
ScriptsWebStrategy(dir),
+ ScriptsWebStrategy(web_stub_path),
ScriptsMysqlStrategy(application, dir),
ScriptsEmailStrategy(),
]
- for arg in self.args.values():
- if os.getenv(arg.envname) is not None:
- self.provides.add(arg.name)
for strategy in raw_strategies:
try:
strategy.prepare()
if missing:
raise MissingRequiredParam(missing)
for strategy in self.strategies:
+ # If the application being installed doesn't need all of the
+ # parameters a strategy could provide, we don't use it.
if any(not hasattr(options, name) for name in strategy.provides):
if any(hasattr(options, name) for name in strategy.provides):
logging.warning("Ignored partial strategy %s" % strategy)