Package caldavclientlibrary :: Package admin :: Package xmlaccounts :: Package commands :: Module addrecord
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.admin.xmlaccounts.commands.addrecord

  1  ## 
  2  # Copyright (c) 2007-2016 Apple Inc. All rights reserved. 
  3  # 
  4  # Licensed under the Apache License, Version 2.0 (the "License"); 
  5  # you may not use this file except in compliance with the License. 
  6  # You may obtain a copy of the License at 
  7  # 
  8  # http://www.apache.org/licenses/LICENSE-2.0 
  9  # 
 10  # Unless required by applicable law or agreed to in writing, software 
 11  # distributed under the License is distributed on an "AS IS" BASIS, 
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 13  # See the License for the specific language governing permissions and 
 14  # limitations under the License. 
 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   
22 -class AddRecord(Command):
23 """ 24 Command that adds a record to the directory. 25 """ 26 27 CMDNAME = "add" 28
29 - def __init__(self):
30 super(AddRecord, self).__init__(self.CMDNAME, "Add a record of the specified type.")
31
32 - def doCommand(self):
33 """ 34 Run the command. 35 """ 36 if self.doAdd(): 37 return self.writeAccounts() 38 return 0
39
40 - def doAdd(self):
41 """ 42 Prompts the user for details and then adds a new record to the directory. 43 """ 44 45 # Prompt for each thing we need in the record 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 # uid 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 # guid 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 # password 69 record.password = self.promptPassword() 70 71 # name 72 record.name = raw_input("Name: ") 73 74 # members 75 if self.recordType in (recordtypes.recordType_groups,): 76 record.members = self.getMemberList("Enter members of this group", "Member", "members") 77 78 # cuaddr 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 # auto-schedule 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 # enabled for calendaring 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 # proxies 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 # Now validate the record and save it 106 if not record.guid: 107 record.guid = str(uuid4()) 108 109 self.directory.addRecord(record) 110 111 return 1
112