[Zope-CVS] CVS: Packages/GadflyDA - Adapter.py:1.1 __init__.py:1.1 configure.zcml:1.1

Albertas Agejevas alga@codeworks.lt
Wed, 7 Aug 2002 06:54:18 -0400


Update of /cvs-repository/Packages/GadflyDA
In directory cvs.zope.org:/tmp/cvs-serv15715

Added Files:
	Adapter.py __init__.py configure.zcml 
Log Message:
Initial implementation of Gadfly DA.
Includes the patched gadfly version from Zope 2 ZGadflyDA

=== Added File Packages/GadflyDA/Adapter.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.
# 
##############################################################################
"""
$Id: Adapter.py,v 1.1 2002/08/07 10:54:17 alga Exp $
"""

import gadfly
import os

from Persistence import Persistent
from Zope.App.RDB.ZopeDatabaseAdapter import ZopeDatabaseAdapter, parseDSN
from Zope.App.RDB.ZopeDatabaseAdapter import DatabaseAdapterError
from Zope.App.RDB.ZopeConnection import ZopeConnection

GadflyError = DatabaseAdapterError

class GadflyAdapter(ZopeDatabaseAdapter):
    """A Gadfly adapter for Zope3"""
    
    __implements__ = ZopeDatabaseAdapter.__implements__
    
    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 must be of the form " \
                  "dbi://dbname or dbi://dbname;dir=directory for GadflyDA."

        connection = conn_info['dbname']
        dir = os.path.join('gadfly',
                           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


=== Added File Packages/GadflyDA/__init__.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.
# 
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: __init__.py,v 1.1 2002/08/07 10:54:17 alga Exp $
"""


=== Added File Packages/GadflyDA/configure.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
>

<content class=".Adapter.GadflyAdapter">
  <factory id="GadflyDA"
      permission="Zope.Public" />
  <require permission="Zope.Public" 
      interface="Zope.App.RDB.IZopeDatabaseAdapter." />
</content>

<include package=".Views" />

</zopeConfigure>