"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "scripts/copy-user.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

copy-user.py  (roundup-1.6.1):copy-user.py  (roundup-2.0.0)
skipping to change at line 18 skipping to change at line 18
""" """
copy-user <instance-home> <instance-home> <userid> [<userid>...] copy-user <instance-home> <instance-home> <userid> [<userid>...]
Copy one or more Roundup users from one tracker instance to another. Copy one or more Roundup users from one tracker instance to another.
Example: Example:
copy-user /roundup/tracker1 /roundup/tracker2 `seq 3 10` 14 16 copy-user /roundup/tracker1 /roundup/tracker2 `seq 3 10` 14 16
(copies users 3, 4, 5, 6, 7, 8, 9, 10, 14 and 16) (copies users 3, 4, 5, 6, 7, 8, 9, 10, 14 and 16)
""" """
from __future__ import print_function
import sys import sys
import roundup.instance import roundup.instance
def copy_user(home1, home2, *userids): def copy_user(home1, home2, *userids):
"""Copy users which are listed by userids from home1 to home2""" """Copy users which are listed by userids from home1 to home2"""
copyattribs = ['username', 'password', 'address', 'realname', 'phone', copyattribs = ['username', 'password', 'address', 'realname', 'phone',
'organisation', 'alternate_addresses', 'roles', 'timezone'] 'organisation', 'alternate_addresses', 'roles', 'timezone']
try: try:
instance1 = roundup.instance.open(home1) instance1 = roundup.instance.open(home1)
print "Opened source instance: %s" % home1 print("Opened source instance: %s" % home1)
except: except:
print "Can't open source instance: %s" % home1 print("Can't open source instance: %s" % home1)
sys.exit(1) sys.exit(1)
try: try:
instance2 = roundup.instance.open(home2) instance2 = roundup.instance.open(home2)
print "Opened target instance: %s" % home2 print("Opened target instance: %s" % home2)
except: except:
print "Can't open target instance: %s" % home2 print("Can't open target instance: %s" % home2)
sys.exit(1) sys.exit(1)
db1 = instance1.open('admin') db1 = instance1.open('admin')
db2 = instance2.open('admin') db2 = instance2.open('admin')
db1.tx_Source = "cli" db1.tx_Source = "cli"
db2.tx_Source = "cli" db2.tx_Source = "cli"
userlist = db1.user.list() userlist = db1.user.list()
for userid in userids: for userid in userids:
try: try:
userid = str(int(userid)) userid = str(int(userid))
except ValueError as why: except ValueError as why:
print "Not a numeric user id: %s Skipping ..." % (userid,) print("Not a numeric user id: %s Skipping ..." % (userid,))
continue continue
if userid not in userlist: if userid not in userlist:
print "User %s not in source instance. Skipping ..." % userid print("User %s not in source instance. Skipping ..." % userid)
continue continue
user = {} user = {}
for attrib in copyattribs: for attrib in copyattribs:
value = db1.user.get(userid, attrib) value = db1.user.get(userid, attrib)
if value: if value:
user[attrib] = value user[attrib] = value
try: try:
db2.user.lookup(user['username']) db2.user.lookup(user['username'])
print "User %s: Username '%s' exists in target instance. Skipping .. ." % (userid, user['username']) print("User %s: Username '%s' exists in target instance. Skipping .. ." % (userid, user['username']))
continue continue
except KeyError as why: except KeyError as why:
pass pass
print "Copying user %s (%s) ..." % (userid, user['username']) print("Copying user %s (%s) ..." % (userid, user['username']))
db2.user.create(**user) db2.user.create(**user)
db2.commit() db2.commit()
db2.close() db2.close()
print "Closed target instance." print("Closed target instance.")
db1.close() db1.close()
print "Closed source instance." print("Closed source instance.")
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 4: if len(sys.argv) < 4:
print __doc__ print(__doc__)
sys.exit(1) sys.exit(1)
else: else:
copy_user(*sys.argv[1:]) copy_user(*sys.argv[1:])
 End of changes. 12 change blocks. 
11 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)