1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from caldavclientlibrary.admin.xmlaccounts import recordtypes
18 from caldavclientlibrary.admin.xmlaccounts import tags
19 from caldavclientlibrary.admin.xmlaccounts.record import XMLRecord
20
21 from xml.etree.ElementTree import Element
22
24 """
25 Model object for the XML-based directory. This can parse and generate the full XML file.
26 """
27
33
35 """
36 Add a new principal record to the directory.
37
38 @param record: the record to add.
39 @type record: L{admin.xmlaccounts.record.XMLRecord}
40 """
41 self.records[record.recordType].append(record)
42
44 """
45 Test whether the directory contains a record of the specified type and user id.
46
47 @param recordType: a principal record type.
48 @type recordType: one of L{admin.xmlaccounts.recordtypes.RECORD_TYPES}
49 @param uid: the user id to check.
50 @type uid: C{str}
51
52 @return: C{True} if present in the directory, C{False} otherwise.
53 @rtype: C{boolean}
54 """
55 for record in self.records[recordType]:
56 if record.uid == uid:
57 return True
58 else:
59 return False
60
62 """
63 Test whether the directory contains a record with the specified GUID.
64
65 @param guid: the GUID to check.
66 @type guid: C{str}
67
68 @return: C{True} if present in the directory, C{False} otherwise.
69 @rtype: C{boolean}
70 """
71 for type in recordtypes.RECORD_TYPES:
72 for record in self.records[type]:
73 if record.guid == guid:
74 return True
75 return False
76
78 """
79 Return the record in the directory with the matching record type and user id.
80
81 @param recordType: a principal record type.
82 @type recordType: one of L{admin.xmlaccounts.recordtypes.RECORD_TYPES}
83 @param uid: the user id to check.
84 @type uid: C{str}
85
86 @return: the matching record, or C{None} if not found.
87 @rtype: L{admin.xmlaccounts.record.XMLRecord}
88 """
89 for record in self.records[recordType]:
90 if record.uid == uid:
91 return record
92 else:
93 return None
94
96 """
97 Remove the record with the matching type and user id from the directory.
98
99 @param recordType: a principal record type.
100 @type recordType: one of L{admin.xmlaccounts.recordtypes.RECORD_TYPES}
101 @param uid: the user id to remove.
102 @type uid: C{str}
103
104 @return: C{True} if found and removed, C{False} otherwise.
105 @rtype: C{boolean}
106 """
107 for record in self.records[recordType]:
108 if record.uid == uid:
109 self.records[recordType].remove(record)
110 return True
111 else:
112 return False
113
128
129
130
145
147 """
148 Generate the XML for all records in the specified list.
149
150 @param root: the XML root element for the directory.
151 @type root: C{xml.etree.ElementTree.Element}
152 @param records: a list of L{admin.xmlaccounts.record.XMLRecord} to process.
153 @type records: C{list}
154 """
155 for record in records:
156 root.append(record.writeXML())
157