[Zope-CVS] CVS: Products/AdaptableStorage/ZMI - FSConnection.py:1.3 FSMountPoint.py:1.2 FSTables.py:1.2 ObjectModel.py:1.2
Shane Hathaway
shane@cvs.zope.org
Tue, 23 Jul 2002 12:14:59 -0400
Update of /cvs-repository/Products/AdaptableStorage/ZMI
In directory cvs.zope.org:/tmp/cvs-serv23056/ZMI
Modified Files:
FSConnection.py FSMountPoint.py FSTables.py ObjectModel.py
Log Message:
Minor cleanup (expanded variable names and removed unused code).
It was possible, until now, to put any kind of object in an FS mount, but
the current structure limits you to storing even folderish objects in a
single file. Now it is more restrictive, so you can read any kind of
object, but not write them. The object selector stuff needs to be
revisited to reenable writing using variable-class models.
=== Products/AdaptableStorage/ZMI/FSConnection.py 1.2 => 1.3 ===
VERIFY_META_TYPES = 1
-TYPE_PIECE = 'type'
+FS_OB_TYPE_PIECE = 'fs_object_type'
DATA_PIECE = 'data'
META_TYPE_PIECE = 'meta_type'
@@ -141,9 +141,12 @@
'.gif Image',
'.jpg Image',
'.jpeg Image',
- 'directory Folder',
- 'object Pickled Object',
- 'unknown File',
+ '.html DTML Method',
+ '.dtml DTML Method',
+ 'object_directory Folder Object (Variable Class)',
+ 'object_file File Object (Variable Class)',
+ 'unknown_directory Folder',
+ 'unknown_file File',
)
_meta_type_lookup = None
@@ -198,7 +201,7 @@
path = self.expandPath(subpath)
# Do some early checking.
if os.path.exists(path):
- if piece_name == TYPE_PIECE:
+ if piece_name == FS_OB_TYPE_PIECE:
want_dir = (data == 'd')
if (want_dir != (not not os.path.isdir(path))):
raise RuntimeError, (
@@ -216,7 +219,7 @@
assert os.path.exists(path), path
isdir = os.path.isdir(path)
# Deal with special piece names first.
- if piece_name == TYPE_PIECE:
+ if piece_name == FS_OB_TYPE_PIECE:
return isdir and 'd' or 'f'
elif piece_name == DATA_PIECE:
# Read either the directory listing or the file contents.
@@ -253,18 +256,25 @@
props = self.getPropertiesFromFile(path)
meta_type = props.get(META_TYPE_PIECE)
if not meta_type and provide_default:
- if os.path.isdir(path):
- meta_type = self._meta_type_lookup.get('directory')
- else:
- stuff, ext = os.path.splitext(path) # ext includes the "."
+ stuff, ext = os.path.splitext(path) # ext includes the "."
+ if ext:
meta_type = self._meta_type_lookup.get(ext)
- if not meta_type:
- if props.get('class'):
- # No meta type, but the class is provided.
- meta_type = self._meta_type_lookup.get('object')
- if not meta_type:
- # Fall back to something for any file.
- meta_type = self._meta_type_lookup.get('unknown')
+ if not meta_type:
+ isdir = os.path.isdir(path)
+ if props.get('class'):
+ # No meta type, but the class is provided.
+ if isdir:
+ meta_type = self._meta_type_lookup.get(
+ 'object_directory')
+ else:
+ meta_type = self._meta_type_lookup.get(
+ 'object_file')
+ if not meta_type:
+ # Fall back to something for any file.
+ if isdir:
+ meta_type = self._meta_type_lookup.get('unknown_directory')
+ else:
+ meta_type = self._meta_type_lookup.get('unknown_file')
if meta_type:
meta_type = meta_type.strip()
return meta_type
@@ -324,7 +334,7 @@
def writeFinal(self, subpath, pieces):
# pieces is a mapping.
path = self.expandPath(subpath)
- t = pieces[TYPE_PIECE]
+ t = pieces[FS_OB_TYPE_PIECE]
if t == 'd' and not os.path.exists(path):
os.mkdir(path)
props_fn = self.getPropertiesPath(path)
@@ -333,12 +343,14 @@
props_f = open(props_fn, 'wb')
try:
for name, data in items:
- if name == TYPE_PIECE:
+ if name == FS_OB_TYPE_PIECE:
continue
elif name == DATA_PIECE:
if t == 'd':
# Change the list of subobjects.
# Here we only have to delete.
+ # Subobjects will be created later.
+ # XXX we might check for dotted names here.
self.deleteUnwanted(path, data)
else:
# Change file contents.
@@ -375,9 +387,9 @@
non_containers = {}
for subpath, pieces in items:
# type must be provided and must always be either 'd' or 'f'.
- if not pieces.has_key(TYPE_PIECE):
+ if not pieces.has_key(FS_OB_TYPE_PIECE):
raise RuntimeError, 'type not specified for %s' % subpath
- t = pieces[TYPE_PIECE]
+ t = pieces[FS_OB_TYPE_PIECE]
if t not in 'df':
raise RuntimeError, 'type must be "d" or "f" at %s' % subpath
dir = os.path.dirname(subpath)
@@ -386,43 +398,6 @@
"Not a directory: %s" % dir)
if t == 'f':
non_containers[subpath] = 1
-## else:
-## self.writeSubobjectMetaTypes(pending, subpath, pieces)
-## if not pieces.has_key(META_TYPE_PIECE):
-## # Copy the meta_type forward.
-## mt = self.getMetaType(self.expandPath(subpath), 0)
-## assert mt, (
-## 'Unable to copy forward the meta_type of "%s"' % subpath)
-## pieces[META_TYPE_PIECE] = mt
-
-
-## def writeSubobjectMetaTypes(self, pending, subpath, pieces):
-## """Store the meta_type of the objects being written.
-
-## Note that when objects change their meta_type, their
-## container must also be changed. Fortunately, Zope
-## doesn't allow the meta_type to be changed, but
-## if it did, perhaps a 'dynamic meta type' aspect could
-## be added to the subitem model, which would take care
-## of notifying the database that the container had changed.
-## """
-## listing = pieces.get(DATA_PIECE)
-## if listing is None:
-## raise RuntimeError, (
-## 'Did not supply directory listing at %s' % subpath)
-## for name, meta_type in listing:
-## item_subpath = '%s/%s' % (subpath, name)
-## if pending.isWriting(item_subpath):
-## # Add the meta_type.
-## pending.write(item_subpath, META_TYPE_PIECE, meta_type)
-## elif VERIFY_META_TYPES:
-## # Verify the meta_type has not changed.
-## item_path = self.expandPath(item_subpath)
-## current = self.getMetaType(item_path, 0)
-## if current and current != meta_type:
-## raise RuntimeError, (
-## 'meta_type changed unexpectedly at %s' %
-## item_path)
=== Products/AdaptableStorage/ZMI/FSMountPoint.py 1.1 => 1.2 ===
o.model_names = (
'dtml_method',
'folder',
- 'varclass',
+ 'var_folder',
+ 'var_file',
)
model.models._add(o)
- o = VariableClassObjectModel('varclass')
+ o = VariableClassObjectModel('var_folder')
+ o.model_names = (
+ 'class_name',
+ 'id_attr',
+ 'folder_items',
+ 'remaining_state_pickle',
+ )
+ o.class_aspect = 'class_name'
+ o.expect_meta_type = 'Folder Object (Variable Class)'
+ o.volatile = volatile
+ o.oid_generator = 'path'
+ model.models._add(o)
+
+ o = VariableClassObjectModel('var_file')
o.model_names = (
'class_name',
'id_attr',
'remaining_state_as_data',
)
o.class_aspect = 'class_name'
- o.expect_meta_type = 'Pickled Object'
+ o.expect_meta_type = 'File Object (Variable Class)'
o.volatile = volatile
o.oid_generator = 'path'
model.models._add(o)
=== Products/AdaptableStorage/ZMI/FSTables.py 1.1.1.1 => 1.2 ===
from Products.AdaptableStorage.Base.RecordSchema import RecordSequenceSchema
from Products.AdaptableStorage.ZMI.Tables import ManageableTable
from Products.AdaptableStorage.ZMI.utils import SimpleItemWithProperties
+from Products.AdaptableStorage.ZMI.FSConnection import FS_OB_TYPE_PIECE, \
+ META_TYPE_PIECE, DATA_PIECE
class FSManageableTable(ManageableTable):
@@ -52,15 +54,15 @@
def load(self, db_model, key):
c = self.getOpenConnection(db_model)
- assert c.read(key, 'type') == 'd'
- items = c.read(key, 'data')
+ assert c.read(key, FS_OB_TYPE_PIECE) == 'd'
+ items = c.read(key, DATA_PIECE)
res = self.canonical(items)
return res, res # Use the state as the serial.
def store(self, db_model, key, state):
c = self.getOpenConnection(db_model)
- c.write(key, 'type', 'd')
- c.write(key, 'data', state)
+ c.write(key, FS_OB_TYPE_PIECE, 'd')
+ c.write(key, DATA_PIECE, state)
return self.canonical(state)
@@ -74,8 +76,8 @@
def load(self, db_model, key):
c = self.getOpenConnection(db_model)
- assert c.read(key, 'type') == 'f'
- data = c.read(key, 'data', '')
+ assert c.read(key, FS_OB_TYPE_PIECE) == 'f'
+ data = c.read(key, DATA_PIECE, '')
state = ((data,),)
return state, state
@@ -83,8 +85,8 @@
c = self.getOpenConnection(db_model)
assert len(state) == 1
assert len(state[0]) == 1
- c.write(key, 'type', 'f')
- c.write(key, 'data', state[0][0])
+ c.write(key, FS_OB_TYPE_PIECE, 'f')
+ c.write(key, DATA_PIECE, state[0][0])
return state
@@ -125,7 +127,7 @@
def load(self, db_model, key):
c = self.getOpenConnection(db_model)
- data = c.read(key, 'meta_type', '').strip()
+ data = c.read(key, META_TYPE_PIECE, '').strip()
state = ((data,),)
return state, state
@@ -133,7 +135,7 @@
c = self.getOpenConnection(db_model)
assert len(state) == 1
assert len(state[0]) == 1
- c.write(key, 'meta_type', state[0][0])
+ c.write(key, META_TYPE_PIECE, state[0][0])
return state
=== Products/AdaptableStorage/ZMI/ObjectModel.py 1.1.1.1 => 1.2 ===
'select_variable': 'listAvailableOIDGenerators'},
)
- expect_meta_type = 'Pickled Object'
+ expect_meta_type = 'Object'
def __init__(self, id):
self.id = id
@@ -138,7 +138,7 @@
return res
def matchesClassification(self, c):
- return 1
+ return c.get('meta_type') == self.expect_meta_type
def getClassInfo(self, dm, full_state):
assert self.class_aspect