[CalendarServer-changes] [922] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jan 4 17:42:07 PST 2007
Revision: 922
http://trac.macosforge.org/projects/calendarserver/changeset/922
Author: wsanchez at apple.com
Date: 2007-01-04 17:42:07 -0800 (Thu, 04 Jan 2007)
Log Message:
-----------
Add location resource type to XML service
Modified Paths:
--------------
CalendarServer/trunk/conf/accounts-test.xml
CalendarServer/trunk/conf/accounts.dtd
CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml
CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py
CalendarServer/trunk/twistedcaldav/directory/test/util.py
CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
Modified: CalendarServer/trunk/conf/accounts-test.xml
===================================================================
--- CalendarServer/trunk/conf/accounts-test.xml 2007-01-05 01:13:07 UTC (rev 921)
+++ CalendarServer/trunk/conf/accounts-test.xml 2007-01-05 01:42:07 UTC (rev 922)
@@ -42,9 +42,14 @@
<name>Public %02d</name>
<cuaddr>mailto:public%02d at example.com</cuaddr>
</user>
+ <location repeat="10">
+ <uid>location%02d</uid>
+ <password>location%02d</password>
+ <name>Room %02d</name>
+ </location>
<resource repeat="10">
<uid>resource%02d</uid>
<password>resource%02d</password>
- <name>Room %02d</name>
+ <name>Resource %02d</name>
</resource>
</accounts>
Modified: CalendarServer/trunk/conf/accounts.dtd
===================================================================
--- CalendarServer/trunk/conf/accounts.dtd 2007-01-05 01:13:07 UTC (rev 921)
+++ CalendarServer/trunk/conf/accounts.dtd 2007-01-05 01:42:07 UTC (rev 922)
@@ -28,6 +28,9 @@
<!ELEMENT resource (uid, password, name, cuaddr*, calendar*, quota?, autorespond?, canproxy?)>
<!ATTLIST resource repeat CDATA "1">
+ <!ELEMENT location (uid, password, name, cuaddr*, calendar*, quota?, autorespond?, canproxy?)>
+ <!ATTLIST location repeat CDATA "1">
+
<!ELEMENT member (#PCDATA)>
<!ATTLIST member type (user|group|resource) "user">
Modified: CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml 2007-01-05 01:13:07 UTC (rev 921)
+++ CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml 2007-01-05 01:42:07 UTC (rev 922)
@@ -112,22 +112,34 @@
<member type="group">left_coast</member>
</members>
</group>
- <resource>
+ <location>
<uid>mercury</uid>
<password>mercury</password>
<name>Mecury Seven</name>
<cuaddr>mailto:mercury at example.com</cuaddr>
- </resource>
- <resource>
+ </location>
+ <location>
<uid>gemini</uid>
<password>gemini</password>
<name>Gemini Twelve</name>
<cuaddr>mailto:gemini at example.com</cuaddr>
- </resource>
- <resource>
+ </location>
+ <location>
<uid>apollo</uid>
<password>apollo</password>
<name>Apollo Eleven</name>
<cuaddr>mailto:apollo at example.com</cuaddr>
+ </location>
+ <resource>
+ <uid>transporter</uid>
+ <password>transporter</password>
+ <name>Mass Transporter</name>
+ <cuaddr>mailto:transporter at example.com</cuaddr>
</resource>
+ <resource>
+ <uid>ftlcpu</uid>
+ <password>ftlcpu</password>
+ <name>Faster-Than-Light Microprocessor</name>
+ <cuaddr>mailto:ftlcpu at example.com</cuaddr>
+ </resource>
</accounts>
Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py 2007-01-05 01:13:07 UTC (rev 921)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py 2007-01-05 01:42:07 UTC (rev 922)
@@ -28,15 +28,15 @@
# FIXME: Add tests for GUID hooey, once we figure out what that means here
class XMLFileBase(object):
- recordTypes = set(("user", "group", "resource"))
+ recordTypes = set(("user", "group", "location", "resource"))
users = {
"admin" : { "password": "nimda", "guid": None, "addresses": () },
"proxy" : { "password": "yxorp", "guid": None, "addresses": () },
"wsanchez": { "password": "zehcnasw", "guid": None, "addresses": ("mailto:wsanchez at example.com",) },
- "cdaboo" : { "password": "oobadc", "guid": None, "addresses": ("mailto:cdaboo at example.com",) },
- "lecroy" : { "password": "yorcel", "guid": None, "addresses": ("mailto:lecroy at example.com",) },
- "dreid" : { "password": "dierd", "guid": None, "addresses": ("mailto:dreid at example.com",) },
+ "cdaboo" : { "password": "oobadc", "guid": None, "addresses": ("mailto:cdaboo at example.com",) },
+ "lecroy" : { "password": "yorcel", "guid": None, "addresses": ("mailto:lecroy at example.com",) },
+ "dreid" : { "password": "dierd", "guid": None, "addresses": ("mailto:dreid at example.com",) },
"user01" : { "password": "01user", "guid": None, "addresses": () },
"user02" : { "password": "02user", "guid": None, "addresses": () },
}
@@ -50,12 +50,17 @@
"both_coasts": { "password": "both_coasts", "guid": None, "addresses": (), "members": (("group", "right_coast"), ("group", "left_coast")) },
}
- resources = {
+ locations = {
"mercury": { "password": "mercury", "guid": None, "addresses": ("mailto:mercury at example.com",) },
- "gemini" : { "password": "gemini", "guid": None, "addresses": ("mailto:gemini at example.com",) },
- "apollo" : { "password": "apollo", "guid": None, "addresses": ("mailto:apollo at example.com",) },
+ "gemini" : { "password": "gemini", "guid": None, "addresses": ("mailto:gemini at example.com",) },
+ "apollo" : { "password": "apollo", "guid": None, "addresses": ("mailto:apollo at example.com",) },
}
+ resources = {
+ "transporter": { "password": "transporter", "guid": None, "addresses": ("mailto:transporter at example.com",) },
+ "ftlcpu" : { "password": "ftlcpu", "guid": None, "addresses": ("mailto:ftlcpu at example.com",) },
+ }
+
def xmlFile(self):
if not hasattr(self, "_xmlFile"):
self._xmlFile = FilePath(self.mktemp())
Modified: CalendarServer/trunk/twistedcaldav/directory/test/util.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/util.py 2007-01-05 01:13:07 UTC (rev 921)
+++ CalendarServer/trunk/twistedcaldav/directory/test/util.py 2007-01-05 01:42:07 UTC (rev 922)
@@ -84,6 +84,15 @@
self.assertEquals(self.recordNames("group"), set(self.groups.keys()))
+ def test_listRecords_locations(self):
+ """
+ IDirectoryService.listRecords("locations")
+ """
+ if not self.resources:
+ raise SkipTest("No locations")
+
+ self.assertEquals(self.recordNames("location"), set(self.locations.keys()))
+
def test_listRecords_resources(self):
"""
IDirectoryService.listRecords("resources")
@@ -100,6 +109,7 @@
for recordType, data in (
( "user" , self.users ),
( "group" , self.groups ),
+ ( "location", self.locations ),
( "resource", self.resources ),
):
if not data:
Modified: CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py 2007-01-05 01:13:07 UTC (rev 921)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py 2007-01-05 01:42:07 UTC (rev 922)
@@ -34,6 +34,7 @@
ELEMENT_ACCOUNTS = "accounts"
ELEMENT_USER = "user"
ELEMENT_GROUP = "group"
+ELEMENT_LOCATION = "location"
ELEMENT_RESOURCE = "resource"
ELEMENT_SHORTNAME = "uid"
@@ -48,6 +49,13 @@
ATTRIBUTE_REPEAT = "repeat"
ATTRIBUTE_RECORDTYPE = "type"
+RECORD_TYPES = {
+ ELEMENT_USER : "user",
+ ELEMENT_GROUP : "group",
+ ELEMENT_RESOURCE : "resource",
+ ELEMENT_LOCATION : "location",
+}
+
class XMLAccountsParser(object):
"""
XML account configuration file parser.
@@ -61,7 +69,10 @@
self.xmlFile = xmlFile
self.realm = None
- self.items = {"user": {}, "group": {}, "resource": {}}
+ self.items = {}
+
+ for recordType in RECORD_TYPES.values():
+ self.items[recordType] = {}
# Read in XML
fd = open(self.xmlFile.path, "r")
@@ -91,29 +102,31 @@
item.groups.add(group.shortName)
for child in node._get_childNodes():
- if child._get_localName() in (ELEMENT_USER, ELEMENT_GROUP, ELEMENT_RESOURCE):
- if child.hasAttribute(ATTRIBUTE_REPEAT):
- repeat = int(child.getAttribute(ATTRIBUTE_REPEAT))
- else:
- repeat = 1
+ child_name = child._get_localName()
+ if child_name is None:
+ continue
- recordType = {
- ELEMENT_USER: "user",
- ELEMENT_GROUP: "group",
- ELEMENT_RESOURCE:"resource",
- }[child._get_localName()]
-
- principal = XMLAccountRecord(recordType)
- principal.parseXML(child)
- if repeat > 1:
- for i in xrange(1, repeat+1):
- newprincipal = principal.repeat(i)
- self.items[recordType][newprincipal.shortName] = newprincipal
- updateMembership(newprincipal)
- else:
- self.items[recordType][principal.shortName] = principal
- updateMembership(principal)
-
+ try:
+ recordType = RECORD_TYPES[child_name]
+ except KeyError:
+ raise RuntimeError("Unknown account type: %s" % (child_name,))
+
+ if child.hasAttribute(ATTRIBUTE_REPEAT):
+ repeat = int(child.getAttribute(ATTRIBUTE_REPEAT))
+ else:
+ repeat = 1
+
+ principal = XMLAccountRecord(recordType)
+ principal.parseXML(child)
+ if repeat > 1:
+ for i in xrange(1, repeat+1):
+ newprincipal = principal.repeat(i)
+ self.items[recordType][newprincipal.shortName] = newprincipal
+ updateMembership(newprincipal)
+ else:
+ self.items[recordType][principal.shortName] = principal
+ updateMembership(principal)
+
class XMLAccountRecord (object):
"""
Contains provision information for one user.
@@ -167,23 +180,28 @@
def parseXML(self, node):
for child in node._get_childNodes():
- if child._get_localName() == ELEMENT_SHORTNAME:
+ child_name = child._get_localName()
+ if child_name is None:
+ continue
+ elif child_name == ELEMENT_SHORTNAME:
if child.firstChild is not None:
self.shortName = child.firstChild.data.encode("utf-8")
- elif child._get_localName() == ELEMENT_PASSWORD:
+ elif child_name == ELEMENT_PASSWORD:
if child.firstChild is not None:
self.password = child.firstChild.data.encode("utf-8")
- elif child._get_localName() == ELEMENT_NAME:
+ elif child_name == ELEMENT_NAME:
if child.firstChild is not None:
self.name = child.firstChild.data.encode("utf-8")
- elif child._get_localName() == ELEMENT_MEMBERS:
+ elif child_name == ELEMENT_MEMBERS:
self._parseMembers(child)
- elif child._get_localName() == ELEMENT_CUADDR:
+ elif child_name == ELEMENT_CUADDR:
if child.firstChild is not None:
self.calendarUserAddresses.add(child.firstChild.data.encode("utf-8"))
- elif child._get_localName() == ELEMENT_CANPROXY:
+ elif child_name == ELEMENT_CANPROXY:
CalDAVResource.proxyUsers.add(self.shortName)
self.canproxy = True
+ else:
+ raise RuntimeError("Unknown account attribute: %s" % (child_name,))
def _parseMembers(self, node):
for child in node._get_childNodes():
Modified: CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlfile.py 2007-01-05 01:13:07 UTC (rev 921)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlfile.py 2007-01-05 01:42:07 UTC (rev 922)
@@ -53,7 +53,7 @@
self._accounts()
def recordTypes(self):
- recordTypes = ("user", "group", "resource")
+ recordTypes = ("user", "group", "location", "resource")
return recordTypes
def listRecords(self, recordType):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070104/932c2fdd/attachment.html
More information about the calendarserver-changes
mailing list