[Zope3-checkins] CVS: Zope3/src/zope/app/rdb - __init__.py:1.1.2.1 configure.zcml:1.1.2.1 gadflyda.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:32:10 -0500


Update of /cvs-repository/Zope3/src/zope/app/rdb
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/rdb

Added Files:
      Tag: NameGeddon-branch
	__init__.py configure.zcml gadflyda.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/rdb/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/rdb/configure.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
>

<content class="zope.app.rdb.gadflyda.GadflyAdapter">
  <factory id="GadflyDA"
      permission="Zope.Public" />
  <require permission="Zope.Public" 
      interface="zope.app.interfaces.rdb.IZopeDatabaseAdapter" />
  <implements interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />
</content>

<include package=".Views" />

</zopeConfigure>


=== Added File Zope3/src/zope/app/rdb/gadflyda.py ===
##############################################################################
#
# Copyright (c) 2002 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.
# 
##############################################################################
"""
Gadfly Database Adapter (batteries included)

$Id: gadflyda.py,v 1.1.2.1 2002/12/23 19:32:09 jim Exp $
"""

import gadfly
import os

from persistence import Persistent
from zope.app.rdb import ZopeDatabaseAdapter, parseDSN
from zope.app.rdb import DatabaseAdapterError
from zope.app.rdb import ZopeConnection

GadflyError = DatabaseAdapterError


class GadflyAdapter(ZopeDatabaseAdapter):
    """A Gadfly adapter for Zope3"""
    
    __implements__ = ZopeDatabaseAdapter.__implements__

    def _getGadflyRoot(self):
	# XXX: Need to write a configuration directive for setting this up
	# At the moment gadfly root is 'gadfly' under the instance home (which
	# is assumed to be the current directory ATM).
        return 'gadfly'
    
    def _connection_factory(self):
        """Create a Gadfly DBI connection based on the DSN.

        Only local (filesystem-based) Gadfly connections are supported
        at this moment."""

        conn_info = parseDSN(self.dsn)
        if conn_info['host'] != '' or conn_info['username'] != '' or \
           conn_info['port'] != '' or conn_info['password'] != '':
            raise DatabaseAdapterError, "DSN for GadflyDA must be of the form " \
                  "dbi://dbname or dbi://dbname;dir=directory."

        connection = conn_info['dbname']
        dir = os.path.join(self._getGadflyRoot(),
                           conn_info['parameters'].get('dir', connection))

        if not os.path.isdir(dir):
            raise DatabaseAdapterError, 'Not a directory ' + dir

        if not os.path.exists(os.path.join(dir, connection + ".gfd")):
            db = gadfly.gadfly()
            db.startup(connection, dir)
        else:
            db = gadfly.gadfly(connection, dir)
            
        return db