aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/gmg_commands/__init__.py4
-rw-r--r--mediagoblin/gmg_commands/users.py20
2 files changed, 24 insertions, 0 deletions
diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py
index fd546aac..0cb239a2 100644
--- a/mediagoblin/gmg_commands/__init__.py
+++ b/mediagoblin/gmg_commands/__init__.py
@@ -37,6 +37,10 @@ SUBCOMMAND_MAP = {
'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup',
'func': 'mediagoblin.gmg_commands.users:changepw',
'help': 'Changes a user\'s password'},
+ 'deleteuser': {
+ 'setup': 'mediagoblin.gmg_commands.users:deleteuser_parser_setup',
+ 'func': 'mediagoblin.gmg_commands.users:deleteuser',
+ 'help': 'Deletes a user'},
'dbupdate': {
'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup',
'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate',
diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py
index 4a730d9e..186557e0 100644
--- a/mediagoblin/gmg_commands/users.py
+++ b/mediagoblin/gmg_commands/users.py
@@ -115,3 +115,23 @@ def changepw(args):
print 'Password successfully changed'
else:
print 'The user doesn\'t exist'
+
+
+def deleteuser_parser_setup(subparser):
+ subparser.add_argument(
+ 'username',
+ help="Username to delete")
+
+
+def deleteuser(args):
+ commands_util.setup_app(args)
+
+ db = mg_globals.database
+
+ user = db.User.query.filter_by(
+ username=unicode(args.username.lower())).one()
+ if user:
+ user.delete()
+ print 'The user %s has been deleted' % args.username
+ else:
+ print 'The user %s doesn\'t exist' % args.username