]> scripts.mit.edu Git - wizard.git/commitdiff
Add wizard.sql.auth function and plugin, refresh docs.
authorEdward Z. Yang <ezyang@mit.edu>
Mon, 14 Jun 2010 04:13:43 +0000 (21:13 -0700)
committerEdward Z. Yang <ezyang@mit.edu>
Mon, 14 Jun 2010 04:13:43 +0000 (21:13 -0700)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
doc/index.rst
doc/module/wizard.sql.rst
doc/module/wizard.user.rst [new file with mode: 0644]
doc/plugin.rst
plugins/scripts/setup.py
plugins/scripts/wizard_scripts.py
wizard/deploy.py
wizard/install/__init__.py
wizard/sql.py
wizard/user.py

index 4437208aa3a7c9158773182d099469619386673d..085825af8a604cfaef59003a5d7849ccac3e155d 100644 (file)
@@ -83,6 +83,7 @@ Modules
     module/wizard.sql
     module/wizard.sset
     module/wizard.tests
+    module/wizard.user
     module/wizard.util
 
 Indices and tables
index 75191f5f477ce62a93f6c614474e38ab253f6998..659299c3646f8ec63a73a19c137fec787d0240d4 100644 (file)
@@ -6,5 +6,5 @@
 Functions
 ---------
 .. autofunction:: connect
-.. autofunction:: fill_url
+.. autofunction:: auth
 
diff --git a/doc/module/wizard.user.rst b/doc/module/wizard.user.rst
new file mode 100644 (file)
index 0000000..6aa235b
--- /dev/null
@@ -0,0 +1,9 @@
+:mod:`wizard.user`
+==================
+
+.. automodule:: wizard.user
+
+Functions
+---------
+
+.. autofunction:: quota
index c30fc5df4deba002a1ab9133c45039e2ea985b53..fb6e418bc1056711ca129a3848bd6c9f34e9a5e8 100644 (file)
@@ -45,19 +45,30 @@ For more information on how to create an application, check
 
     Plugins marked with prototype todo messages are not complete yet.
 
+.. _wizard.strategy:
+
 ``wizard.strategy``
 -------------------
 
 Used during installation to automatically determine values for
 installation parameters the user may have omitted.
 
+.. _wizard.sql.auth:
+
 ``wizard.sql.auth``
 --------------------
 
 Used to fill in a user's database authentication credentials if none are
-able to be determined from an application's configuration files.
+able to be determined from an application's configuration files.  Plugin
+should be a function that takes a single required argument ``url``,
+which is a :class:`sqlalchemy.engine.url.URL` with partial
+authentication information, including a database name, and should return either
+``None`` if it was unable to fill in authentication credentials for the
+user, or the completed URL.  Mutating the passed argument and then
+returning it is the expected modus operandi of a plugin.  The function
+that runs this plugin is :func:`wizard.sql.auth`.
 
-.. todo:: Prototype
+.. _wizard.deploy.web:
 
 ``wizard.deploy.web``
 ---------------------
@@ -67,7 +78,10 @@ an application's configuration files.  Plugin should be a function that
 takes a single required argument ``dir``, which is the directory to
 determint the web URL(s) for, and return a list or generator of
 :class:`urlparse.ParseResult` objects or URL strings of possible web locations
-for an application.
+for an application.  The function that runs this plugin is
+:func:`wizard.deploy.web`.
+
+.. _wizard.user.email:
 
 ``wizard.user.email``
 ---------------------
@@ -78,6 +92,8 @@ canonical form we recommend taking advantage of it.
 
 .. todo:: Prototype
 
+.. _wizard.user.operator:
+
 ``wizard.user.operator``
 ------------------------
 
@@ -88,6 +104,8 @@ information we recommend taking advantage of it.
 
 .. todo:: Prototype
 
+.. _wizard.user.passwd:
+
 ``wizard.user.passwd``
 ----------------------
 
@@ -98,6 +116,8 @@ alternative ``passwd`` lookup.
 
 .. todo:: Prototype
 
+.. _wizard.user.quota:
+
 ``wizard.user.quota``
 ---------------------
 
@@ -108,4 +128,5 @@ highly system dependent.  Use this hook to implement quota usage and
 limit reporting.  Plugin should be a function that takes a single
 required argument ``dir``, which is the directory to determine the quota
 for, and return a tuple ``(quota usage, quota limit)`` or ``(0, None)``
