[Repoze-dev] Repoze CVS: obob_helper.py

Chris McDonough chrism at agendaless.com
Thu Sep 13 00:02:56 UTC 2007


Update of /home/repoze/cvs/repoze.zope2/repoze/zope2
In directory laguna.palladion.com:/tmp/cvs-serv17216/repoze/zope2

Modified Files:
	obob_helper.py 
Log Message:
Assume get_root will take a helper instead of an environ.


Index: obob_helper.py
===================================================================
RCS file: /home/repoze/cvs/repoze.zope2/repoze/zope2/obob_helper.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- obob_helper.py	12 Sep 2007 23:38:20 -0000	1.1
+++ obob_helper.py	13 Sep 2007 00:02:54 -0000	1.2
@@ -11,25 +11,23 @@
 
 db = None
 
-def _setconfig(configfile):
+def parse_config_file(config):
     """ Configure a Zope instance based on ZopeOptions.  Optionally
     accept a configfile argument (string path) in order to specify
     where the configuration file exists. """
     from Zope2.Startup import options, handlers
-    from App import config
     opts = options.ZopeOptions()
-    opts.configfile = configfile
+    opts.configfile = config['zope.conf']
     opts.realize(doc="Sorry, no option docs yet.", raise_getopt_errs=0)
     handlers.handleConfig(opts.configroot, opts.confighandlers)
-    import App.config
-    App.config.setConfiguration(opts.configroot)
     return opts
 
-def configure():
+def configure(config):
     from Zope2 import Startup
     starter = Startup.get_starter()
-    conf = environ['zope.conf']
-    opts = _setconfig(conf)
+    opts = parse_config_file(config)
+    import App.config
+    App.config.setConfiguration(opts.configroot)
     starter.setConfiguration(opts.configroot)
     starter.setupInitialLogging()
     #starter.setupLocale() # this is rude
@@ -42,13 +40,15 @@
     import Globals
     return Globals.DB
 
-def get_connection(environ, configure):
-    # we pass in configure to make testing this function a little easier
+def get_connection(helper, configure_fn):
+    # we pass in a configure function to make testing this function a
+    # little easier
     global db
     if not db:
-        db = configure()
+        db = configure_fn(helper.config)
     conn = db.open()
     closer = Closer(conn)
+    environ = helper.environ
     cleanup = environ.setdefault('tm.cleanup', {})
     cleanup['closeconn'] = closer # close the connection when the txn ends
     conn.setDebugInfo(environ)
@@ -73,8 +73,9 @@
     return request
 
 class Zope2ObobHelper:
-    def __init__(self, environ):
+    def __init__(self, environ, **config):
         self.environ = environ
+        self.config = config
         self.request = None
 
     def setup(self):
@@ -112,10 +113,10 @@
         # XXX implement
         pass
 
-def get_root(environ, configure=configure):
-    # we allow the override of configure here to make testing a bit easier,
-    # not because it's used by the API
-    conn = get_connection(environ, configure)
+def get_root(helper, configure_fn=configure):
+    # we allow the override of configure_fn here to make testing a bit
+    # easier, not because it's used by the API
+    conn = get_connection(helper, configure_fn)
     root = conn.root()
     app = root['Application']
     return app

_______________________________________________
Repoze-dev mailing list
Repoze-dev at lists.repoze.org
http://lists.repoze.org/mailman/listinfo/repoze-dev



More information about the Repoze-dev mailing list