[CalendarServer-changes] [4083] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Apr 24 12:16:04 PDT 2009


Revision: 4083
          http://trac.macosforge.org/projects/calendarserver/changeset/4083
Author:   sagen at apple.com
Date:     2009-04-24 12:16:04 -0700 (Fri, 24 Apr 2009)
Log Message:
-----------
Moving the resource info database into the directory package

Modified Paths:
--------------
    CalendarServer/trunk/setup.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py
    CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
    CalendarServer/trunk/twistedcaldav/resource.py
    CalendarServer/trunk/twistedcaldav/test/test_upgrade.py

Added Paths:
-----------
    CalendarServer/trunk/twistedcaldav/directory/resourceinfo.py

Modified: CalendarServer/trunk/setup.py
===================================================================
--- CalendarServer/trunk/setup.py	2009-04-24 19:15:02 UTC (rev 4082)
+++ CalendarServer/trunk/setup.py	2009-04-24 19:16:04 UTC (rev 4083)
@@ -105,7 +105,7 @@
                            "images/*/*.jpg",
                          ],
                        },
-    scripts          = [ "bin/caldavd", "bin/caladmin", "bin/caldav_export" ],
+    scripts          = [ "bin/caldavd", "bin/caladmin", "bin/caldav_export", "bin/caldav_utility" ],
     data_files       = [ ("caldavd", ["conf/caldavd.plist"]) ],
     ext_modules      = extensions,
     py_modules       = ["kqreactor", "memcacheclient"],

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2009-04-24 19:15:02 UTC (rev 4082)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2009-04-24 19:16:04 UTC (rev 4083)
@@ -50,6 +50,7 @@
 from twistedcaldav.cache import DisabledCacheNotifier, PropfindCacheMixin
 
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
+from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyPrincipalResource
 from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
 from twistedcaldav.directory.util import NotFilePath
@@ -750,7 +751,33 @@
     def principalUID(self):
         return self.record.uid
 
+
     ##
+    # Extra resource info
+    ##
+
+    def setAutoSchedule(self, autoSchedule):
+        self._resource_info_index().setAutoSchedule(self.record.guid, autoSchedule)
+
+    def getAutoSchedule(self):
+        return self._resource_info_index().getAutoSchedule(self.record.guid)
+
+
+    def _resource_info_index(self):
+        """
+        Return the resource info SQL database for this calendar principal.
+
+        @return: the L{ResourceInfoDatabase} for the calendar principal.
+        """
+
+        # The db is located in the data root
+        self.pcollection = self.parent.parent
+        if not hasattr(self.pcollection, "resource_info_db"):
+            setattr(self.pcollection, "resource_info_db", ResourceInfoDatabase(config.DataRoot))
+        return self.pcollection.resource_info_db
+
+
+    ##
     # Static
     ##
 

