[CalendarServer-changes] [1206] CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Sat Feb 17 10:53:33 PST 2007


Revision: 1206
          http://trac.macosforge.org/projects/calendarserver/changeset/1206
Author:   cdaboo at apple.com
Date:     2007-02-17 10:53:33 -0800 (Sat, 17 Feb 2007)

Log Message:
-----------
Method to set a bunch properties on a resource in one go. Will be useful for copying.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/sqlprops.py
    CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/test/test_sqlprops.py

Modified: CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/sqlprops.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/sqlprops.py	2007-02-17 18:35:23 UTC (rev 1205)
+++ CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/sqlprops.py	2007-02-17 18:53:33 UTC (rev 1206)
@@ -128,6 +128,16 @@
         if self.index:
             self.index.setPropertyValue(self.rname, property.qname(), property)
 
+    def setAll(self, properties):
+        """
+        Write all properties into index.
+        
+        @param properties: C{list} of properties to write
+        """
+
+        if self.index:
+            self.index.setAllPropertyValues(self.rname, [(p.qname(), p) for p in properties])
+
     def delete(self, qname):
         """
         Delete proeprty from index.
@@ -220,6 +230,21 @@
         self._add_to_db(rname, self._encode(pname), cPickle.dumps(pvalue))
         self._db_commit()
 
+    def setAllPropertyValues(self, rname, properties):
+        """
+        Add a property.
+    
+        @param rname: a C{str} containing the resource name.
+        @param pname: a C{str} containing the name of the property to set.
+        @param pvalue: a C{str} containing the property value to set.
+        """
+        
+        # Remove what is there, then add it back.
+        for p in properties:
+            self._delete_from_db(rname, self._encode(p[0]))
+            self._add_to_db(rname, self._encode(p[0]), cPickle.dumps(p[1]))
+        self._db_commit()
+
     def getPropertyValue(self, rname, pname):
         """
         Get a property.

Modified: CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/test/test_sqlprops.py
===================================================================
--- CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/test/test_sqlprops.py	2007-02-17 18:35:23 UTC (rev 1205)
+++ CalendarServer/branches/users/cdaboo/sqlprops-1202/twistedcaldav/test/test_sqlprops.py	2007-02-17 18:53:33 UTC (rev 1206)
@@ -92,8 +92,7 @@
         for i in xrange(number):
             rsrc = CalDAVFile(os.path.join(self.collection_name, "file%04s.ics" % (i,)))
             index = sqlPropertyStore(rsrc)
-            for prop in SQLProps.props:
-                index.set(prop)
+            index.setAll(SQLProps.props)
         return index
 
     def test_db_init_directory(self):
@@ -137,6 +136,16 @@
         self.assertTrue(proplist == expected_proplist,
                         msg="Property lists do not match: %s != %s." % (proplist, expected_proplist))
 
+    def test_setallproperties(self):
+        index = self._setUpIndex()
+        index.setAll(SQLProps.props)
+        for prop in SQLProps.props:
+            self._testProperty(index, prop)
+        proplist = set(index.list())
+        expected_proplist = set([prop.qname() for prop in SQLProps.props])
+        self.assertTrue(proplist == expected_proplist,
+                        msg="Property lists do not match: %s != %s." % (proplist, expected_proplist))
+
     def test_deleteproperties(self):
         index = self._setUpIndex()
         for prop in SQLProps.props:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070217/e5637b8e/attachment.html


More information about the calendarserver-changes mailing list