From 581a2847442f1d8b4051726aca50e0dc31ea29bb Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 6 Mar 2015 14:37:32 -0500 Subject: [PATCH] Add a rename user tool --- tools/renameuser.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tools/renameuser.py diff --git a/tools/renameuser.py b/tools/renameuser.py new file mode 100644 index 000000000..43ff4dcff --- /dev/null +++ b/tools/renameuser.py @@ -0,0 +1,27 @@ +from app import app +from data import model + +import argparse + +def renameUser(username, new_name): + if username == new_name: + raise Exception('Must give a new username') + + check = model.get_user_or_org(new_name) + if check is not None: + raise Exception('New username %s already exists' % new_name) + + existing = model.get_user_or_org(username) + if existing is None: + raise Exception('Username %s does not exist' % username) + + print 'Renaming user...' + model.change_username(existing.id, new_name) + print 'Rename complete' + + +parser = argparse.ArgumentParser(description='Rename a user') +parser.add_argument('username', help='The current username') +parser.add_argument('new_name', help='The new username') +args = parser.parse_args() +renameUser(args.username, args.new_name)