271271
272272
273273def usage ():
274- print """Usage: odsetup [options] create|create-users|remove
274+ print ( """Usage: odsetup [options] create|create-users|remove
275275Options:
276276 -h Print this help and exit
277277 -n node OpenDirectory node to target
@@ -281,18 +281,18 @@ def usage():
281281 -x disable OD node checks
282282 -v verbose logging
283283 -V very verbose logging
284- """
284+ """ )
285285
286286
287287def cmd (args , input = None , raiseOnFail = True ):
288288
289289 if veryverbose :
290- print "-----"
290+ print ( "-----" )
291291 if verbose :
292- print args .replace (diradmin_pswd , "xxxx" )
292+ print ( args .replace (diradmin_pswd , "xxxx" ) )
293293 if veryverbose and input :
294- print input
295- print "*****"
294+ print ( input )
295+ print ( "*****" )
296296 if input :
297297 p = Popen (args , stdin = PIPE , stdout = PIPE , stderr = PIPE , shell = True )
298298 result = p .communicate (input )
@@ -301,8 +301,8 @@ def cmd(args, input=None, raiseOnFail=True):
301301 result = p .communicate ()
302302
303303 if veryverbose :
304- print "Output: %s" % ( result [0 ], )
305- print "Code: %s" % ( p .returncode , )
304+ print ( "Output: %s" % result [0 ])
305+ print ( "Code: %s" % p .returncode )
306306 if raiseOnFail and p .returncode :
307307 raise RuntimeError (result [1 ])
308308 return result [0 ], p .returncode
@@ -319,9 +319,9 @@ def checkDataSource(node):
319319 result = cmd ("dscl localhost -list /LDAPv3" )
320320 result = ["/LDAPv3/{}" .format (subnode ) for subnode in result [0 ].splitlines ()]
321321 if len (result ) > 1 or result [0 ] != node :
322- print "Error: Host is bound to other directory nodes: {}" .format (result )
323- print "CalDAVTester will likely fail with other nodes present."
324- print "Please remove all nodes except the one being used for odsetup."
322+ print ( "Error: Host is bound to other directory nodes: {}" .format (result ) )
323+ print ( "CalDAVTester will likely fail with other nodes present." )
324+ print ( "Please remove all nodes except the one being used for odsetup." )
325325 sys .exit (1 )
326326
327327
@@ -552,8 +552,8 @@ def loadLists(path, records):
552552
553553 try :
554554 plist = readPlistFromString (result [0 ])
555- except xml .parsers .expat .ExpatError , e :
556- print "Error (%s) parsing (%s)" % (e , result [0 ])
555+ except xml .parsers .expat .ExpatError as e :
556+ print ( "Error (%s) parsing (%s)" % (e , result [0 ]) )
557557 raise
558558
559559 for record in plist ["result" ]:
@@ -574,7 +574,7 @@ def doToAccounts(odf, protocol, f, users_only=False):
574574 if count > 1 :
575575 for ctr in range (1 , count + 1 ):
576576 attrs = {}
577- for key , value in record [3 ].iteritems ():
577+ for key , value in record [3 ].items ():
578578 if value .find ("%02d" ) != - 1 :
579579 value = value % (ctr ,)
580580 attrs [key ] = value
@@ -598,7 +598,7 @@ def doGroupMemberships(odf):
598598
599599 for groupname , users , nestedgroups in memberships :
600600 if verbose :
601- print "Group membership: {}" .format (groupname )
601+ print ( "Group membership: {}" .format (groupname ) )
602602
603603 # Get group record
604604 group = odf .lookupRecordName (kDSStdRecordTypeGroups , groupname )
@@ -620,7 +620,7 @@ def doGroupMemberships(odf):
620620def createUser (odf , path , user ):
621621
622622 if verbose :
623- print "Create user: {}/{}" .format (path , user [0 ])
623+ print ( "Create user: {}/{}" .format (path , user [0 ]) )
624624
625625 if path in (kDSStdRecordTypeUsers , kDSStdRecordTypeGroups ,):
626626 createUserViaDS (odf , path , user )
@@ -643,7 +643,7 @@ def createUserViaDS(odf, path, user):
643643 record = odf .createRecord (path , user [0 ], user [1 ], user [2 ])
644644 else :
645645 if verbose :
646- print "%s/%s already exists" % (path , user [0 ],)
646+ print ( "%s/%s already exists" % (path , user [0 ],) )
647647
648648 # Now read the guid for this record
649649 if user [0 ] in guids :
@@ -692,7 +692,7 @@ def createUserViaGateway(path, user):
692692def removeUser (odf , path , user ):
693693
694694 if verbose :
695- print "Remove user: {}/{}" .format (path , user [0 ])
695+ print ( "Remove user: {}/{}" .format (path , user [0 ]) )
696696
697697 if path in (kDSStdRecordTypeUsers , kDSStdRecordTypeGroups ,):
698698 removeUserViaDS (odf , path , user )
@@ -815,7 +815,7 @@ def manageRecords(odf, path, user):
815815 elif option == "-x" :
816816 node_check = False
817817 else :
818- print "Unrecognized option: %s" % ( option , )
818+ print ( "Unrecognized option: %s" % option )
819819 usage ()
820820 raise ValueError
821821
@@ -824,15 +824,15 @@ def manageRecords(odf, path, user):
824824
825825 # Process arguments
826826 if len (args ) == 0 :
827- print "No arguments given. One of 'create' or 'remove' must be present."
827+ print ( "No arguments given. One of 'create' or 'remove' must be present." )
828828 usage ()
829829 raise ValueError
830830 elif len (args ) > 1 :
831- print "Too many arguments given. Only one of 'create' or 'remove' must be present."
831+ print ( "Too many arguments given. Only one of 'create' or 'remove' must be present." )
832832 usage ()
833833 raise ValueError
834834 elif args [0 ] not in ("create" , "create-users" , "remove" ):
835- print "Wrong arguments given: %s" % ( args [0 ], )
835+ print ( "Wrong arguments given: %s" % args [0 ])
836836 usage ()
837837 raise ValueError
838838
@@ -880,6 +880,6 @@ def manageRecords(odf, path, user):
880880 loadLists (kDSStdRecordTypeResources , resources )
881881 doToAccounts (odf , protocol , removeUser )
882882
883- except Exception , e :
883+ except Exception :
884884 traceback .print_exc ()
885885 sys .exit (1 )
0 commit comments