You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2016/04/28 04:31:59 UTC

svn commit: r1741378 - /vcl/sandbox/useful_scripts/managegroups.py

Author: jfthomps
Date: Thu Apr 28 02:31:58 2016
New Revision: 1741378

URL: http://svn.apache.org/viewvc?rev=1741378&view=rev
Log:
updated for python 3
changed from using xmlrpclib to xmlrpc.client - this involved changing a number of the functions defined in the inherited classes
updated calls to print to use parenthesis

Modified:
    vcl/sandbox/useful_scripts/managegroups.py

Modified: vcl/sandbox/useful_scripts/managegroups.py
URL: http://svn.apache.org/viewvc/vcl/sandbox/useful_scripts/managegroups.py?rev=1741378&r1=1741377&r2=1741378&view=diff
==============================================================================
--- vcl/sandbox/useful_scripts/managegroups.py (original)
+++ vcl/sandbox/useful_scripts/managegroups.py Thu Apr 28 02:31:58 2016
@@ -27,103 +27,90 @@
 #vclurl = 'https://vcl.ncsu.edu/scheduling/index.php?mode=xmlrpccall' # URL of VCL site
 # --------------------------------------------------------------------------
 
-import xmlrpclib, sys, os, stat, re
+import sys, os, stat, re
+import xmlrpc.client, http.client
+import urllib
 from optparse import OptionParser
 
-class VCLTransport(xmlrpclib.SafeTransport):
-	##
-	# Send a complete request, and parse the response.
-	#
-	# @param host Target host.
-	# @param handler Target PRC handler.
-	# @param request_body XML-RPC request body.
-	# @param verbose Debugging flag.
-	# @return Parsed response.
-
-	def request(self, host, userid, passwd, handler, request_body, verbose=0):
-		# issue XML-RPC request
-
-		h = self.make_connection(host)
-		if verbose:
-			h.set_debuglevel(1)
-
-		self.send_request(h, handler, request_body)
-		h.putheader('X-APIVERSION', '2')
-		h.putheader('X-User', userid)
-		h.putheader('X-Pass', passwd)
-		self.send_host(h, host)
-		self.send_user_agent(h)
-		self.send_content(h, request_body)
-
-		errcode, errmsg, headers = h.getreply()
-
-		if errcode != 200:
-			raise ProtocolError(
-				host + handler,
-				errcode, errmsg,
-				headers
-				)
-
-		self.verbose = verbose
-
-		try:
-			sock = h._conn.sock
-		except AttributeError:
-			sock = None
-
-		try:
-			resp = self._parse_response(h.getfile(), sock)
-		except xmlrpclib.Fault, err:
-			if(err.faultCode == 3):
-				print "ERROR: Received '%s' error. The credentials you supplied to log in to the VCL site were not accepted." % (err.faultString)
-			elif(err.faultCode == 4):
-				print "ERROR: %s" % (err.faultString)
-			elif(err.faultCode == 5):
-				print "ERROR: Received '%s' error. The VCL site could not establish a connection with your authentication server." % (err.faultString)
-			elif(err.faultCode == 6):
-				print "ERROR: Received '%s' error. The VCL site could not determine a method to use to authenticate the supplied user." % (err.faultString)
-			else:
-				print "ERROR: Received '%s' error from VCL site." % (err.faultString)
-			sys.exit(3)
+class VCLTransport(xmlrpc.client.Transport):
+	__userid = ''
+	__passwd = ''
 
-		return resp
+	def addAuth(self, userid, passwd):
+		self.__userid = userid
+		self.__passwd = passwd
+
+	def addAuthHeaders(self):
+		self._extra_headers.append(('X-APIVERSION', '2'))
+		self._extra_headers.append(('X-User', self.__userid))
+		self._extra_headers.append(('X-Pass', self.__passwd))
+
+class VCLSafeTransport(VCLTransport):
+	"""Handles an HTTPS transaction to an XML-RPC server."""
+
+	def __init__(self, use_datetime=False, use_builtin_types=False, *,
+	             context=None):
+		super().__init__(use_datetime=use_datetime, use_builtin_types=use_builtin_types)
+		self.context = context
+
+	def make_connection(self, host):
+		if self._connection and host == self._connection[0]:
+			return self._connection[1]
+
+		if not hasattr(http.client, "HTTPSConnection"):
+			raise NotImplementedError(
+			"your version of http.client doesn't support HTTPS")
+		# create a HTTPS connection object from a host descriptor
+		# host may be a string, or a (host, x509-dict) tuple
+		chost, self._extra_headers, x509 = self.get_host_info(host)
+		self._connection = host, http.client.HTTPSConnection(chost,
+			None, context=self.context, **(x509 or {}))
+		self.addAuthHeaders()
+		return self._connection[1]
 
