[Zope-CVS] CVS: Products/AdaptableStorage/gateway_fs - FSClassificationSection.py:1.1 FSSectionData.py:1.2 public.py:1.2

Shane Hathaway shane@zope.com
Wed, 4 Dec 2002 23:18:38 -0500


Update of /cvs-repository/Products/AdaptableStorage/gateway_fs
In directory cvs.zope.org:/tmp/cvs-serv26322/gateway_fs

Modified Files:
	FSSectionData.py public.py 
Added Files:
	FSClassificationSection.py 
Log Message:
- Switched to use of the "remaining state" aspect, enabling storage of
any extra data found on ZODB objects.  Fixed bugs related to this.

- Made sure Zope 2 objects store their classification.

- Modified the serialization event interface a little to allow more
control over automatic references.  This needs work still.

- MetaTypeClassifier is now also an IAspectSerializer, making it
possible to delegate classification details to the classifier.



=== Added File Products/AdaptableStorage/gateway_fs/FSClassificationSection.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.
#
##############################################################################
"""Gateway of object classification data.

$Id: FSClassificationSection.py,v 1.1 2002/12/05 04:18:07 shane Exp $
"""

from serial_public import IGateway, RecordSchema

class FSClassificationSection:

    __implements__ = IGateway

    schema = RecordSchema()
    schema.addColumn('classification', 'classification')

    def __init__(self, fs_conn):
        self.fs_conn = fs_conn

    def getSchema(self):
        return self.schema

    def getIdFrom(self, key):
        pos = key.rfind('/')
        if pos >= 0:
            return key[pos + 1:]
        else:
            return key

    def load(self, object_mapper, key):
        classification = {}
        text = self.fs_conn.readSection(key, 'classification', '')
        if text:
            lines = text.split('\n')
            for line in lines:
                if '=' in line:
                    k, v = line.split('=', 1)
                    classification[k.strip()] = v.strip()
        if not classification:
            name = self.getIdFrom(key)
            classifier = object_mapper.getClassifier()
            isdir = (self.fs_conn.readNodeType(key) == 'd')
            classification, mapper_name = classifier.classifyFilename(
                name, isdir)
        items = classification.items()
        items.sort()
        return ((classification,),), tuple(items)

    def store(self, object_mapper, key, state, required=1):
        assert len(state) == 1
        assert len(state[0]) == 1
        classification = state[0][0]
        items = classification.items()
        items.sort()
        lines = []
        for k, v in items:
            lines.append('%s=%s' % (k.strip(), v.strip()))
        text = '\n'.join(lines)
        self.fs_conn.writeSection(key, 'classification', text, required)
        return tuple(items)



=== Products/AdaptableStorage/gateway_fs/FSSectionData.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_fs/FSSectionData.py:1.1	Wed Nov 27 13:37:05 2002
+++ Products/AdaptableStorage/gateway_fs/FSSectionData.py	Wed Dec  4 23:18:07 2002
@@ -39,8 +39,11 @@
         return state, state
 
     def store(self, object_mapper, key, state):
+        if not state:
+            return ''
         c = self.fs_conn
         assert len(state) == 1
         assert len(state[0]) == 1
         c.writeSection(key, self.section, state[0][0])
         return state
+


=== Products/AdaptableStorage/gateway_fs/public.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_fs/public.py:1.1	Wed Nov 27 13:37:05 2002
+++ Products/AdaptableStorage/gateway_fs/public.py	Wed Dec  4 23:18:07 2002
@@ -19,6 +19,7 @@
 from interfaces.public import *
 from exceptions import *
 from FSAutoId import FSAutoId
+from FSClassificationSection import FSClassificationSection
 from FSConnection import FSConnection
 from FSDirectoryItems import FSDirectoryItems
 from FSFileData import FSFileData