[Zope-CVS] CVS: Products/AdaptableStorage/ZMI - FSMountPoint.py:1.1 Aspects.py:1.2 ContainerTab.py:1.2 DatabaseMountPoint.py:1.2 FSConnection.py:1.2

Shane Hathaway shane@cvs.zope.org
Thu, 18 Jul 2002 22:05:13 -0400


Update of /cvs-repository/Products/AdaptableStorage/ZMI
In directory cvs.zope.org:/tmp/cvs-serv12836/ZMI

Modified Files:
	Aspects.py ContainerTab.py DatabaseMountPoint.py 
	FSConnection.py 
Added Files:
	FSMountPoint.py 
Log Message:
Added a simple addable type: "filesystem mount point".  It really works!
(though I've done only limited testing.)


=== Added File Products/AdaptableStorage/ZMI/FSMountPoint.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
# 
##############################################################################
"""Filesystem Mount Point, a simplification of database mount points.

$Id: FSMountPoint.py,v 1.1 2002/07/19 02:05:12 shane Exp $
"""

import os
import Acquisition
from Acquisition import aq_base
from ZODB.Mount import MountPoint
import Globals
from Globals import DTMLFile
from OFS.SimpleItem import SimpleItem
from Products.PageTemplates.PageTemplateFile import PageTemplateFile

from Products.AdaptableStorage.Base.DBModelStorage import DBModelStorage
from Products.AdaptableStorage.Base.MDB import MDB
from Products.AdaptableStorage.Base.DatabaseModelSource \
     import StaticDBModelSource



class FilesystemMountPoint(MountPoint, SimpleItem):
    """ """
    meta_type = 'Filesystem Mount Point'

    icon = 'p_/broken'
    manage_options = ({'label':'Traceback', 'action':'manage_traceback'},)
    
    def __init__(self, fs_path):
        self.fs_path = fs_path
        MountPoint.__init__(self, fs_path, 'Filesystem (AdaptableStorage)')

    manage_traceback = DTMLFile('www/mountfail', globals())

    def mount_error_(self):
        return self._v_connect_error

    def __of__(self, parent):
        # Accesses the database, returning an acquisition
        # wrapper around the connected object rather than around self.
        # Note: the aq_base(self) part is important.  Otherwise the
        # acquisition chain seems to fall apart during traversal. :-(
        w_self = Acquisition.ImplicitAcquisitionWrapper(aq_base(self), parent)
        if parent is aq_base(parent) and self._v_data is None:
            # It's not going to be possible to unrestrictedTraverse().
            # Since someone is probably just doing
            # hasattr(aq_base(parent), me), it should be safe to just
            # return the wrapper around self.
            return w_self
        try:
            return w_self._getOrOpenObject(parent)
        except:
            return w_self

    def _createDB(self):
        '''Calls the external method to create the DB object.
        '''
        model = createFilesystemModel()
        source = StaticDBModelSource(model)
        storage = DBModelStorage(source)
        db = MDB(storage, source)
        return db

    def _getObjectFromConnection(self, conn):
        path = os.path.abspath(self.fs_path)
        oid = 'folder:%s' % path
        obj = conn[oid]
        data = aq_base(obj)
        self._v_data = (data,)
        return data

Globals.InitializeClass(FilesystemMountPoint)



def createFilesystemModel(volatile=1):
    """Returns a database model populated with FS-oriented components.
    """
    from DatabaseModel import DatabaseModel
    from FSConnection import FSConnection
    from FSTables import FSFolderContentsTable, FSFileDataTable, \
         FSExtraDataTable, FSMetaTypeTable, FSClassNameTable
    from Aspects import MRemainingStateAspect, MRollCallAspect, \
         IdAttributeAspect, IgnoreAttributeAspect, \
         FolderItemsAsAttributesAspect, ObjectDataAttributeAspect, \
         DTMLMethodGlobalsAspect, MetaTypeAspect, ClassNameAspect
    from ObjectModel import ObjectModel, VariableClassObjectModel
    from ObjectModelSelector import ObjectModelSelector

    # Ad-hoc component registration.

    model = DatabaseModel('model')
    conn = FSConnection('fs_conn')
    model._setObject('fs_conn', conn)

    t = FSClassNameTable('fs_class_name')
    t.connection = 'fs_conn'
    model.rec_storages._add(t)

    t = FSFileDataTable('fs_data')
    t.connection = 'fs_conn'
    model.rec_storages._add(t)

    t = FSFolderContentsTable('fs_folder_contents')
    t.connection = 'fs_conn'
    model.rec_storages._add(t)

    t = FSMetaTypeTable('fs_meta_type')
    t.connection = 'fs_conn'
    model.rec_storages._add(t)

    t = FSExtraDataTable('fs_pickle')
    t.connection = 'fs_conn'
    t.piece_name = 'pickle'
    model.rec_storages._add(t)

    a = MRemainingStateAspect('remaining_state_as_data')
    a.rs_name = 'fs_data'
    model.aspects._add(a)

    a = MRemainingStateAspect('remaining_state_pickle')
    a.rs_name = 'fs_pickle'
    model.aspects._add(a)

    a = ClassNameAspect('class_name')
    a.rs_name = 'fs_class_name'
    model.aspects._add(a)

    a = DTMLMethodGlobalsAspect('dtml_method_globals')
    model.aspects._add(a)

    a = ObjectDataAttributeAspect('dtml_method_raw')
    a.rs_name = 'fs_data'
    a.attrname = 'raw'
    model.aspects._add(a)

    a = FolderItemsAsAttributesAspect('folder_items')
    a.rs_name = 'fs_folder_contents'
    a.subobject_model_name = 'selector'
    model.aspects._add(a)

    a = IdAttributeAspect('id_attr')
    model.aspects._add(a)

    a = MetaTypeAspect('meta_type_attr')
    a.rs_name = 'fs_meta_type'
    model.aspects._add(a)

    a = MRollCallAspect('roll_call')
    model.aspects._add(a)

    o = ObjectModel('dtml_method')
    o.module_name = 'OFS.DTMLMethod'
    o.class_name = 'DTMLMethod'
    o.aspects = (
        'dtml_method_globals',
        'dtml_method_raw',
        'id_attr',
        'meta_type_attr',
        'remaining_state_pickle',
        )
    o.volatile = volatile
    o.oid_generator = 'path'
    model.models._add(o)

    o = ObjectModel('folder')
    o.module_name = 'OFS.Folder'
    o.class_name = 'Folder'
    o.aspects = (
        'folder_items',
        'id_attr',
        'meta_type_attr',
        'remaining_state_pickle',
        )
    o.volatile = volatile
    o.oid_generator = 'path'
    model.models._add(o)

    o = ObjectModelSelector('selector')
    o.model_names = (
        'dtml_method',
        'folder',
        'varclass',
        )
    model.models._add(o)

    o = VariableClassObjectModel('varclass')
    o.model_names = (
        'class_name',
        'id_attr',
        'remaining_state_as_data',
        )
    o.class_aspect = 'class_name'
    o.expect_meta_type = 'Pickled Object'
    o.volatile = volatile
    o.oid_generator = 'path'
    model.models._add(o)

    return model

    
manage_addFilesystemMountPointForm = PageTemplateFile(
    'www/addFilesystemMount', globals())

def manage_addFilesystemMountPoint(dispatcher, fs_path, REQUEST=None):
    """ """
    dest = dispatcher.this()
    ob = FilesystemMountPoint(fs_path)
    w_ob = Acquisition.ImplicitAcquisitionWrapper(ob, dest)
    w_ob._test(dest)  # Ensures the FS path already exists.
    # Get the ID from the object.
    id = ob.__of__(dest).getId()
    dest._setObject(id, ob)
    if REQUEST is not None:
        return dispatcher.manage_main(dispatcher, REQUEST)



=== Products/AdaptableStorage/ZMI/Aspects.py 1.1.1.1 => 1.2 ===
     meta_type = 'Aspect: Full State'
 
     _properties = ManageableAspect._properties[:1]
+    __init__ = ManageableAspect.__init__
 
 
 class MRemainingStateAspect(RemainingStateAspect, ManageableAspect):
@@ -124,6 +125,7 @@
     meta_type = 'Aspect: Remaining State'
 
     _properties = ManageableAspect._properties[:1]
+    __init__ = ManageableAspect.__init__
 
 
 class MRollCallAspect(AttributeRollCallAspect, ManageableAspect):
@@ -131,6 +133,7 @@
     meta_type = 'Aspect: Roll Call'
 
     _properties = ()
+    __init__ = ManageableAspect.__init__
 
 
 class IdAttributeAspect(ManageableAspect):


=== Products/AdaptableStorage/ZMI/ContainerTab.py 1.1.1.1 => 1.2 ===
             manage_tabs_message=manage_tabs_message,
             )
 
