forked from autotest/autotest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_superuser.py
executable file
·53 lines (46 loc) · 1.45 KB
/
make_superuser.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
try:
import autotest.common as common
except ImportError:
import common
import MySQLdb
import sys
from autotest.client.shared import global_config
if (len(sys.argv) < 2 or
[arg for arg in sys.argv[1:] if arg.startswith('-')]):
print "Usage: %s username [username ...]" %sys.argv[0]
sys.exit(1)
config = global_config.global_config
section = 'AUTOTEST_WEB'
host = config.get_config_value(section, "host")
db_name = config.get_config_value(section, "database")
user = config.get_config_value(section, "user")
password = config.get_config_value(section, "password")
con = MySQLdb.connect(host=host, user=user,
passwd=password, db=db_name)
cur = con.cursor()
for username in sys.argv[1:]:
cur.execute("""
SELECT access_level
FROM afe_users
WHERE login = %s""", username)
row = cur.fetchone()
if row is None:
print "User %s does not exist. Creating..." % username
cur.execute("""
INSERT INTO afe_users (login, access_level)
VALUES (%s, 100)""", username)
print " Done"
else:
print "Updating user %s..." % username
cur.execute("""
UPDATE afe_users
SET access_level = 100
WHERE login = %s""", username)
if (cur.rowcount == 1):
print " Done"
else:
print " %s is already a superuser!" % username
cur.close()
con.commit()
con.close()