[08329f4] | 1 | #!/usr/local/bin/python |
---|
| 2 | |
---|
| 3 | import os, sys |
---|
| 4 | import MySQLdb |
---|
| 5 | from optparse import OptionParser |
---|
| 6 | |
---|
| 7 | if len(sys.argv) == 3: |
---|
| 8 | user, project = sys.argv[1:3] |
---|
| 9 | else: |
---|
| 10 | sys.exit("Usage %s user project" % sys.argv[0]) |
---|
| 11 | |
---|
| 12 | db = MySQLdb.connect(db='tbdb') |
---|
| 13 | c = db.cursor() |
---|
| 14 | c.execute("select uid, uid_idx from users where uid=%s", (user,)) |
---|
| 15 | |
---|
| 16 | uids = c.fetchall() |
---|
| 17 | |
---|
| 18 | if len(uids) == 1: |
---|
| 19 | uid, uid_idx = uids[0] |
---|
| 20 | else: |
---|
| 21 | sys.exit("User is not unique??") |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | c.execute("select pid, pid_idx, gid_idx from groups where pid=%s and pid = gid", (project,)) |
---|
| 25 | gids = c.fetchall() |
---|
| 26 | |
---|
| 27 | if len(gids) == 1: |
---|
| 28 | pid, pid_idx, gid_idx = gids[0] |
---|
| 29 | else: |
---|
| 30 | sys.exit("Group is not unique") |
---|
| 31 | |
---|
| 32 | c.execute("select uid from group_membership where uid=%s and pid=%s", (user, project)) |
---|
| 33 | |
---|
| 34 | uids = c.fetchall() |
---|
| 35 | if len(uids) != 0: |
---|
| 36 | sys.exit("%s already in %s" % (user, project)) |
---|
| 37 | |
---|
| 38 | c.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 | |
---|
| 43 | print "inserted %d rows" % c.rowcount |
---|