[Zope-CVS] CVS: Products/Ape/lib/apelib/fs - connection.py:1.7.2.4
Shane Hathaway
shane at zope.com
Sat Feb 28 14:57:01 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/fs
In directory cvs.zope.org:/tmp/cvs-serv29120/fs
Modified Files:
Tag: ape-fs-oid-branch
connection.py
Log Message:
Stopped clobbering data when there is no _root.
Also made the name of the application object configurable. Zope calls
it "Application". :-)
=== Products/Ape/lib/apelib/fs/connection.py 1.7.2.3 => 1.7.2.4 ===
--- Products/Ape/lib/apelib/fs/connection.py:1.7.2.3 Thu Feb 26 10:02:45 2004
+++ Products/Ape/lib/apelib/fs/connection.py Sat Feb 28 14:57:00 2004
@@ -47,6 +47,11 @@
basepath = ''
root_oid = '0'
+ # When app_filename is set, FSConnection translates paths, placing
+ # the application object at basepath and the root at
+ # (basepath)/_root.
+ app_filename = 'Application'
+
def __init__(self, basepath, annotation_prefix='.', hidden_filenames='_',
ops=None):
# These attributes are used for both reading and writing.
@@ -81,12 +86,16 @@
p = self.table.getPath(self.root_oid, oid)
if p is None:
return self._tmp_subpaths.get(oid)
- if p and p[0] == 'Application':
- # Place the Application object at basepath.
- return p[1:]
+ if self.app_filename:
+ # Translate paths.
+ if p and p[0] == self.app_filename:
+ # Place the application object at basepath.
+ return p[1:]
+ else:
+ # Everything else goes in "_root".
+ return ['_root'] + p
else:
- # Everything else goes in "_root".
- return ['_root'] + p
+ return p
def getPath(self, oid):
p = self.getSubpath(oid)
@@ -145,7 +154,7 @@
stuff, ext = self.ops.splitext(path)
return ext
- def assignNew(self, oid, children):
+ def assignExisting(self, oid, children):
"""See IFSReader.
"""
dir_path = self.getPath(oid)
@@ -155,7 +164,7 @@
for name, child_oid in children:
assert child_oid
if existing.has_key(name) and existing[name] != child_oid:
- raise FSReadError("assignNew() doesn't change existing OIDs")
+ raise FSReadError("assignExisting() doesn't override")
filename = name_to_fn[name]
self.table.add(oid, filename, child_oid)
@@ -447,8 +456,10 @@
for child_oid in to_delete:
script.append(("delete", child_oid))
script.append(("writeAll", container_changes))
- if container_changes.has_key(self.root_oid):
- script.append(("fixupRoot", container_changes[self.root_oid]))
+ if self.app_filename and container_changes.has_key(self.root_oid):
+ # Link or unlink the application object.
+ root_changes = container_changes[self.root_oid]
+ script.append(("linkApp", root_changes.has_key(self.app_filename)))
script.append(("clearTemp",))
return script
@@ -473,10 +484,10 @@
self._rmrf(path)
self._tmp_subpaths.clear()
- def _moveAppContents(self, src, dest):
- """Move the application directory's contents, but not the directory.
+ def _moveBaseContents(self, src, dest):
+ """Move the base directory's contents, but not the directory.
- Also leaves behind any file whose name starts with an underscore.
+ Also leaves behind the _root and _tmp subdirectories.
"""
ops = self.ops
if not ops.exists(dest):
@@ -509,11 +520,11 @@
ops = self.ops
src = self.getPath(oid)
if src == self.basepath:
- # Move the application root by moving most of the contents
+ # Move the base by moving most of the contents
# instead of the actual directory.
- dest_sub = ('_tmp', 'app', 'data')
+ dest_sub = ('_tmp', 'base', 'data')
dest = ops.join(self.basepath, *dest_sub)
- self._moveAppContents(src, dest)
+ self._moveBaseContents(src, dest)
else:
# Move an object.
dest_sub = ('_tmp', 'oid.%s' % oid, 'data')
@@ -532,7 +543,7 @@
src_sub = self._tmp_subpaths[oid]
src = ops.join(self.basepath, *src_sub)
if dest == self.basepath:
- self._moveAppContents(src, dest)
+ self._moveBaseContents(src, dest)
else:
self._moveItem(src, dest)
del self._tmp_subpaths[oid]
@@ -543,9 +554,9 @@
ops = self.ops
path = self.getPath(oid)
if path == self.basepath:
- # Delete the application root.
+ # Delete the contents of the base directory.
for fn in ops.listdir(path):
- if not fn.startswith('_'):
+ if not fn in ('_root', '_tmp'):
self._rmrf(ops.join(self.basepath, fn))
else:
# Delete an object.
@@ -625,16 +636,17 @@
print "tossing: %s" % ', '.join(tossing)
break
- def _do_fixupRoot(self, fn_oid):
- """Script command: fix up the root after the root was written.
+
+ def _do_linkApp(self, app_exists):
+ """Script command: link or unlink the application object at the root.
"""
- path = self.ops.join(self.basepath, '_root', 'Application')
- if fn_oid.has_key('Application'):
- # The root has an Application. Represent it with a directory.
+ path = self.ops.join(self.basepath, '_root', self.app_filename)
+ if app_exists:
+ # The root has an application. Represent it with a directory.
if not self.ops.exists(path):
- self.ops.mkdir(path)
+ self.ops.makedirs(path)
else:
- # The root does not have an Application. Remove it.
+ # The root does not have an application. Remove it.
if self.ops.exists(path):
self.ops.rmtree(path)
@@ -652,6 +664,11 @@
ops = self.ops
if not ops.exists(self.basepath):
ops.makedirs(self.basepath)
+ if self.app_filename:
+ # If there are objects at basepath, create a _root
+ # containing an application also.
+ if self.afs.computeContents(self.basepath):
+ self._do_linkApp(1)
def begin(self):
self.afs.clearCache()
More information about the Zope-CVS
mailing list