[Zope-CVS] CVS: Products/AdaptableStorage/gateway_fs - FSAutoId.py:1.2 FSClassificationSection.py:1.3 FSDirectoryItems.py:1.4 FSFileData.py:1.2 FSSectionData.py:1.3
Shane Hathaway
shane@zope.com
Fri, 6 Dec 2002 17:07:20 -0500
Update of /cvs-repository/Products/AdaptableStorage/gateway_fs
In directory cvs.zope.org:/tmp/cvs-serv8198/gateway_fs
Modified Files:
FSAutoId.py FSClassificationSection.py FSDirectoryItems.py
FSFileData.py FSSectionData.py
Log Message:
Experiment: removed mapper_name from OIDs, with the intent of allowing
loading and storage by different mappers depending on what the classifier
specifies. Not yet complete. Involved changes to virtually every module. :-)
I may decide to revert this. The shane-before-mapper-name-removal tag
was added just before this checkin.
=== Products/AdaptableStorage/gateway_fs/FSAutoId.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_fs/FSAutoId.py:1.1 Wed Nov 27 13:37:05 2002
+++ Products/AdaptableStorage/gateway_fs/FSAutoId.py Fri Dec 6 17:06:50 2002
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Automatic ID gateway based on the key of the item.
+"""Automatic ID gateway based on the keychain of the item.
$Id$
"""
@@ -28,18 +28,19 @@
def getSchema(self):
return self.schema
- def getIdFrom(self, key):
- pos = key.rfind('/')
+ def getIdFrom(self, keychain):
+ path = keychain[-1]
+ pos = path.rfind('/')
if pos >= 0:
- return key[pos + 1:]
+ return path[pos + 1:]
else:
- return key
+ return path
- def load(self, object_mapper, key):
- id = self.getIdFrom(key)
+ def load(self, object_mapper, keychain):
+ id = self.getIdFrom(keychain)
return ((id,),), id
- def store(self, object_mapper, key, state):
- id = self.getIdFrom(key)
+ def store(self, object_mapper, keychain, state):
+ id = self.getIdFrom(keychain)
assert state[0][0] == id, 'Mismatched file ID'
return id
=== Products/AdaptableStorage/gateway_fs/FSClassificationSection.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_fs/FSClassificationSection.py:1.2 Thu Dec 5 12:38:46 2002
+++ Products/AdaptableStorage/gateway_fs/FSClassificationSection.py Fri Dec 6 17:06:50 2002
@@ -13,33 +13,54 @@
##############################################################################
"""Gateway for storing classification data.
-The classification info is designed to be used by the container
-of an object, not the object itself. But frequently an object gets
-stored without its container being stored. So this gateway does nothing
-other than preserve classification information for an object.
-
$Id$
"""
-from serial_public import IGateway
-
-from FSConnection import WRITE_PRESERVE
+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 None
-
- def load(self, object_mapper, key):
- return None, None
-
- def store(self, object_mapper, key, state):
- self.fs_conn.writeSection(key, 'classification', '', WRITE_PRESERVE)
- return None
+ return self.schema
+ def getIdFrom(self, keychain):
+ path = keychain[-1]
+ pos = path.rfind('/')
+ if pos >= 0:
+ return path[pos + 1:]
+ else:
+ return path
+
+ def load(self, object_mapper, keychain):
+ c = self.fs_conn
+ text = c.readSection(keychain[-1], 'classification', '')
+ classification = {}
+ if text:
+ lines = text.split('\n')
+ for line in lines:
+ if '=' in line:
+ k, v = line.split('=', 1)
+ classification[k.strip()] = v.strip()
+ classification['node_type'] = c.readNodeType(keychain[-1])
+ classification['filename'] = self.getIdFrom(keychain)
+ return ((classification,),), text.strip()
+
+ def store(self, object_mapper, keychain, classification):
+ items = classification.items()
+ items.sort()
+ text = []
+ for k, v in items:
+ text.append('%s=%s' % (k, v))
+ text = '\n'.join(text)
+ # Write it only if the rest of the subobject is also stored
+ self.fs_conn.writeSection(keychain[-1], 'classification', text)
+ return text.strip()
=== Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py:1.3 Thu Dec 5 12:38:46 2002
+++ Products/AdaptableStorage/gateway_fs/FSDirectoryItems.py Fri Dec 6 17:06:50 2002
@@ -28,7 +28,7 @@
schema = RecordSchema()
schema.addColumn('id', 'string', 1)
- schema.addColumn('classification', 'classification')
+ schema.addColumn('keychain', 'keychain', 0)
def __init__(self, fs_conn):
self.fs_conn = fs_conn
@@ -36,57 +36,32 @@
def getSchema(self):
return self.schema
+ def getSubKeychain(self, keychain, name):
+ return keychain[:-1] + ((keychain[-1] + '/%s' % name),)
- def load(self, object_mapper, key):
+ def load(self, object_mapper, keychain):
c = self.fs_conn
- assert c.readNodeType(key) == 'd'
- names = c.readData(key)
+ assert c.readNodeType(keychain) == 'd'
+ names = c.readData(keychain)
names.sort()
res = []
- serial = []
for name in names:
- subkey = '%s/%s' % (key, name)
- ctext = c.readSection(subkey, 'classification', None)
- classification = {}
- if ctext:
- lines = ctext.split('\n')
- for line in lines:
- if '=' in line:
- k, v = line.split('=', 1)
- classification[k.strip()] = v.strip()
- if not classification:
- classifier = object_mapper.getClassifier()
- isdir = (c.readNodeType(subkey) == 'd')
- classification, mapper_name = classifier.classifyFilename(
- name, isdir)
- res.append((name, classification))
- items = classification.items()
- items.sort()
- serial.append((name, tuple(items)))
+ subkeychain = self.getSubKeychain(keychain, name)
+ res.append((name, subkeychain))
res.sort()
- serial.sort()
- return tuple(res), tuple(serial)
+ res = tuple(res)
+ return res, res
- def store(self, object_mapper, key, state):
+ def store(self, object_mapper, keychain, state):
c = self.fs_conn
- c.writeNodeType(key, 'd')
+ c.writeNodeType(keychain[-1], 'd')
names = []
- serial = []
- for name, classification in state:
+ state = list(state)
+ state.sort()
+ for name, subkeychain in state:
names.append(name)
- subkey = '%s/%s' % (key, name)
- items = classification.items()
- items.sort()
- serial.append((name, tuple(items)))
- text = []
- for k, v in items:
- text.append('%s=%s' % (k, v))
- text = '\n'.join(text)
- # Write it only if the rest of the subobject is also stored
- c.writeSection(subkey, 'classification', text, WRITE_CONDITIONAL)
- names.sort()
- serial.sort()
- c.writeData(key, names)
- return tuple(serial)
+ assert subkeychain == self.getSubKeychain(keychain, name)
+ c.writeData(keychain[-1], names)
+ return tuple(state)
=== Products/AdaptableStorage/gateway_fs/FSFileData.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/gateway_fs/FSFileData.py:1.1 Wed Nov 27 13:37:05 2002
+++ Products/AdaptableStorage/gateway_fs/FSFileData.py Fri Dec 6 17:06:50 2002
@@ -31,18 +31,18 @@
def getSchema(self):
return self.schema
- def load(self, object_mapper, key):
+ def load(self, object_mapper, keychain):
c = self.fs_conn
- assert c.readNodeType(key) == 'f'
- data = c.readData(key, '')
+ assert c.readNodeType(keychain[-1]) == 'f'
+ data = c.readData(keychain[-1], '')
state = ((data,),)
return state, state
- def store(self, object_mapper, key, state):
+ def store(self, object_mapper, keychain, state):
c = self.fs_conn
assert len(state) == 1
assert len(state[0]) == 1
- c.writeNodeType(key, 'f')
- c.writeData(key, state[0][0])
+ c.writeNodeType(keychain[-1], 'f')
+ c.writeData(keychain[-1], state[0][0])
return state
=== Products/AdaptableStorage/gateway_fs/FSSectionData.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_fs/FSSectionData.py:1.2 Wed Dec 4 23:18:07 2002
+++ Products/AdaptableStorage/gateway_fs/FSSectionData.py Fri Dec 6 17:06:50 2002
@@ -32,18 +32,18 @@
def getSchema(self):
return self.schema
- def load(self, object_mapper, key):
+ def load(self, object_mapper, keychain):
c = self.fs_conn
- data = c.readSection(key, self.section, '')
+ data = c.readSection(keychain[-1], self.section, '')
state = ((data,),)
return state, state
- def store(self, object_mapper, key, state):
+ def store(self, object_mapper, keychain, 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])
+ c.writeSection(keychain[-1], self.section, state[0][0])
return state