source: fedd/user_to_group.py @ 08329f4

axis_examplecompt_changesinfo-opsversion-1.30version-2.00version-3.01version-3.02
Last change on this file since 08329f4 was 08329f4, checked in by Ted Faber <faber@…>, 16 years ago

dynamic projects and multiple keys

  • Property mode set to 100755
File size: 1.1 KB
Line 
1#!/usr/local/bin/python
2
3import os, sys
4import MySQLdb
5from optparse import OptionParser
6
7if len(sys.argv) == 3:
8    user, project = sys.argv[1:3]
9else:
10    sys.exit("Usage %s user project" % sys.argv[0])
11
12db = MySQLdb.connect(db='tbdb')
13c = db.cursor()
14c.execute("select uid, uid_idx from users where uid=%s", (user,))
15
16uids = c.fetchall()
17
18if len(uids) == 1:
19    uid, uid_idx = uids[0]
20else:
21    sys.exit("User is not unique??")
22
23
24c.execute("select pid, pid_idx, gid_idx from groups where pid=%s and pid = gid", (project,))
25gids = c.fetchall()
26
27if len(gids) == 1:
28    pid, pid_idx, gid_idx = gids[0]
29else:
30    sys.exit("Group is not unique")
31
32c.execute("select uid from group_membership where uid=%s and pid=%s", (user, project))
33
34uids = c.fetchall()
35if len(uids) != 0:
36    sys.exit("%s already in %s" % (user, project))
37
38c.execute("insert into group_membership (uid, uid_idx, gid, gid_idx, pid, " + \
39        "pid_idx, trust, date_applied, date_approved) " + \
40        "values (%s, %s, %s, %s, %s, %s, 'none', now(), now())",
41        (uid, uid_idx, pid, gid_idx, pid, pid_idx))
42
43print "inserted %d rows" % c.rowcount
Note: See TracBrowser for help on using the repository browser.