[CalendarServer-changes] [5102] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 12 13:27:50 PST 2010


Revision: 5102
          http://trac.macosforge.org/projects/calendarserver/changeset/5102
Author:   cdaboo at apple.com
Date:     2010-02-12 13:27:49 -0800 (Fri, 12 Feb 2010)
Log Message:
-----------
Support add/remove of augment records (batched). Make sure address book enable option is present.

Modified Paths:
--------------
    CalendarServer/trunk/bin/calendarserver_manage_augments
    CalendarServer/trunk/calendarserver/tools/loadaugmentdb.py
    CalendarServer/trunk/calendarserver/tools/manageaugments.py
    CalendarServer/trunk/conf/auth/augments-default.xml
    CalendarServer/trunk/conf/auth/augments.dtd
    CalendarServer/trunk/twistedcaldav/directory/augment.py
    CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml
    CalendarServer/trunk/twistedcaldav/directory/test/augments-test.xml
    CalendarServer/trunk/twistedcaldav/directory/test/augments.xml
    CalendarServer/trunk/twistedcaldav/directory/test/modify/augments.xml
    CalendarServer/trunk/twistedcaldav/directory/test/resources/augments.xml
    CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py
    CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py

Modified: CalendarServer/trunk/bin/calendarserver_manage_augments
===================================================================
--- CalendarServer/trunk/bin/calendarserver_manage_augments	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/bin/calendarserver_manage_augments	2010-02-12 21:27:49 UTC (rev 5102)
@@ -20,6 +20,7 @@
 #PYTHONPATH
 
 if __name__ == "__main__":
+
     if "PYTHONPATH" in globals():
         sys.path.insert(0, PYTHONPATH)
     else:
@@ -30,7 +31,7 @@
         run = join(home, "run")
 
         child = Popen((run, "-p"), stdout=PIPE)
-        path, stderr = child.communicate()
+        path, _ignore_stderr = child.communicate()
 
         path = path.rstrip("\n")
 

Modified: CalendarServer/trunk/calendarserver/tools/loadaugmentdb.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/loadaugmentdb.py	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/calendarserver/tools/loadaugmentdb.py	2010-02-12 21:27:49 UTC (rev 5102)
@@ -165,15 +165,22 @@
         updated = 0
         removed = 0
         if dbxml:
+            add_records = list()
+            modify_records = list()
             for record in dbxml.db.values():
-                yield augment.AugmentService.addAugmentRecord(record, record.uid in uids)
                 if record.uid in uids:
-                    updated += 1
+                    modify_records.append(record)
                 else:
-                    added += 1
-            for uid in uids.difference(dbxml.db.keys()):
-                yield augment.AugmentService.removeAugmentRecord(uid)
-                removed += 1
+                    add_records.append(record)
+            yield augment.AugmentService.addAugmentRecords(add_records, False)
+            added = len(add_records)
+
+            yield augment.AugmentService.addAugmentRecords(modify_records, True)
+            updated = len(modify_records)
+
+            remove_uids = uids.difference(dbxml.db.keys())
+            yield augment.AugmentService.removeAugmentRecords(remove_uids)
+            removed = len(remove_uids)
         else:
             yield augment.AugmentService.clean()
             removed = len(uids)

Modified: CalendarServer/trunk/calendarserver/tools/manageaugments.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/manageaugments.py	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/calendarserver/tools/manageaugments.py	2010-02-12 21:27:49 UTC (rev 5102)
@@ -15,120 +15,26 @@
 # limitations under the License.
 ##
 
+from calendarserver.tools.loadaugmentdb import StandardIOObserver
+from calendarserver.tools.util import loadConfig, getDirectory,\
+    autoDisableMemcached
+from grp import getgrnam
 from optparse import OptionParser
-from twistedcaldav.directory import xmlaugmentsparser
-from xml.etree.ElementTree import tostring
-import sys
+from pwd import getpwnam
+from twext.log import setLogLevelForNamespace
+from twisted.internet import reactor
+from twisted.python.util import switchUID
+from twistedcaldav.config import config, ConfigurationError
+from twistedcaldav.directory import augment
+from twistedcaldav.directory.augment import AugmentRecord
 import os
-from twistedcaldav.xmlutil import readXML, addSubElement, writeXML
+import sys
+from twisted.internet.defer import inlineCallbacks
 
 def error(s):
     print s
     sys.exit(1)
 
