Skip to content

Commit 4d065c7

Browse files
committed
Convert code to Python 3
Changes from pull request apple#40 by claudep.
1 parent 0d7913a commit 4d065c7

25 files changed

+212
-209
lines changed

cdtdiagnose.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def cmd(args, input=None, raiseOnFail=True):
5555
)
5656
args = parser.parse_args()
5757

58-
print "Running CDT diagnostics due to test failure."
58+
print("Running CDT diagnostics due to test failure.")
5959
log = []
6060

6161
def error(message, e):
6262
log.append("CDT diagnostic: %s" % (message,))
6363
log.append(str(e))
64-
print "\n".join(log)
64+
print("\n".join(log))
6565
sys.exit(1)
6666

6767
now = datetime.datetime.now()
@@ -70,11 +70,11 @@ def error(message, e):
7070

7171
if args.directory is not None:
7272
if not os.path.isdir(args.directory):
73-
print "Specified target directory path is invalid, using default."
73+
print("Specified target directory path is invalid, using default.")
7474
else:
7575
dirname = os.path.join(args.directory, dirname)
7676

77-
print "Saving diagnostic archive to: {}".format(dirname,)
77+
print("Saving diagnostic archive to: {}".format(dirname,))
7878
try:
7979
os.mkdir(dirname)
8080
except Exception as e:
@@ -138,4 +138,4 @@ def error(message, e):
138138
except Exception as e:
139139
error("Could not make diagnostics archive.", e)
140140

141-
print "Saved diagnostics to '%s'" % (archive_name,)
141+
print("Saved diagnostics to '%s'" % (archive_name,))

odsetup.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271

272272

273273
def usage():
274-
print """Usage: odsetup [options] create|create-users|remove
274+
print("""Usage: odsetup [options] create|create-users|remove
275275
Options:
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

287287
def 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):
620620
def 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):
692692
def 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)

setup.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
# limitations under the License.
1717
##
1818

19-
from __future__ import print_function
20-
2119
from os.path import dirname, abspath, join as joinpath
2220
from setuptools import setup, find_packages as setuptools_find_packages
2321
import errno
@@ -62,7 +60,7 @@ def git_info(wc_path):
6260
except subprocess.CalledProcessError:
6361
return None
6462

65-
branch = branch.strip()
63+
branch = branch.decode().strip()
6664

6765
try:
6866
revision = subprocess.check_output(
@@ -76,7 +74,7 @@ def git_info(wc_path):
7674
except subprocess.CalledProcessError:
7775
return None
7876

79-
revision = revision.strip()
77+
revision = revision.decode().strip()
8078

8179
try:
8280
tag = subprocess.check_output(
@@ -90,7 +88,7 @@ def git_info(wc_path):
9088
except subprocess.CalledProcessError:
9189
tag = None
9290
else:
93-
tag = tag.strip()
91+
tag = tag.decode().strip()
9492

9593
return dict(
9694
project=base_project,
@@ -166,7 +164,7 @@ def version():
166164

167165
description = "CalDAV/CardDAV protocol test suite"
168166

169-
long_description = file(joinpath(dirname(__file__), "README.md")).read()
167+
long_description = open(joinpath(dirname(__file__), "README.md")).read()
170168

171169
url = "https://github.com/apple/ccs-caldavtester"
172170

0 commit comments

Comments
 (0)