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 import getopt
19
21
22 CMDNAME = "remove"
23
27
29 print """USAGE: %s TYPE [OPTIONS]
30
31 TYPE: One of "users", "groups", "locations" or "resources". Also,
32 "u", "g", "l" or "r" as shortcuts.
33
34 Options:
35 -f file path to accounts.xml
36 --uid UID to remove
37 """ % (self.cmdname,)
38
40 """
41 Execute the command specified by the command line arguments.
42
43 @param argv: command line arguments.
44 @type argv: C{list}
45
46 @return: 1 for success, 0 for failure.
47 @rtype: C{int}
48 """
49
50
51 argv = self.getTypeArgument(argv)
52 if argv is None:
53 return 0
54
55 opts, args = getopt.getopt(argv, 'f:h', ["help", "uid=",])
56
57 for name, value in opts:
58 if name == "-f":
59 self.path = value
60 elif name in ("-h", "--help"):
61 self.usage()
62 return 1
63 elif name == "--uid":
64 self.uid = value
65 else:
66 print "Unknown option: %s." % (name,)
67 self.usage()
68 return 0
69
70 if not self.path:
71 print "Must specify a path."
72 self.usage()
73 return 0
74 if not self.uid:
75 print "Must specify a UID."
76 self.usage()
77 return 0
78 if args:
79 print "Arguments not allowed."
80 self.usage()
81 return 0
82
83 if not self.loadAccounts():
84 return 0
85 return self.doCommand()
86
94
96 """
97 Removes an existing record from the directory.
98 """
99
100
101 record = self.directory.getRecord(self.recordType, self.uid)
102 if record is None:
103 print "No '%s' record matching uid '%s'" % (self.recordType, self.uid,)
104 return 0
105
106
107 confirm = raw_input("Really delete the record for '%s' in '%s' [y/n]?" % (self.uid, self.recordType,))
108 if confirm != "y":
109 return 0
110
111 self.directory.removeRecord(self.recordType, self.uid)
112 return 1
113