-def doAdd(xmlfile, uid, host, enable_calendar, auto_schedule):
-
-    try:
-        _ignore_etree, augments_node = readXML(xmlfile)
-    except ValueError, e:
-        error("Could not read XML file: %s" % (e,))
-
-    # Make sure UID is not already present
-    for child in augments_node.getchildren():
-        
-        if child.tag != xmlaugmentsparser.ELEMENT_RECORD:
-            error("Unknown augment type: '%s' in augment file: '%s'" % (child.tag, xmlfile,))
-
-        for node in child.getchildren():
-            
-            if node.tag == xmlaugmentsparser.ELEMENT_UID and node.text == uid:
-                error("Cannot add uid '%s' because it already exists in augment file: '%s'" % (uid, xmlfile,))
-    
-    # Create new record
-    if len(augments_node.getchildren()):
-        augments_node.getchildren()[-1].tail = "\n  "
-    record = addSubElement(augments_node, xmlaugmentsparser.ELEMENT_RECORD)
-    addSubElement(record, xmlaugmentsparser.ELEMENT_UID, uid)
-    addSubElement(record, xmlaugmentsparser.ELEMENT_ENABLE, "true")
-    addSubElement(record, xmlaugmentsparser.ELEMENT_HOSTEDAT, host)
-    addSubElement(record, xmlaugmentsparser.ELEMENT_ENABLECALENDAR, "true" if enable_calendar else "false")
-    addSubElement(record, xmlaugmentsparser.ELEMENT_AUTOSCHEDULE, "true" if auto_schedule else "false")
-    
-    # Modify xmlfile
-    writeXML(xmlfile, augments_node)
-    print "Added uid '%s' in augment file: '%s'" % (uid, xmlfile,)
-    
-def doModify(xmlfile, uid, host, enable_calendar, auto_schedule):
-
-    try:
-        _ignore_etree, augments_node = readXML(xmlfile)
-    except ValueError, e:
-        error("Could not read XML file: %s" % (e,))
-
-    # Make sure UID is present
-    for child in augments_node.getchildren():
-        
-        if child.tag != xmlaugmentsparser.ELEMENT_RECORD:
-            error("Unknown augment type: '%s' in augment file: '%s'" % (child.tag, xmlfile,))
-
-        for node in child.getchildren():
-            
-            if node.tag == xmlaugmentsparser.ELEMENT_UID and node.text == uid:
-                break
-        else:
-            continue
-        break
-    else:
-        error("Cannot modify uid '%s' because it does not exist in augment file: '%s'" % (uid, xmlfile,))
-    
-    # Modify record
-    if host is not None:
-        child.find(xmlaugmentsparser.ELEMENT_HOSTEDAT).text = host
-    child.find(xmlaugmentsparser.ELEMENT_ENABLECALENDAR).text = "true" if enable_calendar else "false"
-    child.find(xmlaugmentsparser.ELEMENT_AUTOSCHEDULE).text = "true" if auto_schedule else "false"
-    
-    # Modify xmlfile
-    writeXML(xmlfile, augments_node)
-    print "Modified uid '%s' in augment file: '%s'" % (uid, xmlfile,)
-
-def doRemove(xmlfile, uid):
-
-    try:
-        _ignore_etree, augments_node = readXML(xmlfile)
-    except ValueError, e:
-        error("Could not read XML file: %s" % (e,))
-
-    # Make sure UID is present
-    for child in augments_node.getchildren():
-        
-        if child.tag != xmlaugmentsparser.ELEMENT_RECORD:
-            error("Unknown augment type: '%s' in augment file: '%s'" % (child.tag, xmlfile,))
-
-        for node in child.getchildren():
-            
-            if node.tag == xmlaugmentsparser.ELEMENT_UID and node.text == uid:
-                break
-        else:
-            continue
-        augments_node.remove(child)
-        break
-    else:
-        error("Cannot remove uid '%s' because it does not exist in augment file: '%s'" % (uid, xmlfile,))
-    
-    # Modify xmlfile
-    writeXML(xmlfile, augments_node)
-    print "Removed uid '%s' from augment file: '%s'" % (uid, xmlfile,)
-    
-def doPrint(xmlfile):
-
-    # Read in XML
-    try:
-        _ignore_etree, augments_node = readXML(xmlfile)
-    except ValueError, e:
-        error("Could not read XML file: %s" % (e,))
-
-    print tostring(augments_node)
-
 def main():
 
     usage = "%prog [options] ACTION"
@@ -138,7 +44,6 @@
   add:    add a user record
   modify: modify a user record
   remove: remove a user record
