[Zope-CVS] CVS: Products/Ape - component.xml:1.1 datatypes.py:1.1

Shane Hathaway shane@zope.com
Sat, 2 Aug 2003 13:19:01 -0400


Update of /cvs-repository/Products/Ape
In directory cvs.zope.org:/tmp/cvs-serv4227

Added Files:
	component.xml datatypes.py 
Log Message:
Added to the Zope 2 ZConfig schema.  You can now set up Ape databases via zope.conf if you make a minor local change to zopeschema.xml.

=== Added File Products/Ape/component.xml ===
<?xml version="1.0"?>

<!-- Ape storage and database ZConfig section setup

To use this, first add the following line near the top of
Zope/Startup/zopeschema.xml:

  <import package="Products.Ape"/>

Then add to zope.conf:

<ape-db fs>
  <ape-storage>
    mapper-variation filesystem
    <ape-fs-connection fs>
      basepath $INSTANCE/var/myfs
    </ape-fs-connection>
  </ape-storage>
  mount-point /fs
  scan-interval 10
</ape-db>

-->


<component prefix="Products.Ape.datatypes">

  <abstracttype name="apelib.Connection" />

  <sectiontype name="ape-storage" implements="ZODB.storage"
      datatype=".Storage">
    <key name="mapper-variation" required="yes">
      <description>
        The name of the mapper variation to load from apeconf.xml
        files.  See Products/Ape/doc/apexml.txt.
      </description>
    </key>
    <multisection type="apelib.Connection" name="+" attribute="connections">
      <description>
        Defines a database connector for use with this storage.
      </description>
    </multisection>
  </sectiontype>


  <sectiontype name="ape-fs-connection" implements="apelib.Connection"
      datatype=".FSConnection">
    <key name="basepath" required="yes">
      <description>
        The base filesystem path for the storage.
      </description>
    </key>
    <key name="metadata-prefix" default=".">
      <description>
        The prefix to use for all metadata files.
      </description>
    </key>
    <key name="hidden-filenames" default="_">
      <description>
        A regular expression that determines which filenames should be
        hidden from the object system.  The default is '_', meaning
        that filenames starting with an underscore do not appear in
        the object system.  This filter is in addition to the metadata
        filename filtering.
      </description>
    </key>
  </sectiontype>


  <sectiontype name="ape-dbapi-connection" implements="apelib.Connection"
      datatype=".DBAPIConnection">
    <key name="module-name" required="yes">
      <description>
        The base filesystem path for the storage.
      </description>
    </key>
    <key name="prefix" default="zodb">
      <description>
        A prefix to use for all tables in the database.
      </description>
    </key>
    <multikey name="param" attribute="params">
      <description>
        Positional parameters for opening the database.
      </description>
    </multikey>
    <key name="+" attribute="kwparams">
      <description>
        Keyword parameters for opening the database.
      </description>
    </key>
  </sectiontype>


  <sectiontype name="ape-db" implements="ZODB.database"
      datatype=".Database">
    <key name="mapper-variation" required="no">
      <description>
        The name of the mapper variation to load from apeconf.xml
        files.  See Products/Ape/doc/apexml.txt.
      </description>
    </key>
    <key name="scan-interval" datatype="integer" default="10">
      <description>
        Cache scan interval in seconds.  Set to 0 to disable scanning.
      </description>
    </key>

    <!-- ZConfig refuses to let us extend the "zodb_db" section type,
    therefore we have to duplicate.  Grumble.  The following is copied
    from ZODB/component.xml and Zope/Startup/zopeschema.xml, with
    package names expanded. -->

    <section type="ZODB.storage" name="*" attribute="storage"/>
    <key name="cache-size" datatype="integer" default="5000"/>
    <key name="pool-size" datatype="integer" default="7"/>
    <key name="version-pool-size" datatype="integer" default="3"/>
    <key name="version-cache-size" datatype="integer" default="100"/>

    <multikey name="mount-point" required="yes" attribute="mount_points"
              datatype="Zope.Startup.datatypes.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>

    <key name="connection-class"
         datatype="Zope.Startup.datatypes.importable_name">
      <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="Zope.Startup.datatypes.importable_name"
        default="DBTab.ClassFactories.autoClassFactory">
      <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>

    <key name="container-class"
         datatype="Zope.Startup.datatypes.importable_name">
      <description>
       Change the contiainer class a (mounted) database uses on a
       per-database basis to support a different container than a plain
       Folder. Use a Python dotted-path name to specify the container class.
      </description>
    </key>

  </sectiontype>

</component>



=== Added File Products/Ape/datatypes.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""ZConfig data types

$Id: datatypes.py,v 1.1 2003/08/02 17:18:56 shane Exp $
"""

from ZODB.config import BaseConfig
from Zope.Startup.datatypes import ZopeDatabase
from apelib.zope2.mapper import createMapper
from apelib.zodb3 import storage, db, resource


class Storage(BaseConfig):

    def open(self):
        config = self.config
        conns = {}
        for c in config.connections:
            conns[c.name] = c.open()
        mapper = createMapper(config.mapper_variation, search_products=1)
        r = resource.StaticResource(mapper)
        return storage.ApeStorage(r, conns, name=self.name)


class Database(ZopeDatabase):

    def createDB(self):
        config = self.config
        if config.mapper_variation:
            mapper = createMapper(config.mapper_variation, search_products=1)
            r = resource.StaticResource(mapper)
        else:
            r = None
        s = config.storage.open()
        kw = {}
        for name in ('scan_interval', 'pool_size', 'cache_size',
                     'version_pool_size', 'version_cache_size'):
            if hasattr(config, name):
                kw[name] = getattr(config, name)
        d = db.ApeDB(s, r, **kw)
        return d


def getParams(config):
    kw = {}
    for name in config.__dict__.keys():
        if not name.startswith('_'):
            kw[name] = getattr(config, name)
    return kw


class FSConnection(BaseConfig):

    def open(self):
        from apelib.fs.connection import FSConnection as impl
        return impl(**getParams(self.config))


class DBAPIConnection:

    def open(self):
        from apelib.sql.dbapi import DBAPIConnector as impl
        config = self.config
        return impl(module_name=config.module_name,
                    prefix=config.prefix,
                    params=config.params,
                    kwparams=config.kwparams)