[Zope-CVS] CVS: Products/Ape/apelib/fs - connection.py:1.2 interfaces.py:1.2 structure.py:1.2

Shane Hathaway shane@zope.com
Sat, 29 Mar 2003 17:28:20 -0500


Update of /cvs-repository/Products/Ape/apelib/fs
In directory cvs.zope.org:/tmp/cvs-serv10503/apelib/fs

Modified Files:
	connection.py interfaces.py structure.py 
Log Message:
Made _p_mtime work.  The modification time comes through a gateway and
gets installed by a serializer.

Note that the strategy we're using for SQL is starting to become
burdensome.  There is a lot of information we could collect with a
single query rather than several (currently a minimum of four queries
per object).  CompositeGateway is perhaps too simple.

Also updated the style of imports in sqlmapper and fsmapper.  By
importing modules rather than classes, the import statements are
simpler.  I think this is nice but not applicable everywhere.


=== Products/Ape/apelib/fs/connection.py 1.1.1.1 => 1.2 ===
--- Products/Ape/apelib/fs/connection.py:1.1.1.1	Sat Mar 15 18:44:37 2003
+++ Products/Ape/apelib/fs/connection.py	Sat Mar 29 17:27:49 2003
@@ -248,6 +248,14 @@
         return ext
 
 
+    def getModTime(self, subpath, default=0):
+        path = self._expandPath(subpath)
+        try:
+            return os.path.getmtime(path)
+        except OSError:
+            return default
+
+
     def _getPropertyPaths(self, path):
         """Returns the property and remainder paths for a path."""
         if os.path.isdir(path):
@@ -399,6 +407,11 @@
 
 
     def _closeOrDelete(self, f, fn):
+        """Finish writing or remove a file.
+
+        If f was opened, close it.  If f was not opened, no file is needed,
+        so remove it.
+        """
         if f is not None:
             f.close()
         else:


=== Products/Ape/apelib/fs/interfaces.py 1.1.1.1 => 1.2 ===
--- Products/Ape/apelib/fs/interfaces.py:1.1.1.1	Sat Mar 15 18:44:37 2003
+++ Products/Ape/apelib/fs/interfaces.py	Sat Mar 29 17:27:49 2003
@@ -73,3 +73,8 @@
     def getExtension(subpath):
         """Returns the filename extension used for a filesystem node.
         """
+
+    def getModTime(subpath, default=0):
+        """Returns the modification time of a file.
+        """
+


=== Products/Ape/apelib/fs/structure.py 1.1.1.1 => 1.2 ===
--- Products/Ape/apelib/fs/structure.py:1.1.1.1	Sat Mar 15 18:44:37 2003
+++ Products/Ape/apelib/fs/structure.py	Sat Mar 29 17:27:49 2003
@@ -117,3 +117,27 @@
         c.writeData(p, names)
         return tuple(state)
 
+
+class FSModTime:
+    """Reads the modification time of a file."""
+
+    __implements__ = IGateway
+
+    schema = FieldSchema('mtime', 'float')
+
+    def __init__(self, fs_conn):
+        self.fs_conn = fs_conn
+
+    def getSchema(self):
+        return self.schema
+
+    def load(self, event):
+        p = event.getKey()
+        state = float(self.fs_conn.getModTime(p))
+        return state, None  # Use None as the hash (see store())
+
+    def store(self, event, state):
+        # Under normal circumstances, there is no need to change the mod
+        # time of a file.  Ignore by returning None as the hash.
+        return None
+