#!/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 = 'extras-qa@fedoraproject.org' 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("accounts@fedora.redhat.com", 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))