-class VCLServerProxy(xmlrpclib.ServerProxy):
+class VCLServerProxy(xmlrpc.client.ServerProxy):
 	__userid = ''
 	__passwd = ''
-	def __init__(self, uri, userid, passwd, transport=None, encoding=None,
-				 verbose=0, allow_none=0, use_datetime=0):
+	def __init__(self, uri, userid, passwd, transport=None, encoding=None, verbose=False,
+	             allow_none=False, use_datetime=False, use_builtin_types=False,
+	             *, context=None):
 		self.__userid = userid
 		self.__passwd = passwd
 		# establish a "logical" server connection
 
 		# get the url
-		import urllib
-		type, uri = urllib.splittype(uri)
+		type, uri = urllib.parse.splittype(uri)
 		if type not in ("http", "https"):
-			raise IOError, "unsupported XML-RPC protocol"
-		self.__host, self.__handler = urllib.splithost(uri)
+			raise IOError("unsupported XML-RPC protocol")
+		self.__host, self.__handler = urllib.parse.splithost(uri)
 		if not self.__handler:
 			self.__handler = "/RPC2"
 
 		if transport is None:
-			transport = VCLTransport()
+			if type == "https":
+				handler = VCLSafeTransport
+				extra_kwargs = {"context": context}
+			else:
+				handler = VCLTransport
+				extra_kwargs = {}
+			transport = handler(use_datetime=use_datetime,
+				use_builtin_types=use_builtin_types,
+				**extra_kwargs)
+			transport.addAuth(self.__userid, self.__passwd)
 		self.__transport = transport
 
-		self.__encoding = encoding
+		self.__encoding = encoding or 'utf-8'
 		self.__verbose = verbose
 		self.__allow_none = allow_none
 
 	def __request(self, methodname, params):
 		# call a method on the remote server
 
