[Zope-CVS] CVS: Products/Ape/lib/apelib/fs - annotated.py:1.4
base.py:1.7 connection.py:1.7 interfaces.py:1.4
Shane Hathaway
shane at zope.com
Fri Feb 20 22:30:40 EST 2004
Update of /cvs-repository/Products/Ape/lib/apelib/fs
In directory cvs.zope.org:/tmp/cvs-serv6073
Modified Files:
annotated.py base.py connection.py interfaces.py
Log Message:
Split IFSConnection into IFSReader and IFSWriter.
This makes FSConnection clearer, since all of its read methods look at
the filesystem while all of its write methods defer the write until
transaction commit.
=== Products/Ape/lib/apelib/fs/annotated.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/fs/annotated.py:1.3 Thu Feb 19 01:44:03 2004
+++ Products/Ape/lib/apelib/fs/annotated.py Fri Feb 20 22:30:39 2004
@@ -41,7 +41,7 @@
class AnnotatedFilesystem:
"""Filesystem abstraction that adds annotations and automatic extensions.
- Annotations are stored in .properties and .remainder files.
+ Annotations are stored in .properties files.
"""
def __init__(self, ops, annotation_prefix='.', hidden_filenames='_'):
=== Products/Ape/lib/apelib/fs/base.py 1.6 => 1.7 ===
--- Products/Ape/lib/apelib/fs/base.py:1.6 Mon Feb 2 10:07:20 2004
+++ Products/Ape/lib/apelib/fs/base.py Fri Feb 20 22:30:39 2004
@@ -16,9 +16,6 @@
$Id$
"""
-from interfaces import IFSConnection
-
-
class FSGatewayBase:
"""Base implementation for FS gateways."""
=== Products/Ape/lib/apelib/fs/connection.py 1.6 => 1.7 ===
--- Products/Ape/lib/apelib/fs/connection.py:1.6 Mon Feb 2 10:07:20 2004
+++ Products/Ape/lib/apelib/fs/connection.py Fri Feb 20 22:30:39 2004
@@ -17,7 +17,7 @@
"""
from apelib.core.interfaces import ITPCConnection, ISourceRepository, LoadError
-from interfaces import IFSConnection, FSWriteError
+from interfaces import IFSReader, IFSWriter, FSWriteError
from fileops import StandardFileOperations
from annotated import AnnotatedFilesystem, object_names_ann
@@ -36,16 +36,8 @@
class FSConnection:
"""Reads / writes files with annotations.
-
- The required 'type' annotation specifies whether the object is a file
- or a directory. The optional 'data' annotation specifies either the
- main file contents or the names of the files in the directory.
- All other annotations get stored in the '.properties' and
- '.remainder' files. The properties file uses square-bracket
- annotation headers and encodes annotations by doubling left-square
- brackets.
"""
- __implements__ = IFSConnection, ITPCConnection, ISourceRepository
+ __implements__ = IFSReader, IFSWriter, ITPCConnection, ISourceRepository
basepath = ''
@@ -62,6 +54,10 @@
# _pending: { subpath string -> { annotation_name -> data } }
self._pending = {}
+ #
+ # IFSReader implementation.
+ #
+
def getPath(self, subpath):
if self.basepath:
while subpath.startswith('/') or subpath.startswith('\\'):
@@ -111,27 +107,11 @@
annotations = self.afs.getAnnotations(path)
return annotations.get(name, default)
- def writeNodeType(self, subpath, data):
- self._queue(subpath, node_type_ann, data)
-
- def writeData(self, subpath, data, as_text=0):
- self._queue(subpath, data_ann, (data, as_text))
-
- def writeDirectory(self, subpath, names):
- self._queue(subpath, file_list_ann, names)
-
- def writeAnnotation(self, subpath, name, data):
- self.afs.checkAnnotationName(name)
- self._queue(subpath, name, data)
-
def getExtension(self, subpath):
path = self.getPath(subpath)
stuff, ext = self.ops.splitext(path)
return ext
- def suggestExtension(self, subpath, ext):
- self._queue(subpath, suggested_extension_ann, ext)
-
def getModTime(self, subpath, default=0):
"""Returns the time an object was last modified.
@@ -154,6 +134,60 @@
maxtime = default
return maxtime
+ #
+ # ISourceRepository implementation.
+ #
+
+ def _get_paths_mtime(self, paths):
+ t = []
+ for path in paths:
+ try:
+ t.append(self.ops.getmtime(path))
+ except OSError:
+ t.append(None)
+ return t
+
+ def getPollSources(self, subpath):
+ path = self.getPath(subpath)
+ extra = self.afs.getAnnotationPaths(path)
+ paths = (path,) + tuple(extra)
+ t = self._get_paths_mtime(paths)
+ return {(self, paths): t}
+
+ def poll(self, sources):
+ """ISourceRepository implementation.
+
+ Returns the changed items.
+ """
+ res = {}
+ for source, t in sources.items():
+ myself, paths = source
+ assert myself is self
+ new_t = self._get_paths_mtime(paths)
+ if t != new_t:
+ res[source] = new_t
+ return res
+
+ #
+ # IFSWriter implementation.
+ #
+
+ def writeNodeType(self, subpath, data):
+ self._queue(subpath, node_type_ann, data)
+
+ def writeData(self, subpath, data, as_text=0):
+ self._queue(subpath, data_ann, (data, as_text))
+
+ def writeDirectory(self, subpath, names):
+ self._queue(subpath, file_list_ann, names)
+
+ def writeAnnotation(self, subpath, name, data):
+ self.afs.checkAnnotationName(name)
+ self._queue(subpath, name, data)
+
+ def suggestExtension(self, subpath, ext):
+ self._queue(subpath, suggested_extension_ann, ext)
+
def _writeFinal(self, subpath, anns):
"""Performs an actual write of a file or directory to disk.
@@ -365,34 +399,3 @@
def close(self):
self.reset()
-
-
- def _get_paths_mtime(self, paths):
- t = []
- for path in paths:
- try:
- t.append(self.ops.getmtime(path))
- except OSError:
- t.append(None)
- return t
-
- def getPollSources(self, subpath):
- path = self.getPath(subpath)
- extra = self.afs.getAnnotationPaths(path)
- paths = (path,) + tuple(extra)
- t = self._get_paths_mtime(paths)
- return {(self, paths): t}
-
- def poll(self, sources):
- """ISourceRepository implementation.
-
- Returns the changed items.
- """
- res = {}
- for source, t in sources.items():
- myself, paths = source
- assert myself is self
- new_t = self._get_paths_mtime(paths)
- if t != new_t:
- res[source] = new_t
- return res
=== Products/Ape/lib/apelib/fs/interfaces.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/fs/interfaces.py:1.3 Mon Feb 2 10:07:20 2004
+++ Products/Ape/lib/apelib/fs/interfaces.py Fri Feb 20 22:30:39 2004
@@ -23,8 +23,8 @@
"""Unable to write data"""
-class IFSConnection (Interface):
- """Simple filesystem connection with annotations.
+class IFSReader (Interface):
+ """Filesystem reader that supports annotations.
"""
def getPath(subpath):
@@ -58,6 +58,29 @@
"""Reads a text-based annotation for a file.
"""
+ def getExtension(subpath):
+ """Returns the filename extension for a subpath.
+ """
+
+ def getModTime(subpath, default=0):
+ """Returns the last-modified time of a file.
+ """
+
+ def getPollSources(subpath):
+ """Returns source information for a subpath.
+
+ The source information is a mapping that maps
+ (source_repository, path) to a state object. The contents of
+ path and state are specific to a source repository. The
+ source repository (an ISourceRepository) may be polled
+ periodically to freshen the state of objects in caches.
+ """
+
+
+class IFSWriter (Interface):
+ """Filesystem writer that supports annotations.
+ """
+
def writeNodeType(subpath, data):
"""Writes the node type for a filesystem node.
@@ -80,27 +103,9 @@
"""Writes a text-based annotation for a filesystem node.
"""
- def getExtension(subpath):
- """Returns the filename extension for a subpath.
- """
-
def suggestExtension(subpath, ext):
"""Suggests a filename extension for a filesystem node.
The IFSConnection may use this information to store the file
with an automatically appended filename extension.
- """
-
- def getModTime(subpath, default=0):
- """Returns the last-modified time of a file.
- """
-
- def getPollSources(subpath):
- """Returns source information for a subpath.
-
- The source information is a mapping that maps
- (source_repository, path) to a state object. The contents of
- path and state are specific to a source repository. The
- source repository (an ISourceRepository) may be polled
- periodically to freshen the state of objects in caches.
"""
More information about the Zope-CVS
mailing list