+    def _add(self, ob):
+        """Convenience for programatic adding."""
+        self._setObject(ob.getId(), ob)
+


=== Products/AdaptableStorage/ZMI/DatabaseMountPoint.py 1.1.1.1 => 1.2 ===
 $Id$
 """
 
-import cPickle
-
 import Acquisition
 from Acquisition import aq_base
 from ZODB.Mount import MountPoint
@@ -70,7 +68,7 @@
             return w_self
 
     def _createDB(self):
-        '''Calls the external method to create the DB object.
+        '''Gets the model and creates the DB object.
         '''
         model = self.unrestrictedTraverse(self.model_path)
         s_source = DynamicDBModelSource(model._p_jar._db, model._p_oid)


=== Products/AdaptableStorage/ZMI/FSConnection.py 1.1.1.1 => 1.2 ===
 
 
     def expandPath(self, subpath):
-        while subpath.startswith('/') or subpath.startswith('\\'):
-            subpath = subpath[1:]
-        return os.path.join(self.filesystem_path, subpath)
+        if self.filesystem_path:
+            while subpath.startswith('/') or subpath.startswith('\\'):
+                subpath = subpath[1:]
+            return os.path.join(self.filesystem_path, subpath)
+        else:
+            # unchanged.
+            return subpath
 
 
     def write(self, subpath, piece_name, data):