-		request = xmlrpclib.dumps(params, methodname, encoding=self.__encoding,
-				  allow_none=self.__allow_none)
+		request = xmlrpc.client.dumps(params, methodname, encoding=self.__encoding,
+						allow_none=self.__allow_none).encode(self.__encoding)
 
 		response = self.__transport.request(
 			self.__host,
-			self.__userid,
-			self.__passwd,
 			self.__handler,
 			request,
 			verbose=self.__verbose
@@ -136,68 +123,65 @@ class VCLServerProxy(xmlrpclib.ServerPro
 
 	def __getattr__(self, name):
 		# magic method dispatcher
-		return xmlrpclib._Method(self.__request, name)
-
-	# note: to call a remote object with an non-standard name, use
-	# result getattr(server, "strange-python-name")(args)
+		return xmlrpc.client._Method(self.__request, name)
 
 def addUserGroup(options):
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCaddUserGroup(options.name, options.affiliation, options.owner, options.managingGroup, options.initialmax, options.totalmax, options.maxextend, options.custom)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	elif rc['status'] == 'success':
-		print "SUCCESS: User group sucessfully created"
+		print("SUCCESS: User group sucessfully created")
 	else:
-		print "ERROR: unknown problem while creating new user group"
+		print("ERROR: unknown problem while creating new user group")
 
 def getUserGroupAttributes(options):
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCgetUserGroupAttributes(options.name, options.affiliation)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	elif rc['status'] == 'success':
-		print "SUCCESS: Attributes retreived"
-		print 'owner: %s\nmanagingGroup: %s\ninitialMaxTime: %s\ntotalMaxTime: %s\nmaxExtendTime: %s' % (rc['owner'], rc['managingGroup'], rc['initialMaxTime'], rc['totalMaxTime'], rc['maxExtendTime'])
+		print("SUCCESS: Attributes retreived")
+		print('owner: %s\nmanagingGroup: %s\ninitialMaxTime: %s\ntotalMaxTime: %s\nmaxExtendTime: %s' % (rc['owner'], rc['managingGroup'], rc['initialMaxTime'], rc['totalMaxTime'], rc['maxExtendTime']))
 	else:
-		print "ERROR: unknown problem while getting user group attributes"
+		print("ERROR: unknown problem while getting user group attributes")
 
 def deleteUserGroup(options):
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCdeleteUserGroup(options.name, options.affiliation)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	elif rc['status'] == 'success':
-		print "SUCCESS: User group sucessfully deleted"
+		print("SUCCESS: User group sucessfully deleted")
 	else:
-		print "ERROR: unknown problem while deleting user group"
+		print("ERROR: unknown problem while deleting user group")
 
 def editUserGroup(options):
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCeditUserGroup(options.name, options.affiliation, options.newname, options.newaffiliation, options.owner, options.managingGroup, options.initialmax, options.totalmax, options.maxextend)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	elif rc['status'] == 'success':
-		print "SUCCESS: User group sucessfully updated"
+		print("SUCCESS: User group sucessfully updated")
 	else:
-		print "ERROR: unknown problem while updating user group"
+		print("ERROR: unknown problem while updating user group")
 
 def getUserGroupMembers(options):
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCgetUserGroupMembers(options.name, options.affiliation)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	elif rc['status'] == 'success':
-		print "SUCCESS: Membership retrieved"
+		print("SUCCESS: Membership retrieved")
 		for item in rc['members']:
-			print item
+			print(item)
 	else:
-		print "ERROR: unknown problem while getting user group members"
+		print("ERROR: unknown problem while getting user group members")
 
 def addUsersToGroup(options):
 	newusers = []
@@ -209,17 +193,17 @@ def addUsersToGroup(options):
 	if options.userlist:
 		newusers += options.userlist.split(',')
 	if len(newusers) == 0:
-		print "WARNING: no users specified to add to group, not doing anything"
+		print("WARNING: no users specified to add to group, not doing anything")
 		sys.exit(4)
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCaddUsersToGroup(options.name, options.affiliation, newusers)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	elif rc['status'] == 'success':
-		print "SUCCESS: Users sucessfully added to group"
+		print("SUCCESS: Users sucessfully added to group")
 	else:
-		print "ERROR: unknown problem while adding users to group"
+		print("ERROR: unknown problem while adding users to group")
 
 def removeUsersFromGroup(options):
 	delusers = []
@@ -231,23 +215,23 @@ def removeUsersFromGroup(options):
 	if options.userlist:
 		delusers += options.userlist.split(',')
 	if len(delusers) == 0:
-		print "WARNING: no users specified to remove from group, not doing anything"
+		print("WARNING: no users specified to remove from group, not doing anything")
 		sys.exit(4)
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCremoveUsersFromGroup(options.name, options.affiliation, delusers)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	elif rc['status'] == 'success':
-		print "SUCCESS: Users sucessfully removed from group"
+		print("SUCCESS: Users sucessfully removed from group")
 	else:
-		print "ERROR: unknown problem while removing users from group"
+		print("ERROR: unknown problem while removing users from group")
 
 def emptyGroupMembership(options):
 	caller = VCLServerProxy(options.vclurl, options.vcluser, options.vclpass)
 	rc = caller.XMLRPCgetUserGroupMembers(options.name, options.affiliation)
 	if(rc['status'] == 'error'):
-		print  'ERROR: There was an error with the API call: ' + rc['errormsg']
+		print('ERROR: There was an error with the API call: ' + rc['errormsg'])
 		sys.exit(5)
 	else:
 		options.userlist = ','.join(rc['members'])
@@ -256,73 +240,73 @@ def emptyGroupMembership(options):
 
 def printHelp(command='all'):
 	if command == 'all':
-		print "Usage: \n"
-		print "  %s [-u vcluser] [-p 'vclpass'] [-r vclurl] <command> <command parameters>\n" % (sys.argv[0])
-		print "  These first three options can be omitted by defining them at the top of %s" % (sys.argv[0])
-		print "    -u vcluser - log in to VCL site with this user, must be in username@affiliation form"
-		print "    -p 'vclpass' - password used when logging in to VCL site, use quotes if it contains spaces"
-		print "    -r vclurl - URL of VCL site\n"
-		print "Commands:\n"
+		print("Usage: \n")
+		print("  %s [-u vcluser] [-p 'vclpass'] [-r vclurl] <command> <command parameters>\n" % (sys.argv[0]))
+		print("  These first three options can be omitted by defining them at the top of %s" % (sys.argv[0]))
+		print("    -u vcluser - log in to VCL site with this user, must be in username@affiliation form")
+		print("    -p 'vclpass' - password used when logging in to VCL site, use quotes if it contains spaces")
+		print("    -r vclurl - URL of VCL site\n")
+		print("Commands:\n")
 	if command == 'all' or command == 'addUserGroup':
-		print "  addUserGroup - creates a new user group"
-		print "  parameters:"
-		print "    -n name - name of new user group"
-		print "    -a affiliation - affiliation of new user group"
-		print "    -o owner - user that will be the owner of the group in username@affiliation form"
-		print "    -m ManagingGroup - name of user group that can manage membership of the new group"
-		print "    -i InitialMaxTime - (minutes) max initial time users in this group can select for length of reservations"
-		print "    -t TotalMaxTime - (minutes) total length users in the group can have for a reservation (including all extensions)"
-		print "    -x MaxExtendTime - (minutes) max length of time users can request as an extension to a reservation at a time"
-		print "    -c custom (optional, default=1) - whether or not the group should be created as a custom group; if not custom "
-		print "                                      the group membership will be managed via the user's authentication protocol\n"
+		print("  addUserGroup - creates a new user group")
+		print("  parameters:")
+		print("    -n name - name of new user group")
+		print("    -a affiliation - affiliation of new user group")
+		print("    -o owner - user that will be the owner of the group in username@affiliation form")
+		print("    -m ManagingGroup - name of user group that can manage membership of the new group")
+		print("    -i InitialMaxTime - (minutes) max initial time users in this group can select for length of reservations")
+		print("    -t TotalMaxTime - (minutes) total length users in the group can have for a reservation (including all extensions)")
+		print("    -x MaxExtendTime - (minutes) max length of time users can request as an extension to a reservation at a time")
+		print("    -c custom (optional, default=1) - whether or not the group should be created as a custom group; if not custom ")
+		print("                                      the group membership will be managed via the user's authentication protocol\n")
 	if command == 'all' or command == 'getUserGroupAttributes':
-		print "  getUserGroupAttributes - gets information about a user group"
-		print "  parameters:"
-		print "    -n name - name of an existing user group"
-		print "    -a affiliation - affiliation of user group\n"
+		print("  getUserGroupAttributes - gets information about a user group")
+		print("  parameters:")
+		print("    -n name - name of an existing user group")
+		print("    -a affiliation - affiliation of user group\n")
 	if command == 'all' or command == 'deleteUserGroup':
-		print "  deleteUserGroup - deletes a user group"
-		print "  parameters:"
-		print "    -n name - name of an existing user group"
-		print "    -a affiliation - affiliation of user group\n"
+		print("  deleteUserGroup - deletes a user group")
+		print("  parameters:")
+		print("    -n name - name of an existing user group")
+		print("    -a affiliation - affiliation of user group\n")
 	if command == 'all' or command == 'editUserGroup':
-		print "  editUserGroup - modifies attributes of a user group"
-		print "  parameters:"
-		print "    -n name - name of an existing user group"
-		print "    -a affiliation - affiliation of user group"
-		print "    -N NewName - (optional) new name for the user group"
-		print "    -A NewAffiliation - (optional) new affiliation for the user group"
-		print "    -O NewOwner - (optional) new owner for the user group in username@affiliation form"
-		print "    -M NewManagingGroup - (optional) new user group that can manage membership of the user group in group@affiliation form"
-		print "    -I NewInitialMaxTime - (optional) new max initial time users in the group can select for length of reservations"
-		print "    -T NewTotalMaxTime - (optional) new total length users in the group can have for a reservation (including all extensions)"
-		print "    -X NewMaxExtendTime - (optional) new max length of time users can request as an extension to a reservation at a time\n"
+		print("  editUserGroup - modifies attributes of a user group")
+		print("  parameters:")
+		print("    -n name - name of an existing user group")
+		print("    -a affiliation - affiliation of user group")
+		print("    -N NewName - (optional) new name for the user group")
+		print("    -A NewAffiliation - (optional) new affiliation for the user group")
+		print("    -O NewOwner - (optional) new owner for the user group in username@affiliation form")
+		print("    -M NewManagingGroup - (optional) new user group that can manage membership of the user group in group@affiliation form")
+		print("    -I NewInitialMaxTime - (optional) new max initial time users in the group can select for length of reservations")
+		print("    -T NewTotalMaxTime - (optional) new total length users in the group can have for a reservation (including all extensions)")
+		print("    -X NewMaxExtendTime - (optional) new max length of time users can request as an extension to a reservation at a time\n")
 	if command == 'all' or command == 'getUserGroupMembers':
-		print "  getUserGroupMembers - gets members of a user group (Note: it is possible for a group to have no members)"
-		print "  parameters:"
-		print "    -n name - name of an existing user group"
-		print "    -a affiliation - affiliation of user group\n"
+		print("  getUserGroupMembers - gets members of a user group (Note: it is possible for a group to have no members)")
+		print("  parameters:")
+		print("    -n name - name of an existing user group")
+		print("    -a affiliation - affiliation of user group\n")
 	if command == 'all' or command == 'addUsersToGroup':
-		print "  addUsersToGroup - adds users to a group"
-		print "  parameters:"
-		print "    -n name - name of an existing user group"
-		print "    -a affiliation - affiliation of user group"
-		print "    At least one of these must also be specified:"
-		print "      -l UserList - comma delimited list of users to add (no spaces) in username@affiliation form"
-		print "      -f filename - name of file containing users to add (one user per line) in username@affiliation form\n"
+		print("  addUsersToGroup - adds users to a group")
+		print("  parameters:")
+		print("    -n name - name of an existing user group")
+		print("    -a affiliation - affiliation of user group")
+		print("    At least one of these must also be specified:")
+		print("      -l UserList - comma delimited list of users to add (no spaces) in username@affiliation form")
+		print("      -f filename - name of file containing users to add (one user per line) in username@affiliation form\n")
 	if command == 'all' or command == 'removeUsersFromGroup':
-		print "  removeUsersFromGroup - removes users from a group"
-		print "  parameters:"
-		print "    -n name - name of an existing user group"
-		print "    -a affiliation - affiliation of user group"
-		print "    At least one of these must also be specified:"
-		print "      -l UserList - comma delimited list of users to remove (no spaces) in username@affiliation form"
-		print "      -f filename - name of file containing users to remove (one user per line) in username@affiliation form\n"
+		print("  removeUsersFromGroup - removes users from a group")
+		print("  parameters:")
+		print("    -n name - name of an existing user group")
+		print("    -a affiliation - affiliation of user group")
+		print("    At least one of these must also be specified:")
+		print("      -l UserList - comma delimited list of users to remove (no spaces) in username@affiliation form")
+		print("      -f filename - name of file containing users to remove (one user per line) in username@affiliation form\n")
 	if command == 'all' or command == 'emptyGroupMembership':
-		print "  emptyGroupMembership - removes all users currently in a group"
-		print "  parameters:"
-		print "    -n name - name of an existing user group"
-		print "    -a affiliation - affiliation of user group\n"
+		print("  emptyGroupMembership - removes all users currently in a group")
+		print("  parameters:")
+		print("    -n name - name of an existing user group")
+		print("    -a affiliation - affiliation of user group\n")
 
 if len(sys.argv) == 1:
 	printHelp()
@@ -352,17 +336,17 @@ else:
 try:
 	vcluser
 except NameError:
-	print "ERROR: vcluser must be definied internally or specified on the command line"
+	print("ERROR: vcluser must be definied internally or specified on the command line")
 	sys.exit(1)
 try:
 	vclpass
 except NameError:
-	print "ERROR: vclpass must be definied internally or specified on the command line"
+	print("ERROR: vclpass must be definied internally or specified on the command line")
 	sys.exit(1)
 try:
 	vclurl
 except NameError:
-	print "ERROR: vclurl must be definied internally or specified on the command line"
+	print("ERROR: vclurl must be definied internally or specified on the command line")
 	sys.exit(1)
 
 parser = OptionParser(add_help_option=False)
@@ -379,7 +363,7 @@ if command == 'addUserGroup':
 	parser.add_option('-c', dest='custom', default=1)
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('addUserGroup')
 		sys.exit(2)
 	if options.custom == '1' and options.name and options.affiliation and options.owner and options.managingGroup and options.initialmax and options.totalmax and options.maxextend:
@@ -388,7 +372,7 @@ if command == 'addUserGroup':
 		options.owner = ''
 		options.managingGroup = ''
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('addUserGroup')
 		sys.exit(2)
 	options.vcluser = vcluser
@@ -402,13 +386,13 @@ elif command == 'getUserGroupAttributes'
 	parser.add_option('-a', dest='affiliation')
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('getUserGroupAttributes')
 		sys.exit(2)
 	if options.name and options.affiliation:
 		pass
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('getUserGroupAttributes')
 		sys.exit(2)
 	options.vcluser = vcluser
@@ -422,13 +406,13 @@ elif command == 'deleteUserGroup':
 	parser.add_option('-a', dest='affiliation')
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('deleteUserGroup')
 		sys.exit(2)
 	if options.name and options.affiliation:
 		pass
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('deleteUserGroup')
 		sys.exit(2)
 	options.vcluser = vcluser
@@ -449,13 +433,13 @@ elif command == 'editUserGroup':
 	parser.add_option('-X', dest='maxextend')
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('editUserGroup')
 		sys.exit(2)
 	if options.name and options.affiliation:
 		pass
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('editUserGroup')
 		sys.exit(2)
 	params = "name: %s\naffiliation: %s" % (options.name, options.affiliation)
@@ -498,13 +482,13 @@ elif command == 'getUserGroupMembers':
 	parser.add_option('-a', dest='affiliation')
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('getUserGroupMembers')
 		sys.exit(2)
 	if options.name and options.affiliation:
 		pass
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('getUserGroupMembers')
 		sys.exit(2)
 	options.vcluser = vcluser
@@ -520,13 +504,13 @@ elif command == 'addUsersToGroup':
 	parser.add_option('-f', dest='filename')
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('addUsersToGroup')
 		sys.exit(2)
 	if options.name and options.affiliation:
 		pass
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('addUsersToGroup')
 		sys.exit(2)
 	if options.userlist:
@@ -534,16 +518,16 @@ elif command == 'addUsersToGroup':
 	elif options.filename:
 		# check for file existance
 		if not os.path.exists(options.filename):
-			print "ERROR: specified file (%s) does not exist" % (options.filename)
+			print("ERROR: specified file (%s) does not exist" % (options.filename))
 			sys.exit(3)
 		# check for file readability
 		perm = os.stat(options.filename)
 		mode = perm[stat.ST_MODE]
 		if not mode & stat.S_IREAD:
-			print "ERROR: specified file (%s) is not readable" % (options.filename)
+			print("ERROR: specified file (%s) is not readable" % (options.filename))
 			sys.exit(3)
 	else:
-		print "ERROR: at least one of -l or -f must be specified\n"
+		print("ERROR: at least one of -l or -f must be specified\n")
 		printHelp('addUsersToGroup')
 		sys.exit(2)
 	options.vcluser = vcluser
@@ -559,13 +543,13 @@ elif command == 'removeUsersFromGroup':
 	parser.add_option('-f', dest='filename')
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('removeUsersFromGroup')
 		sys.exit(2)
 	if options.name and options.affiliation:
 		pass
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('removeUsersFromGroup')
 		sys.exit(2)
 	if options.userlist:
@@ -573,16 +557,16 @@ elif command == 'removeUsersFromGroup':
 	elif options.filename:
 		# check for file existance
 		if not os.path.exists(options.filename):
-			print "ERROR: specified file (%s) does not exist" % (options.filename)
+			print("ERROR: specified file (%s) does not exist" % (options.filename))
 			sys.exit(3)
 		# check for file readability
 		perm = os.stat(options.filename)
 		mode = perm[stat.ST_MODE]
 		if not mode & stat.S_IREAD:
-			print "ERROR: specified file (%s) is not readable" % (options.filename)
+			print("ERROR: specified file (%s) is not readable" % (options.filename))
 			sys.exit(3)
 	else:
-		print "ERROR: at least one of -l or -f must be specified\n"
+		print("ERROR: at least one of -l or -f must be specified\n")
 		printHelp('removeUsersFromGroup')
 		sys.exit(2)
 	options.vcluser = vcluser
@@ -596,13 +580,13 @@ elif command == 'emptyGroupMembership':
 	parser.add_option('-a', dest='affiliation')
 	(options, remaining) = parser.parse_args(args)
 	if len(remaining):
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('emptyGroupMembership')
 		sys.exit(2)
 	if options.name and options.affiliation:
 		pass
 	else:
-		print "ERROR: Incorrect number of parameters specified\n";
+		print("ERROR: Incorrect number of parameters specified\n")
 		printHelp('emptyGroupMembership')
 		sys.exit(2)
 	options.vcluser = vcluser
@@ -610,7 +594,7 @@ elif command == 'emptyGroupMembership':
 	options.vclurl = vclurl
 	emptyGroupMembership(options)
 else:
-	print "ERROR: unknown command: %s\n" % (command)
+	print("ERROR: unknown command: %s\n" % (command))
 	printHelp()
 	sys.exit(2)