[Zope3-checkins] CVS: Zope3/src/zope/app/fssync - committer.py:1.4

Guido van Rossum guido@python.org
Thu, 29 May 2003 12:10:29 -0400


Update of /cvs-repository/Zope3/src/zope/app/fssync
In directory cvs.zope.org:/tmp/cvs-serv9458

Modified Files:
	committer.py 
Log Message:
Hey, cool -- there's also an IDirectoryFactory API!  Use it.


=== Zope3/src/zope/app/fssync/committer.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/fssync/committer.py:1.3	Wed May 28 18:31:46 2003
+++ Zope3/src/zope/app/fssync/committer.py	Thu May 29 12:10:29 2003
@@ -34,7 +34,7 @@
 from zope.app.interfaces.container import IContainer
 from zope.app.fssync.classes import Default
 from zope.app.traversing import getPath
-from zope.app.interfaces.file import IFileFactory
+from zope.app.interfaces.file import IFileFactory, IDirectoryFactory
 
 class SynchronizationError(Exception):
     pass
@@ -199,7 +199,7 @@
             factory = resolve(factory_name)
             obj = factory()
         else:
-            # No factory; try using the IFileFactory feature
+            # No factory; try using IFileFactory or IDirectoryFactory
             as = getService(container, "Adapters")
             isuffix = name.rfind(".")
             if isuffix >= 0:
@@ -207,17 +207,30 @@
             else:
                 suffix = "."
 
-            factory = as.queryNamedAdapter(container, IFileFactory, suffix)
+            if os.path.isdir(fspath):
+                iface = IDirectoryFactory
+            else:
+                iface = IFileFactory
+
+            factory = as.queryNamedAdapter(container, iface, suffix)
             if factory is None:
-                factory = as.queryAdapter(container, IFileFactory)
+                factory = as.queryAdapter(container, iface)
 
-            if factory:
-                data = self.read_file(fspath)
-                obj = factory(name, None, data)
-                obj = removeAllProxies(obj)
+            if iface is IDirectoryFactory:
+                if factory:
+                    obj = factory(name)
+                    obj = removeAllProxies(obj)
+                else:
+                    raise SynchronizationError(
+                        "don't know how to create a directory")
             else:
-                # Oh well, assume the file is an xml pickle
-                obj = self.load_file(fspath)
+                if factory:
+                    data = self.read_file(fspath)
+                    obj = factory(name, None, data)
+                    obj = removeAllProxies(obj)
+                else:
+                    # Oh well, assume the file is an xml pickle
+                    obj = self.load_file(fspath)
 
         self.set_item(container, name, obj, replace)