2 # Copyright (C) 2003 by Intevation GmbH
4 # Thomas Arendsen Hein <thomas@intevation.de>
6 # This program is free software dual licensed under the GPL (>=v2)
7 # and the Roundup Licensing (see COPYING.txt in the roundup distribution).
10 copy-user <instance-home> <instance-home> <userid> [<userid>...]
12 Copy one or more Roundup users from one tracker instance to another.
14 copy-user /roundup/tracker1 /roundup/tracker2 `seq 3 10` 14 16
15 (copies users 3, 4, 5, 6, 7, 8, 9, 10, 14 and 16)
18 __version__
= "$Revision: 1.1 $"
19 # $Source: /home/stefan/projects/roundup-migrate/roundup/scripts/copy-user.py,v $
20 # $Id: copy-user.py,v 1.1 2003-12-04 23:13:43 richard Exp $
23 import roundup
.instance
26 def copy_user(home1
, home2
, *userids
):
27 """Copy users which are listed by userids from home1 to home2"""
29 copyattribs
= ['username', 'password', 'address', 'realname', 'phone',
30 'organisation', 'alternate_addresses', 'roles', 'timezone']
33 instance1
= roundup
.instance
.open(home1
)
34 print "Opened source instance: %s" % home1
36 print "Can't open source instance: %s" % home1
40 instance2
= roundup
.instance
.open(home2
)
41 print "Opened target instance: %s" % home2
43 print "Can't open target instance: %s" % home2
46 db1
= instance1
.open('admin')
47 db2
= instance2
.open('admin')
49 userlist
= db1
.user
.list()
50 for userid
in userids
:
52 userid
= str(int(userid
))
53 except ValueError, why
:
54 print "Not a numeric user id: %s Skipping ..." % (userid
,)
56 if userid
not in userlist
:
57 print "User %s not in source instance. Skipping ..." % userid
61 for attrib
in copyattribs
:
62 value
= db1
.user
.get(userid
, attrib
)
66 db2
.user
.lookup(user
['username'])
67 print "User %s: Username '%s' exists in target instance. Skipping ..." % (userid
, user
['username'])
71 print "Copying user %s (%s) ..." % (userid
, user
['username'])
72 db2
.user
.create(**user
)
76 print "Closed target instance."
78 print "Closed source instance."
81 if __name__
== "__main__":
86 copy_user(*sys
.argv
[1:])