[CalendarServer-changes] [13578] CalendarServer/trunk/calendarserver/tools/principals.py

source_changes at macosforge.org source_changes at macosforge.org
Fri May 30 11:44:16 PDT 2014


Revision: 13578
          http://trac.calendarserver.org//changeset/13578
Author:   sagen at apple.com
Date:     2014-05-30 11:44:16 -0700 (Fri, 30 May 2014)
Log Message:
-----------
When adding principals on the command line, make record name and uid optional

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/principals.py

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2014-05-30 18:42:18 UTC (rev 13577)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2014-05-30 18:44:16 UTC (rev 13578)
@@ -21,7 +21,7 @@
 import operator
 import os
 import sys
-from uuid import UUID
+import uuid
 
 from calendarserver.tools.cmdline import utilityMain, WorkerService
 from calendarserver.tools.util import (
@@ -827,29 +827,41 @@
 
 def parseCreationArgs(args):
     """
-    Look at the command line arguments for --add, and simply assume the first
-    is full name, the second is short name, and the third is uid.  We can make
-    this fancier later.
+    Look at the command line arguments for --add; the first arg is required
+    and is the full name.   If only that one arg is provided, generate a UUID
+    and use it for record name and uid.  If two args are provided, use the
+    second arg as the record name and generate a UUID for the uid.  If three
+    args are provided, the second arg is the record name and the third arg
+    is the uid.
     """
 
-    if len(args) != 3:
+    numArgs = len(args)
+    if numArgs == 0:
         print(
-            "When adding a principal, you must provide full-name, record-name, "
-            "and UID"
+            "When adding a principal, you must provide the full-name"
         )
         sys.exit(64)
 
     fullName = args[0].decode("utf-8")
-    shortName = args[1].decode("utf-8")
-    uid = args[2].decode("utf-8")
 
+    if numArgs == 1:
+        shortName = uid = unicode(uuid.uuid4()).upper()
+
+    elif numArgs == 2:
+        shortName = args[1].decode("utf-8")
+        uid = unicode(uuid.uuid4()).upper()
+
+    else:
+        shortName = args[1].decode("utf-8")
+        uid = args[2].decode("utf-8")
+
     return fullName, shortName, uid
 
 
 
 def isUUID(value):
     try:
-        UUID(value)
+        uuid.UUID(value)
         return True
     except:
         return False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140530/64f4cf02/attachment.html>


More information about the calendarserver-changes mailing list