1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from caldavclientlibrary.admin.xmlaccounts.commands.command import Command
18 from caldavclientlibrary.admin.xmlaccounts.record import XMLRecord
19 from uuid import uuid4
20 from caldavclientlibrary.admin.xmlaccounts import recordtypes
21
23 """
24 Command that adds a record to the directory.
25 """
26
27 CMDNAME = "add"
28
31
39
41 """
42 Prompts the user for details and then adds a new record to the directory.
43 """
44
45
46 record = XMLRecord()
47 record.recordType = self.recordType
48 print "Enter the fields for the record (ctrl-D to stop at any time)"
49 try:
50
51 while True:
52 record.uid = raw_input("Id: ")
53 if not record.uid:
54 print "A valid uid is required. Please try again."
55 elif self.directory.containsRecord(self.recordType, record.uid):
56 print "Record uid: '%s' of type: '%s' does already exists in the directory." % (record.uid, self.recordType,)
57 else:
58 break
59
60
61 while True:
62 record.guid = raw_input("GUID [leave empty to auto-generate]: ")
63 if record.guid and self.directory.containsGUID(record.guid):
64 print "GUID: '%s' already used in the directory" % (record.guid,)
65 else:
66 break
67
68
69 record.password = self.promptPassword()
70
71
72 record.name = raw_input("Name: ")
73
74
75 if self.recordType in (recordtypes.recordType_groups,):
76 record.members = self.getMemberList("Enter members of this group", "Member", "members")
77
78
79 while True:
80 cuaddr = raw_input("Calendar user address [leave empty to stop adding addresses]: ")
81 if cuaddr:
82 record.calendarUserAddresses.add(cuaddr)
83 else:
84 break
85
86
87 if self.recordType in (recordtypes.recordType_locations, recordtypes.recordType_resources,):
88 auto_schedule = raw_input("Turn on automatic scheduling [y/n]?: ")
89 if auto_schedule == "y":
90 record.autoSchedule = True
91
92
93 if self.recordType in (recordtypes.recordType_users, recordtypes.recordType_groups,):
94 enable_calendars = raw_input("Create calendar account rather than access-only account [y/n]?: ")
95 if enable_calendars == "n":
96 record.enabledForCalendaring = False
97
98
99 if self.recordType in (recordtypes.recordType_locations, recordtypes.recordType_resources,):
100 record.proxies = self.getMemberList("Enter proxies of this location or resource", "Proxy", "proxies")
101
102 except EOFError:
103 return 0
104
105
106 if not record.guid:
107 record.guid = str(uuid4())
108
109 self.directory.addRecord(record)
110
111 return 1
112