Mercurial > p > roundup > code
comparison scripts/copy-user.py @ 7781:2a6c3eb4e059
chore: lint script
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 04 Mar 2024 21:23:40 -0500 |
| parents | 64b05e24dbd8 |
| children | fed0f839c260 |
comparison
equal
deleted
inserted
replaced
| 7780:9ba04f37896f | 7781:2a6c3eb4e059 |
|---|---|
| 14 copy-user /roundup/tracker1 /roundup/tracker2 `seq 3 10` 14 16 | 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) | 15 (copies users 3, 4, 5, 6, 7, 8, 9, 10, 14 and 16) |
| 16 """ | 16 """ |
| 17 | 17 |
| 18 from __future__ import print_function | 18 from __future__ import print_function |
| 19 | |
| 19 import sys | 20 import sys |
| 21 | |
| 20 import roundup.instance | 22 import roundup.instance |
| 21 | 23 |
| 22 | 24 |
| 23 def copy_user(home1, home2, *userids): | 25 def copy_user(home1, home2, *userids): |
| 24 """Copy users which are listed by userids from home1 to home2""" | 26 """Copy users which are listed by userids from home1 to home2""" |
| 48 | 50 |
| 49 userlist = db1.user.list() | 51 userlist = db1.user.list() |
| 50 for userid in userids: | 52 for userid in userids: |
| 51 try: | 53 try: |
| 52 userid = str(int(userid)) | 54 userid = str(int(userid)) |
| 53 except ValueError as why: | 55 except ValueError: |
| 54 print("Not a numeric user id: %s Skipping ..." % (userid,)) | 56 print("Not a numeric user id: %s Skipping ..." % (userid,)) |
| 55 continue | 57 continue |
| 56 if userid not in userlist: | 58 if userid not in userlist: |
| 57 print("User %s not in source instance. Skipping ..." % userid) | 59 print("User %s not in source instance. Skipping ..." % userid) |
| 58 continue | 60 continue |
| 64 user[attrib] = value | 66 user[attrib] = value |
| 65 try: | 67 try: |
| 66 db2.user.lookup(user['username']) | 68 db2.user.lookup(user['username']) |
| 67 print("User %s: Username '%s' exists in target instance. Skipping ..." % (userid, user['username'])) | 69 print("User %s: Username '%s' exists in target instance. Skipping ..." % (userid, user['username'])) |
| 68 continue | 70 continue |
| 69 except KeyError as why: | 71 except KeyError: |
| 70 pass | 72 pass |
| 71 print("Copying user %s (%s) ..." % (userid, user['username'])) | 73 print("Copying user %s (%s) ..." % (userid, user['username'])) |
| 72 db2.user.create(**user) | 74 db2.user.create(**user) |
| 73 | 75 |
| 74 db2.commit() | 76 db2.commit() |