-  print:  print all user records
 """
     description = "Tool to manipulate CalendarServer augments XML file"
     version = "%prog v1.0"
@@ -146,8 +51,8 @@
     parser.epilog = epilog
     parser.format_epilog = lambda _:epilog
 
-    parser.add_option("-f", "--file", dest="xmlfilename",
-                      help="XML augment file to manipulate", metavar="FILE")
+    parser.add_option("-f", "--file", dest="configfilename",
+                      help="caldavd.plist defining Augment Service", metavar="FILE")
     parser.add_option("-u", "--uid", dest="uid",
                       help="OD GUID to manipulate", metavar="UID")
     parser.add_option("-i", "--uidfile", dest="uidfile",
@@ -156,7 +61,9 @@
                       help="Partition node to assign to UID", metavar="NODE")
     parser.add_option("-c", "--enable-calendar", action="store_true", dest="enable_calendar",
                       default=True, help="Enable calendaring for this UID: %default")
-    parser.add_option("-a", "--auto-schedule", action="store_true", dest="auto_schedule",
+    parser.add_option("-a", "--enable-addressbooks", action="store_true", dest="enable_addressbook",
+                      default=True, help="Enable calendaring for this UID: %default")
+    parser.add_option("-s", "--auto-schedule", action="store_true", dest="auto_schedule",
                       default=False, help="Enable auto-schedule for this UID: %default")
 
     (options, args) = parser.parse_args()
@@ -164,31 +71,77 @@
     if len(args) != 1:
         parser.error("incorrect number of arguments")
 
-    uids = []
-    if options.uid:
-        uids.append(options.uid)
-    elif options.uidfile:
-        if not os.path.exists(options.uidfile):
-            parser.error("File containing list of UIDs does not exist")
-        with open(options.uidfile) as f:
-            for line in f:
-                uids.append(line[:-1])
-        
-    if args[0] == "add":
-        if not options.node:
-            parser.error("Partition node must be specified when adding")
-        for uid in uids:
-            doAdd(options.xmlfilename, uid, options.node, options.enable_calendar, options.auto_schedule)
-    elif args[0] == "modify":
-        for uid in uids:
-            doModify(options.xmlfilename, uid, options.node, options.enable_calendar, options.auto_schedule)
-    elif args[0] == "remove":
-        for uid in uids:
-            doRemove(options.xmlfilename, uid)
-    elif args[0] == "print":
-        doPrint(options.xmlfilename)
-    else:
-        parser.error("Unknown argument")
+    observer = StandardIOObserver()
+    observer.start()
 
+    #
+    # Get configuration
+    #
+    try:
+        loadConfig(options.configfilename)
+        setLogLevelForNamespace(None, "warn")
+
+        # Shed privileges
+        if config.UserName and config.GroupName and os.getuid() == 0:
+            uid = getpwnam(config.UserName).pw_uid
+            gid = getgrnam(config.GroupName).gr_gid
+            switchUID(uid, uid, gid)
+
+        os.umask(config.umask)
+
+        config.directory = getDirectory()
+        autoDisableMemcached(config)
+    except ConfigurationError, e:
+        usage("Unable to start: %s" % (e,))
+
+    #
+    # Start the reactor
+    #
+    reactor.callLater(0, run, parser, options, args)
+    reactor.run()
+
+def makeRecord(uid, options):
+    return AugmentRecord(
+        uid = uid,
+        enabled = True,
+        hostedAt = options.node,
+        enabledForCalendaring = options.enable_calendar,
+        enabledForAddressBooks = options.enable_addressbook,
+        autoSchedule = options.auto_schedule,
+    )
+
+ at inlineCallbacks
+def run(parser, options, args):
+    
+    try:
+        uids = []
+        if options.uid:
+            uids.append(options.uid)
+        elif options.uidfile:
+            if not os.path.exists(options.uidfile):
+                parser.error("File containing list of UIDs does not exist")
+            with open(options.uidfile) as f:
+                for line in f:
+                    uids.append(line[:-1])
+            
+        if args[0] == "add":
+            if not options.node:
+                parser.error("Partition node must be specified when adding")
+            yield augment.AugmentService.addAugmentRecords([makeRecord(uid, options) for uid in uids], False)
+            for uid in uids:
+                print "Added uid '%s' to augment database" % (uid,)
+        elif args[0] == "modify":
+            yield augment.AugmentService.addAugmentRecords([makeRecord(uid, options) for uid in uids], True)
+            for uid in uids:
+                print "Modified uid '%s' in augment database" % (uid,)
+        elif args[0] == "remove":
+            yield augment.AugmentService.removeAugmentRecords(uids)
+            for uid in uids:
+                print "Removed uid '%s' from augment database" % (uid,)
+        else:
+            parser.error("Unknown argument")
+    finally:
+        reactor.stop()
+
 if __name__ == '__main__':
     main()

Modified: CalendarServer/trunk/conf/auth/augments-default.xml
===================================================================
--- CalendarServer/trunk/conf/auth/augments-default.xml	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/conf/auth/augments-default.xml	2010-02-12 21:27:49 UTC (rev 5102)
@@ -23,5 +23,6 @@
     <uid>Default</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
 </augments>

Modified: CalendarServer/trunk/conf/auth/augments.dtd
===================================================================
--- CalendarServer/trunk/conf/auth/augments.dtd	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/conf/auth/augments.dtd	2010-02-12 21:27:49 UTC (rev 5102)
@@ -16,12 +16,13 @@
 
 <!ELEMENT augments (record*) >
 
-  <!ELEMENT record (guid, enable, hosted-at?, enable-calendar?, auto-schedule?)>
+  <!ELEMENT record (guid, enable, hosted-at?, enable-calendar?, enable-addressbook?, auto-schedule?)>
     <!ATTLIST record repeat CDATA "1">
 
-  <!ELEMENT uid               (#PCDATA)>
-  <!ELEMENT enable            (#PCDATA)>
-  <!ELEMENT hosted-at         (#PCDATA)>
-  <!ELEMENT enable-calendar   (#PCDATA)>
-  <!ELEMENT auto-schedule     (#PCDATA)>
+  <!ELEMENT uid                (#PCDATA)>
+  <!ELEMENT enable             (#PCDATA)>
+  <!ELEMENT hosted-at          (#PCDATA)>
+  <!ELEMENT enable-calendar    (#PCDATA)>
+  <!ELEMENT enable-addressbook (#PCDATA)>
+  <!ELEMENT auto-schedule      (#PCDATA)>
 >

Modified: CalendarServer/trunk/twistedcaldav/directory/augment.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/augment.py	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/augment.py	2010-02-12 21:27:49 UTC (rev 5102)
@@ -27,7 +27,7 @@
 import os
 from twistedcaldav.directory import xmlaugmentsparser
 from twistedcaldav.xmlutil import newElementTreeWithRoot, addSubElement,\
-    writeXML
+    writeXML, readXML
 
 
 log = Logger()
@@ -103,6 +103,32 @@
         
         raise NotImplementedError("Child class must define this.")
 
+    def addAugmentRecords(self, records, update=False):
+        """
+        Add an AugmentRecord to the DB.
+
+        @param record: augment records to add
+        @type record: C{list} of L{AugmentRecord}
+        @param update: C{True} if changing an existing record
+        @type update: C{bool}
+        
+        @return: L{Deferred}
+        """
+
+        raise NotImplementedError("Child class must define this.")
+
+    def removeAugmentRecords(self, uids):
+        """
+        Remove AugmentRecords with the specified UIDs.
+
+        @param uid: directory UIDs to remove
+        @type uid: C{list} of C{str}
+        
+        @return: L{Deferred}
+        """
+
+        raise NotImplementedError("Child class must define this.")
+
     def refresh(self):
         """
         Refresh any cached data.
