Below is a small Python script which uses the OpenGroupware.org XML-RPC Daemon to add a OGo team and team members.
Usage
The first parameter given to the script specifies the name of the team to
be created (in the example below this equals to myteam).
The second parameter specifies the logins of the accounts to be added to this team, separated by commas (in the example below these are root,bjoern,joe).
If you specify invalid accounts, the script will notice it and won't add these
accounts to the new team (as you can see in the example, the account joe
doesn't exist in the system and therefore it won't be added to the team).
Sample Run
bjoern@grobi:xmlrpc # ./skyrix_add_team_members.py myteam root,bjoern,joe Team 'myteam' successfully created (ID '12740')
Invalid account 'joe' specified
Successfully added members ['root', 'bjoern']
bjoern@grobi:xmlrpc #
To run this script you need the 'patched' xmlrpclib.py which is available here. See the general Python instructions for more details.
You need to change the variables in the __init__ section to match your
system, especially the password of the 'root' user has to be changed.
Download the script
Script Source
#!/usr/bin/env python
# $Id: index.html 6 2004-08-19 15:10:17Z znek $
# adds a team and the given users to the SKYRiX system
import socket, sys, string, xmlrpclib
from types import *
class AddTeamTool:
def __init__(self):
""" initialization """
self.__url = 'http://localhost:20000/RPC2'
self.__login = 'root'
self.__pwd = 'YOUR_SKYRIX_ROOT_PASSWORD'
def initDaemon(self):
""" init XML-RPC daemon """
try:
self.__server = xmlrpclib.ServerProxy(self.__url,
login=self.__login,
password=self.__pwd)
except TypeError,e:
sys.stderr.write("ERROR: You are probably using the wrong version"
"of xmlrpclib\nGet the right version at:\n")
sys.stderr.write("http://developer.skyrix.com/02_skyrix/xmlrpc/"
"xmlrpclib.py\n")
return 2
except IOError,e:
sys.stderr.write("ERROR: %s\n" % e)
return 3
return 0
def run(self):
result = self.initDaemon()
if result != 0: return result
teamName = sys.argv[1]
members = None
if len(sys.argv) > 2:
members = string.split(sys.argv[2],',')
try:
teamId = self.__server.team.insert({'login' : teamName,
'description' : teamName,
})
except socket.error,e:
sys.stderr.write("Couldn't connect to the XML-RPC daemon\n")
return 2
except:
sys.stderr.write("An error occured when creating the team\n")
return 2
if type(teamId) is IntType:
print "Team '%s' successfully created (ID '%s')" % (teamName,
teamId)
else:
print "Creating team failed..."
return 1
if members != None:
memberIds = []
for member in members:
try:
valid = self.__server.account.getByLogin(member)
except:
sys.stderr.write("An error occured when searching for "
"the login\n")
return 1
if type(valid) is DictType:
memberIds.append(valid['id'])
else:
sys.stderr.write("Invalid account '%s' "
"specified\n" % member)
members.remove(member)
try:
result = self.__server.team.setMembers(teamId, memberIds)
except:
sys.stderr.write("An error occured when adding members\n")
return 1
if result.value == 1:
print "Successfully added members %s" % members
else:
print "Adding members failed"
return 1
return 0
if __name__ == "__main__":
if len(sys.argv) == 1:
sys.stderr.write("No team name provided\n")
sys.exit(2)
tool = AddTeamTool()
try:
returnCode = tool.run()
except KeyboardInterrupt:
sys.stderr.write("Program cancelled by user\n")
returnCode = 2
sys.exit(returnCode)
Author
Björn Stierand