Hey guys, I've rewritten the owners.list => bugzilla script to sync from the packagedb => bugzilla. This script relies on a new version of the python-fedora module which has a fas email => bugzilla email mapping. (python-fedora-0.2.90.5-1.noarch.rpm).
I'm attaching the old version that's in cvs so people who don't have the module checked out from cvs can more easily take a look at the differences. -Toshio
#!/usr/bin/python
#!/usr/bin/python2
import sys, os, errno
import website, crypt
import getopt, re
from fedora.accounts.fas import AccountSystem
GRANT_DIRECT = 0
GRANT_DERIVED = 1
GRANT_REGEXP = 2
def get_bz_user_id(bzdbh, username):
bzdbc = bzdbh.cursor()
bzdbc.execute("SELECT userid FROM profiles WHERE login_name = %s",
(username,))
if bzdbc.rowcount:
return bzdbc.fetchone()[0]
opts, args = getopt.getopt(sys.argv[1:], '', ('usage', 'help'))
if len(args) < 1 or ('--usage','') in opts or ('--help','') in opts:
print """
Usage: bz-make-components.py FILENAME...
"""
sys.exit(1)
if __name__ == '__main__':
# Initialize the connection to the bugzilla db
bzdbh = website.get_dbh('bugs', 'bugs')
bzdbc = bzdbh.cursor()
bzdbh.commit()
# Email addresses that are listed in the pkgdb but not in bugzilla
need_emails = {}
# Initialize the connection to the package database
pkgdbh = website.get_dbh('pkgdb')
pkgdbc = pkgdbh.cursor()
pkgdbh.commit()
# Fetch the owner information from the db
qry = "select c.name, c.version, p.name, p.description, pl.owner," \
" pl.qacontact pl.id from" \
" collection as c, package as p, packagelisting as pl where" \
" c.id = pl.collectionid and p.id = pl.packageid"
pkgdbc.execute(qry)
for pkg in pkgdbc.fetchall():
product = pkg[0]
productVersion = pkg[1]
component = pkg[2]
description = pkg[3]
ownerId = pkg[4]
qaId = pkg[5]
pkgListingId = pkg[6]
# Get co-maintainers and watchers
cclistIds = []
qry = "select userid from personpackagelisting as p," \
" personpackagelistingacl as a, statuscodetranslation as s" \
" where p.packagelistingid = %s and a.acl = 'watchbugzilla'" \
" and a.statuscode = s.statuscodeid and s.language = 'C' and" \
" s.statusname = 'Approved' and p.id = a.personpackagelistingid"
pkgdbc.execute(qry, (pkgListingId,))
for ccPerson in pkgdbc.fetchall():
cclistIds.append(ccPerson[0])
# Convert fas ids into bugzilla email addresses and from there into
# a bugzilla Id.
fas = AccountSystem()
(user, groups) = fas.get_user_info(ownerId)
owner = user['bugzilla_email']
owner_num = get_bz_user_id(bzdbh, owner)
if owner_num is None:
if owner not in need_emails:
need_emails[owner] = []
need_emails[owner].append((product, productVersion, component,
ownerId, user['email'], owner, pkgListingId))
# print "Invalid owner %s at %s:%s" % (owner, curfile, lnum)
# We cannot enter this package into bugzilla until it has an owner
continue
if qaId:
(user, groups) = fas.get_user_info(qaId)
qa = user['bugzilla_email']
else:
qa = '[EMAIL PROTECTED]'
qa_num = get_bz_user_id(bzdbh, qa)
cclist = []
for personId in cclistIds:
(user, groups) = fas.get_user_info(personId)
bzId = get_bz_user_id(bzdbh, user['bugzilla_email'])
if bzId == None:
if user['bugzilla_email'] not in need_emails:
need_emails[user['bugzilla_email']] = []
need_emails[user['bugzilla_email']].append((product,
productVersion, component, personId, user['email'],
user['bugzilla_email'], pkgListingId))
else:
cclist.append(bzId)
if product[:len('Fedora ')] != 'Fedora ' or product == 'Fedora Core' or product == 'Fedora Legacy':
print "Invalid product %s at %s:%s" % (product, curfile, lnum)
continue
bzdbc.execute("SELECT id FROM products WHERE name = %s", (product,))
if not bzdbc.rowcount:
bzdbc.execute("INSERT INTO products (name, description, disallownew, votesperuser, maxvotesperbug, votestoconfirm, defaultmilestone, depends) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", (product, product, 0, 0, 10000, 0, '---', 0))
bzdbc.execute("SELECT id FROM products WHERE name = %s", (product,))
product_id = bzdbc.fetchone()[0]
bzdbc.execute("INSERT INTO versions (value, product_id) VALUES (%s, %s)", ("development", product_id))
bzdbc.execute("INSERT INTO milestones (product_id, value, sortkey) VALUES (%s, '---', 0)", (product_id,))
else:
product_id = bzdbc.fetchone()[0]
bzdbc.execute("SELECT * FROM components WHERE product_id = %s AND name = %s", (product_id, component))
if bzdbc.rowcount:
arow = bzdbc.fetchhash()
bzdbc.execute("UPDATE components SET initialowner = %s, initialqacontact = %s, initialcclist = %s WHERE id = %s",
(owner_num, qa_num, ':'.join(map(str,cclist)), arow['id']))
else:
bzdbc.execute("INSERT INTO components (name, product_id, description, initialowner, initialqacontact, initialcclist) VALUES (%s, %s, %s, %s, %s, %s)",
(component, product_id, description, owner_num, qa_num, ':'.join(map(str,cclist))))
bzdbh.commit()
for email, identifiers in need_emails.items():
if not email.strip():
print "Need an e-mail for", identifiers
continue
print "Sending e-mail to", email
website.send_email("[EMAIL PROTECTED]", email, "You need to create a bugzilla account for %s" % email, """
In order to make bugzilla components for Fedora-related programs, we need to have an existing bugzilla account for
the listed owner. You (%s) do not have a bugzilla account, but are listed as the owner for the following components:
%s
Please create a bugzilla account for %s immediately, because this amazingly stupid cron job will keep sending you an
e-mail every hour until you do :)
- The management
""" % (email, '\n'.join(identifiers), email))
#!/usr/bin/python
#!/usr/bin/python2
import sys, os, errno
import website, crypt
import getopt, re
GRANT_DIRECT = 0
GRANT_DERIVED = 1
GRANT_REGEXP = 2
def get_bz_user_id(bzdbh, username):
bzdbc = bzdbh.cursor()
bzdbc.execute("SELECT userid FROM profiles WHERE login_name = %s",
(username,))
if bzdbc.rowcount:
return bzdbc.fetchone()[0]
opts, args = getopt.getopt(sys.argv[1:], '', ('usage', 'help'))
if len(args) < 1 or ('--usage','') in opts or ('--help','') in opts:
print """
Usage: bz-make-components.py FILENAME...
"""
sys.exit(1)
bzdbh = website.get_dbh('bugs', 'bugs')
bzdbc = bzdbh.cursor()
bzdbh.commit()
need_emails = {}
for curfile in args:
if not os.path.exists(curfile):
continue
fh = open(curfile, 'r')
lnum = 0
while 1:
aline = fh.readline()
lnum += 1
if not aline:
break
aline = aline.strip()
if not aline or aline[0] == '#':
continue
pieces = aline.split('|')
try:
product, component, description, owner, qa = pieces[:5]
except:
print "Invalid line %s at %s:%s" % (aline, curfile, lnum)
cclist = []
owners = owner.split(',')
owner = owners[0]
if len(owners) > 1:
for I in owners[1:]:
Inum = get_bz_user_id(bzdbh, I)
if Inum is None:
if not need_emails.has_key(I):
need_emails[I] = []
need_emails[I].append((product, component, curfile, lnum))
continue
cclist.append(Inum)
owner_num = get_bz_user_id(bzdbh, owner)
qa_num = get_bz_user_id(bzdbh, qa)
if owner_num is None:
if not need_emails.has_key(owner):
need_emails[owner] = []
need_emails[owner].append((product, component, curfile, lnum))
# print "Invalid owner %s at %s:%s" % (owner, curfile, lnum)
continue
if len(pieces) > 5 and pieces[5]:
for I in pieces[5].split(','):
Inum = get_bz_user_id(bzdbh, I)
if Inum is None:
if not need_emails.has_key(I):
need_emails[I] = []
need_emails[I].append((product, component, curfile, lnum))
continue
cclist.append(Inum)
if product[:len('Fedora ')] != 'Fedora ' or product == 'Fedora Core' or product == 'Fedora Legacy':
print "Invalid product %s at %s:%s" % (product, curfile, lnum)
continue
bzdbc.execute("SELECT id FROM products WHERE name = %s", (product,))
if not bzdbc.rowcount:
bzdbc.execute("INSERT INTO products (name, description, disallownew, votesperuser, maxvotesperbug, votestoconfirm, defaultmilestone, depends) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", (product, product, 0, 0, 10000, 0, '---', 0))
bzdbc.execute("SELECT id FROM products WHERE name = %s", (product,))
product_id = bzdbc.fetchone()[0]
bzdbc.execute("INSERT INTO versions (value, product_id) VALUES (%s, %s)", ("development", product_id))
bzdbc.execute("INSERT INTO milestones (product_id, value, sortkey) VALUES (%s, '---', 0)", (product_id,))
else:
product_id = bzdbc.fetchone()[0]
bzdbc.execute("SELECT * FROM components WHERE product_id = %s AND name = %s", (product_id, component))
if bzdbc.rowcount:
arow = bzdbc.fetchhash()
bzdbc.execute("UPDATE components SET initialowner = %s, initialqacontact = %s, initialcclist = %s WHERE id = %s",
(owner_num, qa_num, ':'.join(map(str,cclist)), arow['id']))
else:
bzdbc.execute("INSERT INTO components (name, product_id, description, initialowner, initialqacontact, initialcclist) VALUES (%s, %s, %s, %s, %s, %s)",
(component, product_id, description, owner_num, qa_num, ':'.join(map(str,cclist))))
bzdbh.commit()
for I, J in need_emails.items():
if not I.strip():
print "Need an e-mail for", J
continue
print "Sending e-mail to", I
website.send_email("[EMAIL PROTECTED]", I, "You need to create a bugzilla account for %s" % I, """
In order to make bugzilla components for Fedora-related programs, we need to have an existing bugzilla account for
the listed owner. You (%s) do not have a bugzilla account, but are listed as the owner for the following components:
%s
Please create a bugzilla account for %s immediately, because this amazingly stupid cron job will keep sending you an
e-mail every hour until you do :)
- The management
""" % (I, '\n'.join(map(lambda x: "%s (%s)" % x[:2], J)), I))
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Fedora-infrastructure-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/fedora-infrastructure-list