-if it could not determine quota.
+if it could not determine quota.  The function that runs this plugin is
+:func:`wizard.user.quota`.
index 057503287975515495170e50a7dc03f2d2c2c2bd..e9a07d3265e9a6be63946f3dcca594bb9d285fb4 100644 (file)
@@ -12,5 +12,6 @@ setuptools.setup(
     entry_points = {
         'wizard.user.quota': 'scripts = wizard_scripts:user_quota',
         'wizard.deploy.web': 'scripts = wizard_scripts:deploy_web',
+        'wizard.sql.auth': 'scripts = wizard_scripts:sql_auth',
     }
 )
index d97adc999903988a1ff98806967facb142ad5450..45fadbd62fcc744362ca5b7a6afde3495634ebd2 100644 (file)
@@ -98,3 +98,12 @@ class QuotaParseError(wizard.Error):
 
 ERROR: Could not parse quota. %s
 """ % self.msg
+
+def sql_auth(url):
+    if url.driver == "mysql":
+        try:
+            url.host, url.username, url.password = shell.Shell().eval("/mit/scripts/sql/bin/get-password").split()
+            return url
+        except shell.CallError:
+            pass
+    return None
index b1e8e6a9d55d9663f9a2e7857056f180754de461..27a1bb30bbb6d8b4d0712666f725bb1819f1f490 100644 (file)
@@ -80,6 +80,8 @@ 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
@@ -329,7 +331,7 @@ 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):
@@ -345,13 +347,6 @@ class Deployment(object):
             return self._url
         except StopIteration:
             raise UnknownWebPath
-    def enableOldStyleUrls(self):
-        """
-        Switches to using http://user.scripts.mit.edu/~user/app URLs.
-        No effect if they have an explicit .scripts/url override.
-        """
-        # XXX: This is pretty scripts specific
-        self._url = scripts.fill_url(self.location, self.application.url(self), old_style = True)
     @staticmethod
     def parse(line):
         """
index 64e3b09588d92bdcd4a68b8110c73b3fa91f0979..70bb3fd90d03b5dedfbb370f5b6cfc91b55942da 100644 (file)
@@ -32,7 +32,7 @@ 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)
+    options.dsn = sql.auth(options.dsn)
     # perform some sanity checks on the database
     database = options.dsn.database
     options.dsn.database = None
@@ -126,7 +126,7 @@ class ScriptsWebStrategy(Strategy):
         if not urls:
             raise StrategyFailed
         try:
-            self._url = urls.next()
+            self._url = urls.next() # pylint: disable-msg=E1101
         except StopIteration:
             raise StrategyFailed
     def execute(self, options):
index f19f5e3cbb6022881b614e22f747038f51b2373b..548d8a6d399c5b4cd897eb1337e7d732bb970a5f 100644 (file)
@@ -1,5 +1,7 @@
 import sqlalchemy
 import os
+import pkg_resources
+import copy
 
 from wizard import shell
 
@@ -14,10 +16,13 @@ def connect(url):
     meta.reflect()
     return meta
 
-def fill_url(url):
+def auth(url):
     """
     If the URL has a database name but no other values, it will
     use the global configuration, and then try the database name.
+
+    This function implements a plugin interface named
+    :ref:`wizard.sql.auth`.
     """
     if not url:
         return None
@@ -28,13 +33,12 @@ def fill_url(url):
     if any((url.host, url.username, url.password)):
         # don't try for defaults if a few of these were set
         return url
-    # this is hook stuff
-    if url.driver == "mysql":
-        try:
-            url.host, url.username, url.password = shell.Shell().eval("/mit/scripts/sql/bin/get-password").split()
-            return url
-        except shell.CallError:
-            pass
+    for entry in pkg_resources.iter_entry_points("wizard.sql.auth"):
+        func = entry.load()
+        r = func(copy.copy(url))
+        print r
+        if r is not None:
+            return r
     env_dsn = os.getenv("WIZARD_DSN")
     if env_dsn:
         old_url = url
index 81015eb04318196284667eb4ee151d7bf7b7c9e7..50fc7272cfe3473a867a5ec3d8edaaf669015d0f 100644 (file)
@@ -12,6 +12,9 @@ def quota(dir=None):
     Returns a tuple (quota usage, quota limit).  Returns ``(0, None)`` if
     the quota usage is unknown.  If ``dir`` is omitted, the current
     working directory is assumed.  Value returned is in bytes.
+
+    This function implements a plugin interface named
+    :ref:`wizard.user.quota`.
     """
     if dir is None:
         dir = os.getcwd()