Added: CalendarServer/trunk/twistedcaldav/directory/resourceinfo.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/resourceinfo.py	                        (rev 0)
+++ CalendarServer/trunk/twistedcaldav/directory/resourceinfo.py	2009-04-24 19:16:04 UTC (rev 4083)
@@ -0,0 +1,171 @@
+##
+# Copyright (c) 2005-2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Database for storing extra resource information, such as auto-schedule
+"""
+
+__all__ = [
+    "ResourceInfoDatabase",
+]
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twistedcaldav.log import LoggingMixIn
+from twistedcaldav.memcacher import Memcacher
+from twistedcaldav.sql import AbstractSQLDatabase, db_prefix
+import os
+
+class ResourceInfoDatabase(AbstractSQLDatabase, LoggingMixIn):
+    """
+    A database to maintain resource (and location) information
+
+    SCHEMA:
+
+    Group Database:
+
+    ROW: GUID, AUTOSCHEDULE
+
+    """
+
+    dbType = "RESOURCEINFO"
+    dbFilename = "resourceinfo.sqlite"
+    dbOldFilename = db_prefix + "resourceinfo"
+    dbFormatVersion = "1"
+
+    class ResourceInfoDBMemcacher(Memcacher):
+
+        def setAutoSchedule(self, guid, autoSchedule):
+            return self.set("resourceinfo:%s" % (str(guid),), "1" if autoSchedule else "0")
+
+        @inlineCallbacks
+        def getAutoSchedule(self, guid):
+            result = (yield self.get("resourceinfo:%s" % (str(guid),)))
+            if result is not None:
+                autoSchedule = result == "1"
+            else:
+                autoSchedule = None
+            returnValue(autoSchedule)
+
+    def __init__(self, path):
+        path = os.path.join(path, ResourceInfoDatabase.dbFilename)
+        super(ResourceInfoDatabase, self).__init__(path, True)
+
+        self._memcacher = ResourceInfoDatabase.ResourceInfoDBMemcacher("resourceInfoDB")
+
+    @inlineCallbacks
+    def setAutoSchedule(self, guid, autoSchedule):
+        """
+        Set a resource/location's auto-Schedule boolean.
+
+        @param guid: the UID of the group principal to add.
+        @param autoSchedule: boolean
+        """
+        self.setAutoScheduleInDatabase(guid, autoSchedule)
+
+        # Update cache
+        _ignore = (yield self._memcacher.setAutoSchedule(guid, autoSchedule))
+
+    def setAutoScheduleInDatabase(self, guid, autoSchedule):
+        """
+        A blocking call to set a resource/location's auto-Schedule boolean
+        value in the database.
+
+        @param guid: the UID of the group principal to add.
+        @param autoSchedule: boolean
+        """
+        # Remove what is there, then add it back.
+        self._delete_from_db(guid)
+        self._add_to_db(guid, autoSchedule)
+        self._db_commit()
+
+    @inlineCallbacks
+    def getAutoSchedule(self, guid):
+        """
+        Return the auto-Schedule state for the resource/location specified by guid
+        """
+
+        # Pull from cache
+        autoSchedule = (yield self._memcacher.getAutoSchedule(guid))
+        if autoSchedule is None:
+            # Not in memcache, check local db
+            autoSchedule = self._db_value_for_sql("select AUTOSCHEDULE from RESOURCEINFO where GUID = :1", guid)
+            if autoSchedule is not None:
+                autoSchedule = autoSchedule == 1
+                result = (yield self._memcacher.setAutoSchedule(guid, autoSchedule))
+            else:
+                # Not in local db
+                # Default to False
+                autoSchedule = False
+
+        returnValue(autoSchedule)
+
+    def _add_to_db(self, guid, autoSchedule):
+        """
+        Insert the specified entry into the database.
+
+        @param guid: the guid of the resource/location
+        @param autoSchedule: a boolean
+        """
+        self._db_execute(
+            """
+            insert into RESOURCEINFO (GUID, AUTOSCHEDULE)
+            values (:1, :2)
+            """, guid, 1 if autoSchedule else 0
+        )
+
+    def _delete_from_db(self, guid):
+        """
+        Deletes the specified entry from the database.
+
+        @param guid: the guid of the resource/location to delete
+        """
+        self._db_execute("delete from RESOURCEINFO where GUID = :1", guid)
+
+    def _db_version(self):
+        """
+        @return: the schema version assigned to this index.
+        """
+        return ResourceInfoDatabase.dbFormatVersion
+
+    def _db_type(self):
+        """
+        @return: the collection type assigned to this index.
+        """
+        return ResourceInfoDatabase.dbType
+
+    def _db_init_data_tables(self, q):
+        """
+        Initialise the underlying database tables.
+        @param q:           a database cursor to use.
+        """
+
+        #
+        # RESOURCEINFO table
+        #
+        q.execute(
+            """
+            create table RESOURCEINFO (
+                GUID            text,
+                AUTOSCHEDULE    integer
+            )
+            """
+        )
+        q.execute(
+            """
+            create index RESOURCEGUIDS on RESOURCEINFO (GUID)
+            """
+        )
+

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py	2009-04-24 19:15:02 UTC (rev 4082)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py	2009-04-24 19:16:04 UTC (rev 4083)
@@ -23,7 +23,7 @@
 from twistedcaldav.directory.directory import DirectoryService
 import twistedcaldav.directory.test.util
 from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.resource import ResourceInfoDatabase
+from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
 from twistedcaldav.config import config
 
 xmlFile = FilePath(os.path.join(os.path.dirname(__file__), "accounts.xml"))

Modified: CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py	2009-04-24 19:15:02 UTC (rev 4082)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py	2009-04-24 19:16:04 UTC (rev 4083)
@@ -31,7 +31,7 @@
 from twistedcaldav.config import config
 from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.log import Logger
-from twistedcaldav.resource import ResourceInfoDatabase
+from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
 
 log = Logger()

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2009-04-24 19:15:02 UTC (rev 4082)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2009-04-24 19:16:04 UTC (rev 4083)
@@ -1006,39 +1006,7 @@
         """
         return None
 
