[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup - __init__.py:1.9 datatypes.py:1.8 zopeschema.xml:1.11

Chris McDonough chrism@zope.com
Sat, 19 Jul 2003 22:56:20 -0400


Update of /cvs-repository/Zope/lib/python/Zope/Startup
In directory cvs.zope.org:/tmp/cvs-serv5583/lib/python/Zope/Startup

Modified Files:
	__init__.py datatypes.py zopeschema.xml 
Log Message:
Integrate DBTab into HEAD.

DBTab now obtains all values related to storages and databases from zope.conf.  It is also now just a package rather than a product.

A new product named ZODBMountPoint exposes the mount point functionality to the ZMI.


=== Zope/lib/python/Zope/Startup/__init__.py 1.8 => 1.9 ===
--- Zope/lib/python/Zope/Startup/__init__.py:1.8	Sat Jul 19 16:18:58 2003
+++ Zope/lib/python/Zope/Startup/__init__.py	Sat Jul 19 22:56:14 2003
@@ -21,31 +21,6 @@
 
 import ZConfig
 
-from cmdline import getOptions, getOptionDescriptions # exported
-
-# global to hold config structures
-_schema = None
-_configuration = None
-
-def getConfiguration():
-    return _configuration
-
-def getSchema():
-    global _schema
-    if _schema is None:
-        here = os.path.dirname(__file__)
-        path = os.path.join(here, 'zopeschema.xml')
-        _schema = ZConfig.loadSchema(path)
-    return _schema
-
-def configure(config_location, options):
-    global _configuration
-    import handlers
-    schema = getSchema()
-    _configuration, handler = ZConfig.loadConfig(schema, config_location)
-    handlers.handleConfig(_configuration, handler, options)
-    return _configuration
-
 def start_zope(cfg):
     # set up our initial logging environment (log everything to stderr
     # if we're not in debug mode).


=== Zope/lib/python/Zope/Startup/datatypes.py 1.7 => 1.8 ===
--- Zope/lib/python/Zope/Startup/datatypes.py:1.7	Tue Jul  8 01:25:16 2003
+++ Zope/lib/python/Zope/Startup/datatypes.py	Sat Jul 19 22:56:14 2003
@@ -103,7 +103,7 @@
 
 # Datatype for the root configuration object
 # (adds the softwarehome and zopehome fields; default values for some
-#  computed paths)
+#  computed paths, configures dbtab)
 
 def root_config(section):
     from ZConfig import ConfigurationError
@@ -125,31 +125,76 @@
     if not section.databases:
         section.databases = [getDefaultDatabaseFactory(section)]
 
-    section.db_mount_tab = db_mount_tab = {}
-    section.db_name_tab =  db_name_tab = {}
+    mount_factories = {} # { name -> factory}
+    mount_points = {} # { virtual path -> name }
     dup_err = ('Invalid configuration: ZODB databases named "%s" and "%s" are '
                'both configured to use the same mount point, named "%s"')
 
     for database in section.databases:
-        mount_points = database.config.mount_points
+        points = database.getVirtualMountPaths()
         name = database.config.getSectionName()
-        db_name_tab[name] = database
-        for point in mount_points:
-            if db_mount_tab.has_key(point):
-                raise ConfigurationError(dup_err % (db_mount_tab[point], name,
-                                         point))
-            db_mount_tab[point] = name
+        mount_factories[name] = database
+        for point in points:
+            if mount_points.has_key(point):
+                raise ConfigurationError(dup_err % (mount_points[point],
+                                                    name, point))
+            mount_points[point] = name
+    from DBTab.DBTab import DBTab
+    section.dbtab = DBTab(mount_factories, mount_points)
 
     return section
 
 class ZopeDatabase(ZODBDatabase):
     """ A ZODB database datatype that can handle an extended set of
-    attributes """
+    attributes for use by DBTab """
+
+    container_class = 'OFS.Folder.Folder'
+
     def open(self):
         DB = ZODBDatabase.open(self)
         # set the connection class
         DB.klass = self.config.connection_class
+        if self.config.class_factory is not None:
+            DB.setClassFactory(self.config.class_factory)
+        from ZODB.ActivityMonitor import ActivityMonitor
+        DB.setActivityMonitor(ActivityMonitor())
         return DB
+
+    def getName(self):
+        return self.name
+
+    def getOpenAtStartup(self):
+        # XXX implement
+        return 0
+
+    def computeMountPaths(self):
+        mps = []
+        for part in self.config.mount_points:
+            real_root = None
+            if ':' in part:
+                # 'virtual_path:real_path'
+                virtual_path, real_path = part.split(':', 1)
+                if real_path.startswith('~'):
+                    # Use a special root.
+                    # 'virtual_path:~real_root/real_path'
+                    real_root, real_path = real_path[1:].split('/', 1)
+            else:
+                # Virtual path is the same as the real path.
+                virtual_path = real_path = part
+            mps.append((virtual_path, real_root, real_path))
+        return mps
+
+    def getVirtualMountPaths(self):
+        return [item[0] for item in self.computeMountPaths()]
+
+    def getMountParams(self, mount_path):
+        """Returns (real_root, real_path, container_class) for a virtual
+        mount path.
+        """
+        for (virtual_path, real_root, real_path) in self.computeMountPaths():
+            if virtual_path == mount_path:
+                return (real_root, real_path, self.container_class)
+        raise LookupError('Nothing known about mount path %s' % mount_path)
     
 def getDefaultDatabaseFactory(context):
     # default to a filestorage named 'Data.fs' in clienthome
@@ -176,5 +221,6 @@
     db_ns.version_cache_size = 100
     db_ns.mount_points = ['/']
     db_ns.connection_class = Connection
+    db_ns.class_factory = None
     return ZopeDatabase(db_ns)
 


=== Zope/lib/python/Zope/Startup/zopeschema.xml 1.10 => 1.11 ===
--- Zope/lib/python/Zope/Startup/zopeschema.xml:1.10	Sat Jul 19 18:37:12 2003
+++ Zope/lib/python/Zope/Startup/zopeschema.xml	Sat Jul 19 22:56:14 2003
@@ -139,16 +139,29 @@
       so this is a multikey.
     </description>
     <multikey name="mount-point" required="yes" attribute="mount_points"
-              datatype=".mount_point"/>
+              datatype=".mount_point">
+      <description>
+       The mount point is the slash-separated path to which this database
+       will be mounted within the Zope application server.
+      </description>
+    </multikey>
 
-    <description>
-     We want to allow people to be able to change the connection
-     class a database uses on a per-database basis to support
-     different connection policies.
-    </description>
     <key name="connection-class" datatype=".importable_name"
-              default="ZODB.Connection.Connection"/>
+              default="ZODB.Connection.Connection">
+      <description>
+       Change the connection class a database uses on a per-database basis to
+       support different connection policies.  Use a Python dotted-path
+       name to specify the connection class.
+      </description>
+    </key>
 
+   <key name="class-factory" datatype=".importable_name">
+      <description>
+       Change the class factory function a database uses on a
+       per-database basis to support different class factory policy.
+       Use a Python dotted-path name to specify the class factory function.
+      </description>
+    </key>
   </sectiontype>
 
   <!-- end of type definitions -->