@@ -143,6 +169,7 @@
                     addSubElement(record, xmlaugmentsparser.ELEMENT_UID, "Default")
                     addSubElement(record, xmlaugmentsparser.ELEMENT_ENABLE, "true")
                     addSubElement(record, xmlaugmentsparser.ELEMENT_ENABLECALENDAR, "true")
+                    addSubElement(record, xmlaugmentsparser.ELEMENT_ENABLEADDRESSBOOK, "true")
                     doDefault = False
                 writeXML(missedFile, root)
             
@@ -180,6 +207,115 @@
             
         return succeed(self.db.get(uid))
 
+    def addAugmentRecords(self, records, update=False):
+        """
+        Add an AugmentRecord to the DB.
+
+        @param records: augment records to add
+        @type records: C{list} of L{AugmentRecord}
+        @param update: C{True} if changing an existing record
+        @type update: C{bool}
+        
+        @return: L{Deferred}
+        """
+
+        if update:
+            # Now look at each file and modify the UIDs
+            for xmlFile in self.xmlFiles:
+                self._doModifyInFile(xmlFile, records)
+        else:
+            # Add to first file in list
+            self._doAddToFile(self.xmlFiles[0], records)
+
+    def _doAddToFile(self, xmlfile, records):
+    
+        _ignore_etree, augments_node = readXML(xmlfile)
+    
+        # Create new record
+        for record in records:
+            record_node = addSubElement(augments_node, xmlaugmentsparser.ELEMENT_RECORD)
+            addSubElement(record_node, xmlaugmentsparser.ELEMENT_UID, record.uid)
+            addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLE, "true" if record.enabled else "false")
+            addSubElement(record_node, xmlaugmentsparser.ELEMENT_HOSTEDAT, record.hostedAt)
+            addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLECALENDAR, "true" if record.enabledForCalendaring else "false")
+            addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLEADDRESSBOOK, "true" if record.enabledForAddressBooks else "false")
+            addSubElement(record_node, xmlaugmentsparser.ELEMENT_AUTOSCHEDULE, "true" if record.autoSchedule else "false")
+        
+        # Modify xmlfile
+        writeXML(xmlfile, augments_node)
+        
+    def _doModifyInFile(self, xmlfile, records):
+    
+        _ignore_etree, augments_node = readXML(xmlfile)
+    
+        # Map uid->record for fast lookup
+        recordMap = dict([(record.uid, record) for record in records])
+
+        # Make sure UID is present
+        changed = False
+        for child in augments_node.getchildren():
+            
+            if child.tag != xmlaugmentsparser.ELEMENT_RECORD:
+                continue
+    
+            uid = child.find(xmlaugmentsparser.ELEMENT_UID).text
+            if uid in recordMap:
+                # Modify record
+                record = recordMap[uid]
+                child.find(xmlaugmentsparser.ELEMENT_ENABLE).text = "true" if record.enabled else "false"
+                child.find(xmlaugmentsparser.ELEMENT_HOSTEDAT).text = record.hostedAt
+                child.find(xmlaugmentsparser.ELEMENT_ENABLECALENDAR).text = "true" if record.enabledForCalendaring else "false"
+                child.find(xmlaugmentsparser.ELEMENT_ENABLEADDRESSBOOK).text = "true" if record.enabledForAddressBooks else "false"
+                child.find(xmlaugmentsparser.ELEMENT_AUTOSCHEDULE).text = "true" if record.autoSchedule else "false"
+                changed = True
+        
+        
+        # Modify xmlfile
+        if changed:
+            writeXML(xmlfile, augments_node)
+
+    def removeAugmentRecords(self, uids):
+        """
+        Remove AugmentRecords with the specified UIDs.
+
+        @param uid: directory UID to lookup
+        @type uid: C{list} of C{str}
+        
+        @return: L{Deferred}
+        """
+
+        # Remove from cache first
+        removed = set()
+        for uid in uids:
+            if uid in self.db:
+                del self.db[uid]
+                removed.add(uid)
+
+        # Now look at each file and remove the UIDs
+        for xmlFile in self.xmlFiles:
+            self._doRemoveFromFile(xmlFile, removed)
+
+        return succeed(None)
+
+    def _doRemoveFromFile(self, xmlfile, uids):
+    
+        _ignore_etree, augments_node = readXML(xmlfile)
+    
+        # Remove all UIDs present
+        changed = False
+        for child in tuple(augments_node.getchildren()):
+            
+            if child.tag != xmlaugmentsparser.ELEMENT_RECORD:
+                continue
+
+            if child.find(xmlaugmentsparser.ELEMENT_UID).text in uids:
+                augments_node.remove(child)
+                changed = True
+        
+        # Modify xmlfile
+        if changed:
+            writeXML(xmlfile, augments_node)
+        
     def refresh(self):
         """
         Refresh any cached data.
@@ -240,58 +376,64 @@
         """
         
         # Query for the record information
