forked from qd-today/qd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrole.py
More file actions
33 lines (29 loc) · 743 Bytes
/
chrole.py
File metadata and controls
33 lines (29 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2017 Binux <roy@binux.me>
#
# Distributed under terms of the MIT license.
"""
change the role of user
"""
import sys
import config
if config.db_type == 'sqlite3':
import sqlite3_db as db
else:
import db
userdb = db.UserDB()
if not 2 <= len(sys.argv) <= 3:
print("Usage: {} email [role]".format(sys.argv[0]))
sys.exit(1)
else:
email = sys.argv[1]
role = sys.argv[2] if len(sys.argv) == 3 else ''
user = userdb.get(email=email, fields=['id'])
if not user:
print("Cannot find user: ", email)
sys.exit(1)
userdb.mod(user['id'], role=role)
print("role of {} changed to {}".format(email, role or '[empty]'))