-    def setAutoSchedule(self, autoSchedule):
-        self._resource_info_index().setAutoSchedule(self.record.guid, autoSchedule)
 
-    def getAutoSchedule(self):
-        return self._resource_info_index().getAutoSchedule(self.record.guid)
-
-    def _resource_info_index(self):
-        """
-        Return the resource info SQL database for this calendar principal.
-
-        @return: the L{ResourceInfoDatabase} for the calendar principal.
-        """
-
-        # The db is located in the data root
-        self.pcollection = self.parent.parent # MOR: doesn't feel right
-        if not hasattr(self.pcollection, "resource_info_db"):
-            setattr(self.pcollection, "resource_info_db", ResourceInfoDatabase(config.DataRoot))
-        return self.pcollection.resource_info_db
-
-    def _calendar_user_proxy_index(self):
-        """
-        Return the calendar user proxy SQL database for this calendar principal.
-
-        @return: the L{CalendarUserProxyDatabase} for the calendar principal.
-        """
-
-        # The db is located in the data root
-        self.pcollection = self.parent.parent # MOR: doesn't feel right
-        if not hasattr(self.pcollection, "calendar_user_proxy_db"):
-            setattr(self.pcollection, "calendar_user_proxy_db", CalendarUserProxyDatabase(config.DataRoot))
-        return self.pcollection.calendar_user_proxy_db
-
-
 ##
 # Utilities
 ##
@@ -1060,144 +1028,3 @@
         return resource.isPseudoCalendarCollection()
 
 