-        results = (yield self.query("select UID, ENABLED, PARTITIONID, CALENDARING, AUTOSCHEDULE from AUGMENTS where UID = :1", (uid,)))
+        results = (yield self.query("select UID, ENABLED, PARTITIONID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE from AUGMENTS where UID = :1", (uid,)))
         if not results:
             returnValue(None)
         else:
-            uid, enabled, partitionid, enabdledForCalendaring, autoSchedule = results[0]
+            uid, enabled, partitionid, enabledForCalendaring, enabledForAddressBooks, autoSchedule = results[0]
             
             record = AugmentRecord(
                 uid = uid,
                 enabled = enabled == "T",
                 hostedAt = (yield self._getPartition(partitionid)),
-                enabledForCalendaring = enabdledForCalendaring == "T",
+                enabledForCalendaring = enabledForCalendaring == "T",
+                enabledForAddressBooks = enabledForAddressBooks == "T",
                 autoSchedule = autoSchedule == "T",
             )
             
             returnValue(record)
 
     @inlineCallbacks
-    def addAugmentRecord(self, record, update=False):
+    def addAugmentRecords(self, records, update=False):
 
-        partitionid = (yield self._getPartitionID(record.hostedAt))
-        
-        if update:
-            yield self.execute(
-                """update AUGMENTS set
-                (UID, ENABLED, PARTITIONID, CALENDARING, AUTOSCHEDULE) =
-                (:1, :2, :3, :4, :5) where UID = :6""",
-                (
-                    record.uid,
-                    "T" if record.enabled else "F",
-                    partitionid,
-                    "T" if record.enabledForCalendaring else "F",
-                    "T" if record.autoSchedule else "F",
-                    record.uid,
+        for record in records:
+            partitionid = (yield self._getPartitionID(record.hostedAt))
+            
+            if update:
+                yield self.execute(
+                    """update AUGMENTS set
+                    (UID, ENABLED, PARTITIONID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE) =
+                    (:1, :2, :3, :4, :5, :6) where UID = :7""",
+                    (
+                        record.uid,
+                        "T" if record.enabled else "F",
+                        partitionid,
+                        "T" if record.enabledForCalendaring else "F",
+                        "T" if record.enabledForAddressBooks else "F",
+                        "T" if record.autoSchedule else "F",
+                        record.uid,
+                    )
                 )
-            )
-        else:
-            yield self.execute(
-                """insert into AUGMENTS
-                (UID, ENABLED, PARTITIONID, CALENDARING, AUTOSCHEDULE)
-                values (:1, :2, :3, :4, :5)""",
-                (
-                    record.uid,
-                    "T" if record.enabled else "F",
-                    partitionid,
-                    "T" if record.enabledForCalendaring else "F",
-                    "T" if record.autoSchedule else "F",
+            else:
+                yield self.execute(
+                    """insert into AUGMENTS
+                    (UID, ENABLED, PARTITIONID, CALENDARING, ADDRESSBOOKS, AUTOSCHEDULE)
+                    values (:1, :2, :3, :4, :5, :6)""",
+                    (
+                        record.uid,
+                        "T" if record.enabled else "F",
+                        partitionid,
+                        "T" if record.enabledForCalendaring else "F",
+                        "T" if record.enabledForAddressBooks else "F",
+                        "T" if record.autoSchedule else "F",
+                    )
                 )
-            )
 
-    def removeAugmentRecord(self, uid):
+    @inlineCallbacks
+    def removeAugmentRecords(self, uids):
 
-        return self.query("delete from AUGMENTS where UID = :1", (uid,))
+        for uid in uids:
+            yield self.execute("delete from AUGMENTS where UID = :1", (uid,))
 
     @inlineCallbacks
     def _getPartitionID(self, hostedat, createIfMissing=True):
@@ -341,20 +483,29 @@
         """
 
         #
-        # TESTTYPE table
+        # AUGMENTS table
         #
-        yield self._create_table("AUGMENTS", (
-            ("UID",          "text unique"),
-            ("ENABLED",      "text(1)"),
-            ("PARTITIONID",  "text"),
-            ("CALENDARING",  "text(1)"),
-            ("AUTOSCHEDULE", "text(1)"),
-        ))
+        yield self._create_table(
+            "AUGMENTS",
+            (
+                ("UID",          "text unique"),
+                ("ENABLED",      "text(1)"),
+                ("PARTITIONID",  "text"),
+                ("CALENDARING",  "text(1)"),
+                ("ADDRESSBOOKS", "text(1)"),
+                ("AUTOSCHEDULE", "text(1)"),
+            ),
+            ifnotexists=True,
+        )
 
-        yield self._create_table("PARTITIONS", (
-            ("PARTITIONID",   "serial"),
-            ("HOSTEDAT",      "text"),
-        ))
+        yield self._create_table(
+            "PARTITIONS",
+            (
+                ("PARTITIONID",   "serial"),
+                ("HOSTEDAT",      "text"),
+            ),
+            ifnotexists=True,
+        )
 
     @inlineCallbacks
     def _db_empty_data_tables(self):

Modified: CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/test/augments-test-default.xml	2010-02-12 21:27:49 UTC (rev 5102)
@@ -23,6 +23,7 @@
     <uid>Default</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
     <hosted-at>00001</hosted-at>
   </record>
   <record>
@@ -33,6 +34,7 @@
     <uid>6423F94A-6B76-4A3A-815B-D52CFD77935D</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>5A985493-EE2C-4665-94CF-4DFEA3A89500</uid>
@@ -42,6 +44,7 @@
     <uid>8B4288F6-CC82-491D-8EF9-642EF4F3E7D0</uid>
     <enable>true</enable>
     <enable-calendar>false</enable-calendar>
+    <enable-addressbook>false</enable-addressbook>
   </record>
   <record>
     <uid>5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1</uid>
@@ -59,6 +62,7 @@
     <hosted-at>00002</hosted-at>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
     <auto-schedule>true</auto-schedule>
   </record>
 </augments>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/augments-test.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/augments-test.xml	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/test/augments-test.xml	2010-02-12 21:27:49 UTC (rev 5102)
@@ -27,6 +27,7 @@
     <uid>6423F94A-6B76-4A3A-815B-D52CFD77935D</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>5A985493-EE2C-4665-94CF-4DFEA3A89500</uid>
@@ -36,6 +37,7 @@
     <uid>8B4288F6-CC82-491D-8EF9-642EF4F3E7D0</uid>
     <enable>true</enable>
     <enable-calendar>false</enable-calendar>
+    <enable-addressbook>false</enable-addressbook>
   </record>
   <record>
     <uid>5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1</uid>
@@ -53,6 +55,7 @@
     <hosted-at>00002</hosted-at>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
     <auto-schedule>true</auto-schedule>
   </record>
 </augments>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/augments.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/augments.xml	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/test/augments.xml	2010-02-12 21:27:49 UTC (rev 5102)
@@ -23,36 +23,43 @@
     <uid>D11F03A0-97EA-48AF-9A6C-FAC7F3975766</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>6423F94A-6B76-4A3A-815B-D52CFD77935D</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>5A985493-EE2C-4665-94CF-4DFEA3A89500</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>8B4288F6-CC82-491D-8EF9-642EF4F3E7D0</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>543D28BA-F74F-4D5F-9243-B3E3A61171E5</uid>
     <enable>true</enable>
     <enable-calendar>false</enable-calendar>
+    <enable-addressbook>false</enable-addressbook>
   </record>
   <record repeat="2">
     <uid>user%02d</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1</uid>
@@ -94,35 +101,42 @@
     <uid>mercury</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>gemini</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>apollo</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>orion</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>transporter</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>ftlcpu</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>non_calendar_proxy</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
 </augments>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/modify/augments.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/modify/augments.xml	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/test/modify/augments.xml	2010-02-12 21:27:49 UTC (rev 5102)
@@ -23,10 +23,12 @@
     <uid>user01</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>user02</uid>
     <enable>false</enable>
     <enable-calendar>false</enable-calendar>
+    <enable-addressbook>false</enable-addressbook>
   </record>
 </augments>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/resources/augments.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/resources/augments.xml	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/test/resources/augments.xml	2010-02-12 21:27:49 UTC (rev 5102)
@@ -23,22 +23,26 @@
     <uid>user01</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
   </record>
   <record>
     <uid>user02</uid>
     <enable>false</enable>
     <enable-calendar>false</enable-calendar>
+    <enable-addressbook>false</enable-addressbook>
   </record>
   <record>
     <uid>resource01</uid>
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
+    <enable-addressbook>true</enable-addressbook>
     <auto-schedule>true</auto-schedule>
   </record>
   <record>
     <uid>resource02</uid>
     <enable>false</enable>
     <enable-calendar>false</enable-calendar>
+    <enable-addressbook>false</enable-addressbook>
     <auto-schedule>false</auto-schedule>
   </record>
 </augments>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_augment.py	2010-02-12 21:27:49 UTC (rev 5102)
@@ -26,16 +26,16 @@
 xmlFileDefault = os.path.join(os.path.dirname(__file__), "augments-test-default.xml")
 
 testRecords = (
-    {"uid":"D11F03A0-97EA-48AF-9A6C-FAC7F3975766", "enabled":True,  "hostedAt":"", "enabledForCalendaring":False, "autoSchedule":False},
-    {"uid":"6423F94A-6B76-4A3A-815B-D52CFD77935D", "enabled":True,  "hostedAt":"", "enabledForCalendaring":True, "autoSchedule":False},
-    {"uid":"5A985493-EE2C-4665-94CF-4DFEA3A89500", "enabled":False, "hostedAt":"", "enabledForCalendaring":False, "autoSchedule":False},
-    {"uid":"8B4288F6-CC82-491D-8EF9-642EF4F3E7D0", "enabled":True,  "hostedAt":"", "enabledForCalendaring":False, "autoSchedule":False},
-    {"uid":"5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1", "enabled":True,  "hostedAt":"00001", "enabledForCalendaring":False, "autoSchedule":False},
-    {"uid":"543D28BA-F74F-4D5F-9243-B3E3A61171E5", "enabled":True,  "hostedAt":"00002", "enabledForCalendaring":False, "autoSchedule":False},
-    {"uid":"6A73326A-F781-47E7-A9F8-AF47364D4152", "enabled":True,  "hostedAt":"00002", "enabledForCalendaring":True, "autoSchedule":True},
+    {"uid":"D11F03A0-97EA-48AF-9A6C-FAC7F3975766", "enabled":True,  "hostedAt":"", "enabledForCalendaring":False, "enabledForAddressBooks":False, "autoSchedule":False},
+    {"uid":"6423F94A-6B76-4A3A-815B-D52CFD77935D", "enabled":True,  "hostedAt":"", "enabledForCalendaring":True, "enabledForAddressBooks":True, "autoSchedule":False},
+    {"uid":"5A985493-EE2C-4665-94CF-4DFEA3A89500", "enabled":False, "hostedAt":"", "enabledForCalendaring":False, "enabledForAddressBooks":False, "autoSchedule":False},
+    {"uid":"8B4288F6-CC82-491D-8EF9-642EF4F3E7D0", "enabled":True,  "hostedAt":"", "enabledForCalendaring":False, "enabledForAddressBooks":False, "autoSchedule":False},
+    {"uid":"5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1", "enabled":True,  "hostedAt":"00001", "enabledForCalendaring":False, "enabledForAddressBooks":False, "autoSchedule":False},
+    {"uid":"543D28BA-F74F-4D5F-9243-B3E3A61171E5", "enabled":True,  "hostedAt":"00002", "enabledForCalendaring":False, "enabledForAddressBooks":False, "autoSchedule":False},
+    {"uid":"6A73326A-F781-47E7-A9F8-AF47364D4152", "enabled":True,  "hostedAt":"00002", "enabledForCalendaring":True, "enabledForAddressBooks":True, "autoSchedule":True},
 )
 
-testRecordDefault = {"uid":"A4318887-F2C7-4A70-9056-B88CC8DB26F1", "enabled":True,  "hostedAt":"00001", "enabledForCalendaring":True, "autoSchedule":False}
+testRecordDefault = {"uid":"A4318887-F2C7-4A70-9056-B88CC8DB26F1", "enabled":True,  "hostedAt":"00001", "enabledForCalendaring":True, "enabledForAddressBooks":True, "autoSchedule":False}
 
 class AugmentTests(TestCase):
 
@@ -113,8 +113,7 @@
         db = AugmentSqliteDB(self.mktemp())
 
         dbxml = AugmentXMLDB((xmlFile,))
-        for record in dbxml.db.values():
-            yield db.addAugmentRecord(record)
+        yield db.addAugmentRecords(dbxml.db.values())
 
         for item in testRecords:
             yield self._checkRecord(db, item)
@@ -127,8 +126,7 @@
         db = AugmentSqliteDB(self.mktemp())
 
         dbxml = AugmentXMLDB((xmlFileDefault,))
-        for record in dbxml.db.values():
-            yield db.addAugmentRecord(record)
+        yield db.addAugmentRecords(dbxml.db.values())
 
         for item in testRecords:
             yield self._checkRecord(db, item)
@@ -144,8 +142,7 @@
         yield db.clean()
 
         dbxml = AugmentXMLDB((xmlFile,))
-        for record in dbxml.db.values():
-            yield db.addAugmentRecord(record)
+        yield db.addAugmentRecords(dbxml.db.values())
 
         for item in testRecords:
             yield self._checkRecord(db, item)
@@ -159,8 +156,7 @@
         yield db.clean()
 
         dbxml = AugmentXMLDB((xmlFileDefault,))
-        for record in dbxml.db.values():
-            yield db.addAugmentRecord(record)
+        yield db.addAugmentRecords(dbxml.db.values())
 
         for item in testRecords:
             yield self._checkRecord(db, item)

Modified: CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py	2010-02-12 21:26:48 UTC (rev 5101)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlaugmentsparser.py	2010-02-12 21:27:49 UTC (rev 5102)
@@ -36,8 +36,8 @@
 ELEMENT_UID               = "uid"
 ELEMENT_ENABLE            = "enable"
 ELEMENT_HOSTEDAT          = "hosted-at"
+ELEMENT_ENABLECALENDAR    = "enable-calendar"
 ELEMENT_ENABLEADDRESSBOOK = "enable-addressbook"
-ELEMENT_ENABLECALENDAR    = "enable-calendar"
 ELEMENT_AUTOSCHEDULE      = "auto-schedule"
 
 ATTRIBUTE_REPEAT          = "repeat"
@@ -102,8 +102,8 @@
                 elif node.tag in (
                     ELEMENT_ENABLE,
                     ELEMENT_ENABLECALENDAR,
+                    ELEMENT_ENABLEADDRESSBOOK,
                     ELEMENT_AUTOSCHEDULE,
-                    ELEMENT_ENABLEADDRESSBOOK
                 ):
                     fields[node.tag] = node.text == VALUE_TRUE
                 else:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100212/1c383e50/attachment-0001.html>


More information about the calendarserver-changes mailing list