-class ResourceInfoDatabase(AbstractSQLDatabase, LoggingMixIn):
-    """
-    A database to maintain resource (and location) information
-
-    SCHEMA:
-
-    Group Database:
-
-    ROW: GUID, AUTOSCHEDULE
-
-    """
-
-    dbType = "RESOURCEINFO"
-    dbFilename = "resourceinfo.sqlite"
-    dbOldFilename = db_prefix + "resourceinfo"
-    dbFormatVersion = "1"
-
-    class ResourceInfoDBMemcacher(Memcacher):
-
-        def setAutoSchedule(self, guid, autoSchedule):
-            return self.set("resourceinfo:%s" % (str(guid),), "1" if autoSchedule else "0")
-
-        @inlineCallbacks
-        def getAutoSchedule(self, guid):
-            result = (yield self.get("resourceinfo:%s" % (str(guid),)))
-            if result is not None:
-                autoSchedule = result == "1"
-            else:
-                autoSchedule = None
-            returnValue(autoSchedule)
-
-    def __init__(self, path):
-        path = os.path.join(path, ResourceInfoDatabase.dbFilename)
-        super(ResourceInfoDatabase, self).__init__(path, True)
-
-        self._memcacher = ResourceInfoDatabase.ResourceInfoDBMemcacher("resourceInfoDB")
-
-    @inlineCallbacks
-    def setAutoSchedule(self, guid, autoSchedule):
-        """
-        Set a resource/location's auto-Schedule boolean.
-
-        @param guid: the UID of the group principal to add.
-        @param autoSchedule: boolean
-        """
-        self.setAutoScheduleInDatabase(guid, autoSchedule)
-
-        # Update cache
-        _ignore = (yield self._memcacher.setAutoSchedule(guid, autoSchedule))
-
-    def setAutoScheduleInDatabase(self, guid, autoSchedule):
-        """
-        A blocking call to set a resource/location's auto-Schedule boolean
-        value in the database.
-
-        @param guid: the UID of the group principal to add.
-        @param autoSchedule: boolean
-        """
-        # Remove what is there, then add it back.
-        self._delete_from_db(guid)
-        self._add_to_db(guid, autoSchedule)
-        self._db_commit()
-
-    @inlineCallbacks
-    def getAutoSchedule(self, guid):
-        """
-        Return the auto-Schedule state for the resource/location specified by guid
-        """
-
-        # Pull from cache
-        autoSchedule = (yield self._memcacher.getAutoSchedule(guid))
-        if autoSchedule is None:
-            # Not in memcache, check local db
-            autoSchedule = self._db_value_for_sql("select AUTOSCHEDULE from RESOURCEINFO where GUID = :1", guid)
-            if autoSchedule is not None:
-                autoSchedule = autoSchedule == 1
-                result = (yield self._memcacher.setAutoSchedule(guid, autoSchedule))
-            else:
-                # Not in local db
-                # Default to False
-                autoSchedule = False
-
-        returnValue(autoSchedule)
-
-    def _add_to_db(self, guid, autoSchedule):
-        """
-        Insert the specified entry into the database.
-
-        @param guid: the guid of the resource/location
-        @param autoSchedule: a boolean
-        """
-        self._db_execute(
-            """
-            insert into RESOURCEINFO (GUID, AUTOSCHEDULE)
-            values (:1, :2)
-            """, guid, 1 if autoSchedule else 0
-        )
-
-    def _delete_from_db(self, guid):
-        """
-        Deletes the specified entry from the database.
-
-        @param guid: the guid of the resource/location to delete
-        """
-        self._db_execute("delete from RESOURCEINFO where GUID = :1", guid)
-
-    def _db_version(self):
-        """
-        @return: the schema version assigned to this index.
-        """
-        return ResourceInfoDatabase.dbFormatVersion
-
-    def _db_type(self):
-        """
-        @return: the collection type assigned to this index.
-        """
-        return ResourceInfoDatabase.dbType
-
-    def _db_init_data_tables(self, q):
-        """
-        Initialise the underlying database tables.
-        @param q:           a database cursor to use.
-        """
-
-        #
-        # RESOURCEINFO table
-        #
-        q.execute(
-            """
-            create table RESOURCEINFO (
-                GUID            text,
-                AUTOSCHEDULE    integer
-            )
-            """
-        )
-        q.execute(
-            """
-            create index RESOURCEGUIDS on RESOURCEINFO (GUID)
-            """
-        )
-

Modified: CalendarServer/trunk/twistedcaldav/test/test_upgrade.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_upgrade.py	2009-04-24 19:15:02 UTC (rev 4082)
+++ CalendarServer/trunk/twistedcaldav/test/test_upgrade.py	2009-04-24 19:16:04 UTC (rev 4083)
@@ -16,7 +16,7 @@
 
 from twistedcaldav.config import config
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
-from twistedcaldav.resource import ResourceInfoDatabase
+from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
 from twistedcaldav.upgrade import UpgradeError, upgradeData, updateFreeBusySet
 from twistedcaldav.test.util import TestCase
 from calendarserver.tools.util import getDirectory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090424/9290d869/attachment-0001.html>


More information about the calendarserver-changes mailing list