示例#1
0
 def test_get_bug_wrng_api_k(self):
     """ Wrong API Key, it should raise an Error"""
     # Load our agent for BMO
     bmo = BMOAgent('wrong_api_key_test')
     # Get the bugs from the api
     bug = bmo.get_bug(656222)
     print bug
示例#2
0
 def test_get_bug_wrng_api_k(self):
     """ Wrong API Key, it should raise an Error"""
     # Load our agent for BMO
     bmo = BMOAgent('wrong_api_key_test')
     # Get the bugs from the api
     bug = bmo.get_bug(656222)
     print bug
示例#3
0
def signup():
    error = None
    try:
        initializeSession()
        if request.method == 'GET':
            products = Product.query.order_by(Product.description).all()
            return render_template('signup.html', products=products)
        else:
            email = request.form['email']
            user = User.query.filter_by(email=email).first()

            if user is not None:
                raise Exception('User email already exists')

            password = request.form['password']
            if email == '' or password == '':
                raise Exception('User must have an email and a password!')

            if password != request.form['confirmpassword']:
                raise Exception('Please re-enter the same password')

            try:
                # verify email and password
                bmo = BMOAgent(email, password)
                bug = bmo.get_bug('80000')
            except Exception, e:
                raise Exception(
                    'Failed to verify Bugzilla account on Bugzilla server:' +
                    e)

            #generate salt, hash and store to db
            salt = os.urandom(8)
            m = hashlib.md5()
            m.update(salt)
            m.update(password)
            _hash = m.digest()
            user = User(email=email,
                        _hash=_hash.encode('base64'),
                        salt=salt.encode('base64'))
            db.session.add(user)
            db.session.commit()
            print 'creating'
            create_view(user, request)

            return loginSession(user, password)
    except Exception, e:
        print e
        if error is None:
            error = e
示例#4
0
 def test_get_bug_list_wrng_api_k(self):
     """ Wrong API Key, it should raise an Error"""
     # Set whatever REST API options we want
     options = {
         'changed_after': ['2012-12-24'],
         'changed_before': ['2012-12-27'],
         'changed_field': ['status'],
         'changed_field_to': ['RESOLVED'],
         'product': ['Firefox'],
         'resolution': ['FIXED'],
         'include_fields': ['attachments'],
     }
     # Load our agent for BMO
     bmo = BMOAgent('wrong_api_key_test')
     # Get the bugs from the api
     bmo.get_bug_list(options)
示例#5
0
 def test_get_bug_list_wrng_api_k(self):
     """ Wrong API Key, it should raise an Error"""
     # Set whatever REST API options we want
     options = {
         'changed_after':    ['2012-12-24'],
         'changed_before':   ['2012-12-27'],
         'changed_field':    ['status'],
         'changed_field_to': ['RESOLVED'],
         'product':          ['Firefox'],
         'resolution':       ['FIXED'],
         'include_fields':   ['attachments'],
     }
     # Load our agent for BMO
     bmo = BMOAgent('wrong_api_key_test')
     # Get the bugs from the api
     bmo.get_bug_list(options)
示例#6
0
 def test_get_bug_list(self):
     # Set whatever REST API options we want
     options = {
         'changed_after':    ['2012-12-24'],
         'changed_before':   ['2012-12-27'],
         'changed_field':    ['status'],
         'changed_field_to': ['RESOLVED'],
         'product':          ['Firefox'],
         'resolution':       ['FIXED'],
         'include_fields':   ['attachments'],
     }
     # Load our agent for BMO
     bmo = BMOAgent()
     # Get the bugs from the api
     buglist = bmo.get_bug_list(options)
     assert buglist != []
示例#7
0
def edit_account():
    error = ''
    message = ''
    email = ''
    try:
        email = request.form['email']
        password = request.form['password']
        user = User.query.filter_by(email=session['user'].email).first()

        if verify_account(user, password):
            newpassword = request.form['newpassword']
            if newpassword != request.form['confirmpassword']:
                raise Exception('Please re-enter the same password')
            else:
                session['bmo'] = bmo = BMOAgent(email, newpassword)
                try:
                    bug = bmo.get_bug('80000')
                except:
                    error = "Could not get bug, check your account details"
                salt = os.urandom(8)
                m = hashlib.md5()
                m.update(salt)
                m.update(newpassword)
                _hash = m.digest()
                user.hash = _hash.encode('base64')
                user.salt = salt.encode('base64')

            user.email = email
            db.session.commit()
            session['user'] = user
            message = 'Account updated'
    except Exception, e:
        error = e
示例#8
0
 def test_get_bug_list(self):
     # Set whatever REST API options we want
     options = {
         'changed_after': ['2012-12-24'],
         'changed_before': ['2012-12-27'],
         'changed_field': ['status'],
         'changed_field_to': ['RESOLVED'],
         'product': ['Firefox'],
         'resolution': ['FIXED'],
         'include_fields': ['attachments'],
     }
     # Load our agent for BMO
     bmo = BMOAgent()
     # Get the bugs from the api
     buglist = bmo.get_bug_list(options)
     assert buglist != []
示例#9
0
def signup():
    error = None
    try:
        initializeSession()
        if request.method == 'GET':
            products = Product.query.order_by(Product.description).all()
            return render_template('signup.html', products=products)
        else:
            email = request.form['email']
            user = User.query.filter_by(email=email).first()

            if user is not None:
                raise Exception('User email already exists')

            password = request.form['password']
            if email == '' or password == '':
                raise Exception('User must have an email and a password!')

            if password != request.form['confirmpassword']:
                raise Exception('Please re-enter the same password')

            try:
                # verify email and password
                bmo = BMOAgent(email, password)
                bug = bmo.get_bug('80000')
            except Exception, e:
                raise Exception('Failed to verify Bugzilla account on Bugzilla server:' + e)

            #generate salt, hash and store to db
            salt = os.urandom(8)
            m = hashlib.md5()
            m.update(salt)
            m.update(password)
            _hash = m.digest()
            user = User(email=email, _hash=_hash.encode('base64'), salt=salt.encode('base64'))
            db.session.add(user)
            db.session.commit()
            print 'creating'
            create_view(user, request)

            return loginSession(user, password)
    except Exception, e:
        print e
        if error is None:
            error = e
示例#10
0
def loginSession(user, password):
    initializeSession()
    session['logged_in'] = True
    session['user'] = user
    session['bmo'] = BMOAgent(user.email, password)
    session.permanent = True
    # TODO(lsblak): Make there be a default view available to non-logged in user
    #view = View.query.filter_by(default=True).filter_by(owner_id=user.id).first()
    return view_individual(user)
示例#11
0
def getBugs(host):
    # We can use "None" for both instead to not authenticate
    # username, password = get_credentials()

    # Load our agent for BMO
    bmo = BMOAgent(None, None)

    # Set whatever REST API options we want
    options = {
        'alias': 'reboots-sjc1',
    }

    # Get the bugs from the api
    buglist = bmo.get_bug_list(options)

    print "Found %s bugs" % (len(buglist))

    for bug in buglist:
        print bug.id, bug.status, bug.summary, bug.blocks, bug.depends_on
        print bug.id, bug.comments
示例#12
0
def getBugs(host):
    # We can use "None" for both instead to not authenticate
    # username, password = get_credentials()

    # Load our agent for BMO
    bmo = BMOAgent(None, None)

    # Set whatever REST API options we want
    options = {
        'alias': 'reboots-sjc1',
    }

    # Get the bugs from the api
    buglist = bmo.get_bug_list(options)

    print "Found %s bugs" % (len(buglist))

    for bug in buglist:
        print bug.id, bug.status, bug.summary, bug.blocks, bug.depends_on
        print bug.id, bug.comments
示例#13
0
def edit_account():
    error = ''
    message = ''
    email = ''
    try:
        email = request.form['email']
        password = request.form['password']
        user = User.query.filter_by(email=session['user'].email).first()
        print user.email

        if verify_account(user, password):
            newpassword = request.form['newpassword']
            print 'shit'
            if newpassword != request.form['confirmpassword']:
                raise Exception('Please re-enter the same password')
            print 'dshit'
            if newpassword == '':
                bmo = BMOAgent(email, password)
                bug = bmo.get_bug('80000')
            else:
                session['bmo'] = bmo = BMOAgent(email, newpassword)
                bug = bmo.get_bug('80000')
                salt = os.urandom(8)
                m = hashlib.md5()
                m.update(salt)
                m.update(password)
                _hash = m.digest()
                user.hash = _hash.encode('base64')
                user.salt = salt.encode('base64')

            user.email = email
            db.session.commit()
            session['user'] = user
            message = 'Account updated'
    except Exception, e:
        error = e
示例#14
0
#  Christian Holler <*****@*****.**> (Original Developer)
#
# ***** END LICENSE BLOCK *****

import sys
import os
import subprocess

from bugzilla.agents import BMOAgent
from bugzilla.utils import get_credentials

# We can use "None" for both instead to not authenticate
username, password = get_credentials()

# Load our agent for BMO
bmo = BMOAgent(username, password)

# Search for all open IonMonkey fuzz bugs
options = {
    'resolution':       '---',
    'query_format':     'advanced',
    'field0-0-0':       'status_whiteboard',
    'type0-0-0':        'substring',
    'value0-0-0':       '[jsbugmon:',
    'include_fields':   '_default',
}

# Get the bugs from the api
buglist = bmo.get_bug_list(options)

if len(buglist) == 0:
示例#15
0
import sys
import os
import subprocess
import re

from bugzilla.agents import BMOAgent
from bugzilla.models import Bug, Attachment, Flag, User, Comment
from bugzilla.utils import urljoin, qs, get_credentials, FILE_TYPES
from sets import Set

# We can use "None" for both instead to not authenticate
username, password = get_credentials()

# Load our agent for BMO
bz = BMOAgent(username, password)

# Search for all fixed bugs that have a security rating of critical or high
options = {
    # Must be a bug in Core product which is FIXED
    'product': 'Core',
    'resolution': 'FIXED',
    # Ignore old bugs, should be fixed at most 180 days ago
    'chfieldto': 'Now',
    'chfieldfrom': '-180d',
    'chfield': 'resolution',
    'chfieldvalue': 'FIXED',
    # Advanced search criteria
    'query_format': 'advanced',
    # Should have an [sg:crit/high tag in whiteboard
    'type0-0-0': 'regexp',
示例#16
0
def nagEmailScript():
    print "*******In nagEmailScript"
    email_cc_list=['*****@*****.**']
    print "*******In nagEmailScript2"
    # Load our agent for BMO
    username = flask.session['username']
    print "*******In nagEmailScript", username
    password = flask.session['password']
    print "*******In nagEmailScript", password
    print "\n\nbefore bmo"
    
    bmo = BMOAgent(username, password)
    bmo.check_login("https://bugzilla.mozilla.org/show_bug.cgi?id=12");
    #people = flask.session["people"]
    people = phonebook.PhonebookDirectory(flask.session['username'],flask.session['password']);
    queries = flask.session['queries'] 
    print "\n\nafter BMO"
    # Get the buglist(s)
    collected_queries = {}
    print queries
    for query in queries:
    # import the query
        print "*****",query
        query_name = query['query_name']
        print "\nquery_name\n",query_name
        print "\nquery_channel\n",query['query_channel']
        collected_queries[query_name] = {
            'channel': query['query_channel'],
            'bugs' : [],
            }
        print "\n\nafter import query"
        if query.has_key('query_params'):
            print "Gathering bugs from query_params in %s" % query
            collected_queries[query_name]['bugs'] = bmo.get_bug_list(query['query_params'])
        elif query.has_key('query_url'):
            print "Gathering bugs from query_url in %s" % query
            collected_queries[query_name]['bugs'] = bmo.get_bug_list(query_url_to_urlencoded(query['query_url']))
            print "gathered$$$$$$$$$$$"
        else:
            raise Exception("Error - no valid query params or url in the config file")
            
    print "After collected queries",   collected_queries  
    total_bugs = 0
    for channel in collected_queries.keys():
        total_bugs += len(collected_queries[channel]['bugs'])

    print "Found %s bugs total for %s queries" % (total_bugs, len(collected_queries.keys()))
    print "Queries to collect: %s" % collected_queries.keys()
    managers = people.managers
    manual_notify = []
    counter = 0
    print "\najajajakakka"
    
    def add_to_managers(manager_email, query):
        if managers[manager_email].has_key('nagging'):
            if managers[manager_email]['nagging'].has_key(query):
                managers[manager_email]['nagging'][query]['bugs'].append(bug)
                print "Adding %s to %s in nagging for %s" % (bug.id, query, manager_email)
            else:
                managers[manager_email]['nagging'][query] = { 'bugs': [bug] }
                print "Adding new query key %s for bug %s in nagging and %s" % (query, bug.id, manager_email)
        else:
            managers[manager_email]['nagging'] = {
                    query : { 'bugs': [bug] },
                }
            print "Creating query key %s for bug %s in nagging and %s" % (query, bug.id, manager_email)
    
  
    verbose = False
    for query in collected_queries.keys():
        print "\nBNBNBNNBN\n"
        
        for b in collected_queries[query]['bugs']:
            if verbose:
                print "\nb::::",b
            counter = counter + 1
            send_mail = True
            bug = bmo.get_bug(b.id)
            if verbose:
                print "\nYYYYYYYYYYYYYYYYYYYYY210\n"
            manual_notify.append(bug)
            assignee = bug.assigned_to.name
            if people.people_by_bzmail.has_key(assignee):
                person = dict(people.people_by_bzmail[assignee])
            else:
                person = None
            if verbose:
                print "\nYYYYYYYYYYYYYYYYYYYYY217\n"
            if send_mail:
                if verbose:
                    print "\nYYYYYYYYYYYYYYYYYYYYY219\n"
                if 'nobody' in assignee:
                    assignee = None
                # TODO - get rid of this, SUCH A HACK!
                elif '*****@*****.**' in assignee:
                    #dmandelin is no longer with the firm so this is changed yo naveed
                    #Note to self do perform error handling in add_to_managers
                    print "No one assigned to JS bug: %s, adding to dmandelin's list..." % bug.id
                    add_to_managers('*****@*****.**', query)
                else:
                    if bug.assigned_to.real_name != None:
                        if person != None:
                            # check if assignee is already a manager, add to their own list
                            if managers.has_key(person['mozillaMail']):
                                add_to_managers(person['mozillaMail'], query)
                            # otherwise we search for the assignee's manager
                            else:
                                # check for manager key first, a few people don't have them
                                if person.has_key('manager') and person['manager'] != None:
                                    manager_email = person['manager']['dn'].split('mail=')[1].split(',')[0]
                                    if managers.has_key(manager_email):
                                        add_to_managers(manager_email, query)
                                    elif people.vices.has_key(manager_email):
                                        # we're already at the highest level we'll go
                                        if managers.has_key(assignee):
                                            add_to_managers(assignee, query)
                                        else:
                                            managers[person['mozillaMail']] = {}
                                            add_to_managers(person['mozillaMail'], query)
                                    else:
                                        # try to go up one level and see if we find a manager
                                        if people.people.has_key(manager_email):
                                            person = dict(people.people[manager_email])
                                            manager_email = person['manager']['dn'].split('mail=')[1].split(',')[0]
                                            if managers.has_key(manager_email):
                                                add_to_managers(manager_email, query)
                                        else:
                                            print "Manager could not be found: %s" % manager_email
                                else:
                                    print "%s's entry doesn't list a manager! Let's ask them to update phonebook." % person['name']
    send_msg = []
    manual_notify_msg =''
    for email, info in managers.items():
        if info.has_key('nagging'):
            print "\n\nIn nagging"
            msg = generateEmailOutput(
            people,
            manager_email=email,
            queries=info['nagging'],
            template=flask.session['modified_template'],
            show_summary=True,
            show_comment=False)
            send_msg.append(msg)
            sent_bugs = 0
            for query, info in info['nagging'].items():
                sent_bugs += len(info['bugs'])
                # take sent bugs out of manual notification list
                for bug in info['bugs']:
                    manual_notify.remove(bug)
                counter = counter - sent_bugs
    
    
  # output the manual notification list
    manual_notify_msg += "No email generated for %s/%s bugs, you will need to manually notify the following %s bugs:\n\n" % (counter, total_bugs, len(manual_notify))
    url = "https://bugzilla.mozilla.org/buglist.cgi?quicksearch="
    for bug in manual_notify:
        manual_notify_msg += "[Bug %s] -- assigned to: %s -- Last commented on: %s\n" % (bug.id, bug.assigned_to.real_name, bug.comments[-1].creation_time.replace(tzinfo=None))
        url += "%s," % bug.id
    manual_notify_msg += "\n\nUrl for manual notification bug list: %s \n" % url
    return send_msg, manual_notify_msg


    
    
    if not managers:
        msg = "\n*************\nNo email generated for %s/%s bugs, you will need to manually notify the following %s bugs:\n" % (counter, flask.session['total_bugs'] , len(manual_notify))
        url = "https://bugzilla.mozilla.org/buglist.cgi?quicksearch="
    
        for bug in manual_notify:
            msg += "[Bug %s] -- assigned to: %s\n -- Last commented on: %s\n" % (bug.id, bug.assigned_to.real_name, bug.comments[-1].creation_time.replace(tzinfo=None))
            url += "%s," % bug.id
        msg += "Url for manual notification bug list: %s" % url
        return True, msg
示例#17
0
#  Christian Holler <*****@*****.**> (Original Developer)
#
# ***** END LICENSE BLOCK *****

import sys
import os
import subprocess

from bugzilla.agents import BMOAgent
from bugzilla.utils import get_credentials

# We can use "None" for both instead to not authenticate
username, password = get_credentials()

# Load our agent for BMO
bmo = BMOAgent(username, password)

# Search for all open IonMonkey fuzz bugs
options = {
    'resolution':       '---',
    'status':           'NEW',
    'query_format':     'advanced',
    'field0-0-0':       'blocked',
    'type0-0-0':        'equals',
    'value0-0-0':       '676763',
    'include_fields':   '_default',
}

# Get the bugs from the api
buglist = bmo.get_bug_list(options)
示例#18
0
 def test_get_bug(self):
     # Load our agent for BMO
     bmo = BMOAgent()
     # Get the bugs from the api
     bug = bmo.get_bug(656222)
     assert bug != []
示例#19
0
def nagEmailScript():
    print "*******In nagEmailScript"
    email_cc_list=['*****@*****.**']
    
    # Load our agent for BMO
    username = flask.session['username']
    password = flask.session['password']
    
    bmo = BMOAgent(username, password)
    bmo.check_login("https://bugzilla.mozilla.org/show_bug.cgi?id=12");
    people = phonebook.PhonebookDirectory(flask.session['username'],flask.session['password']);
    queries = flask.session['queries'] 
    
    # Get the buglist(s)
    collected_queries = {}
    
    for query in queries:
    # import the query
        query_name = query['query_name']
        print "\nquery_name\n",query_name
        print "\nquery_channel\n",query['query_channel']
        collected_queries[query_name] = {
            'channel': query['query_channel'],
            'bugs' : [],
            }
        print "\n\nafter import query"
        if query.has_key('query_params'):
            print "Gathering bugs from query_params in %s" % query
            collected_queries[query_name]['bugs'] = bmo.get_bug_list(query['query_params'])
        elif query.has_key('query_url'):
            print "Gathering bugs from query_url in %s" % query
            collected_queries[query_name]['bugs'] = bmo.get_bug_list(query_url_to_urlencoded(query['query_url']))
        else:
            raise Exception("Error - no valid query params or url in the config file")
            
    total_bugs = 0
    for channel in collected_queries.keys():
        total_bugs += len(collected_queries[channel]['bugs'])

    print "Found %s bugs total for %s queries" % (total_bugs, len(collected_queries.keys()))
    print "Queries to collect: %s" % collected_queries.keys()
    managers = people.managers
    manual_notify = []
    counter = 0
    
    def add_to_managers(manager_email, query):
        if managers.has_key(manager_email):
            if managers[manager_email].has_key('nagging'):
                if managers[manager_email]['nagging'].has_key(query):
                    managers[manager_email]['nagging'][query]['bugs'].append(bug)
                    print "Adding %s to %s in nagging for %s" % (bug.id, query, manager_email)
                else:
                    managers[manager_email]['nagging'][query] = { 'bugs': [bug] }
                    print "Adding new query key %s for bug %s in nagging and %s" % (query, bug.id, manager_email)
            else:
                managers[manager_email]['nagging'] = {
                        query : { 'bugs': [bug] },
                    }
                print "Creating query key %s for bug %s in nagging and %s" % (query, bug.id, manager_email)
        else :
            print "Email not found in phonebook: ", manager_email
            managers[manager_email] = {}
            add_to_managers(manager_email, query)
  
    verbose = False
    for query in collected_queries.keys():
        for b in collected_queries[query]['bugs']:
            if verbose:
                print "\nb::::",b
            counter = counter + 1
            send_mail = True
            bug = bmo.get_bug(b.id)
            if verbose:
                print "\nYYYYYYYYYYYYYYYYYYYYY210\n"
            manual_notify.append(bug)
            assignee = bug.assigned_to.name
            if people.people_by_bzmail.has_key(assignee):
                person = dict(people.people_by_bzmail[assignee])
            else:
                person = None
            if verbose:
                print "\nYYYYYYYYYYYYYYYYYYYYY217\n"
            if send_mail:
                if verbose:
                    print "\nYYYYYYYYYYYYYYYYYYYYY219\n"
                if 'nobody' in assignee:
                    #getting the list of owners externally from Andreas's dashboard 
                    owners_js = urllib2.urlopen("http://andreasgal.github.io/dashboard/owners.js").read(10000)
                    
                    #formatting that js file that declares a variable into a json-ish string
                    owners_js = owners_js.split('{')
                    owners_js = "{" + owners_js[1]
                    owners_js = owners_js.split(';')
                    owners_js = owners_js[0]

                    #get rid of comments in the json file, run until all comments are gone
                    while owners_js.find('//') > 0 or owners_js.find('/*') > 0 :
                        owners_js = re.sub('//.*?\n|/\*.*?\*/', '\n', owners_js, re.S)
                    
                    #removing bracketed 2nds
                    while owners_js.find('(') > 0 or owners_js.find(')') > 0 :
                        owners_js = re.sub('\s*?\(.*?\)\s*?', '', owners_js, re.S)
                    
                    #removing trailing comma
                    owners_js = re.sub('{', '', owners_js)
                    owners_js = re.sub('}', '', owners_js)
                    owners_js = owners_js.strip(' \t\n\r')
                    owners_js = owners_js.strip(',')
                    owners_js = '{\n' + owners_js + '\n}'
                    
                    #search for email of the responsible component owner
                    owners_js = simplejson.loads(owners_js)
                    if ( owners_js.has_key(bug.component) ):
                        component_manager_name = owners_js[bug.component]
                        if people.people_by_name.has_key(component_manager_name) :
                            component_manager = people.people_by_name[component_manager_name]
                            if component_manager['mozillaMail'] != None:
                                add_to_managers(component_manager['mozillaMail'], query)
                            else:
                                assignee = None
                        else :
                            print "Name not found in phonebook: ", component_manager_name 
                            assignee = None
                    else:
                        assignee = None

                # TODO - get rid of this, SUCH A HACK!
                elif '*****@*****.**' in assignee:
                    #dmandelin is no longer with the firm so this is changed yo naveed
                    #Note to self do perform error handling in add_to_managers
                    print "No one assigned to JS bug: %s, adding to dmandelin's list..." % bug.id
                    add_to_managers('*****@*****.**', query)
                else:
                    if bug.assigned_to.real_name != None:
                        if person != None:
                            # check if assignee is already a manager, add to their own list
                            if managers.has_key(person['mozillaMail']):
                                add_to_managers(person['mozillaMail'], query)
                            # otherwise we search for the assignee's manager
                            else:
                                # check for manager key first, a few people don't have them
                                if person.has_key('manager') and person['manager'] != None:
                                    manager_email = person['manager']['dn'].split('mail=')[1].split(',')[0]
                                    if managers.has_key(manager_email):
                                        add_to_managers(manager_email, query)
                                    elif people.vices.has_key(manager_email):
                                        # we're already at the highest level we'll go
                                        if managers.has_key(assignee):
                                            add_to_managers(assignee, query)
                                        else:
                                            managers[person['mozillaMail']] = {}
                                            add_to_managers(person['mozillaMail'], query)
                                    else:
                                        # try to go up one level and see if we find a manager
                                        if people.people.has_key(manager_email):
                                            person = dict(people.people[manager_email])
                                            manager_email = person['manager']['dn'].split('mail=')[1].split(',')[0]
                                            if managers.has_key(manager_email):
                                                add_to_managers(manager_email, query)
                                        else:
                                            print "Manager could not be found: %s" % manager_email
                                else:
                                    print "%s's entry doesn't list a manager! Let's ask them to update phonebook." % person['name']
    send_msg = []
    manual_notify_msg =''
    for email, info in managers.items():
        if info.has_key('nagging'):
            print "\n\nIn nagging"
            msg = generateEmailOutput(
            people,
            manager_email=email,
            queries=info['nagging'],
            template=flask.session['modified_template'],
            show_summary=True,
            show_comment=False)
            send_msg.append(msg)
            sent_bugs = 0
            for query, info in info['nagging'].items():
                sent_bugs += len(info['bugs'])
                # take sent bugs out of manual notification list
                for bug in info['bugs']:
                    manual_notify.remove(bug)
                counter = counter - sent_bugs
    
    
  # output the manual notification list
    manual_notify_msg += "No email generated for %s/%s bugs, you will need to manually notify the following %s bugs:\n\n" % (counter, total_bugs, len(manual_notify))
    url = "https://bugzilla.mozilla.org/buglist.cgi?quicksearch="
    
    for bug in manual_notify:
        manual_notify_msg += "[Bug %s] -- assigned to: %s -- Last commented on: %s\n" % (bug.id, bug.assigned_to.real_name, bug.comments[-1].creation_time.replace(tzinfo=None))
        url += "%s," % bug.id
    manual_notify_msg += "\n\nUrl for manual notification bug list: %s \n" % url
    #print send_msg
    return send_msg, manual_notify_msg


    
    
    if not managers:
        msg = "\n*************\nNo email generated for %s/%s bugs, you will need to manually notify the following %s bugs:\n" % (counter, flask.session['total_bugs'] , len(manual_notify))
        url = "https://bugzilla.mozilla.org/buglist.cgi?quicksearch="
    
        for bug in manual_notify:
            msg += "[Bug %s] -- assigned to: %s\n -- Last commented on: %s\n" % (bug.id, bug.assigned_to.real_name, bug.comments[-1].creation_time.replace(tzinfo=None))
            url += "%s," % bug.id
        msg += "Url for manual notification bug list: %s" % url
        return True, msg
示例#20
0
    if options.show_summary:
        print "\n *****ATTN***** Bug Summaries will be shown in output, be careful when sending emails.\n"

    if not options.username:
        # We can use "None" for both instead to not authenticate
        username, password = get_credentials()
    else:
        username, password = get_credentials(username)
    try:
        int(options.days_since_comment)
    except:
        if options.days_since_comment != None:
            parser.error("Need to provide a number for days since last comment value")

    # Load our agent for BMO
    bmo = BMOAgent(username, password)
    
    # Get the buglist(s)
    collected_queries = {}
    for query in options.queries:
        # import the query
        if os.path.exists(query):
            info = {}
            execfile(query, info)
            query_name = info['query_name']
            collected_queries[query_name] = {
                'channel': info.get('query_channel', ''),
                'bugs' : [],
                }
            if info.has_key('query_params'):
                print "Gathering bugs from query_params in %s" % query
示例#21
0
 def test_get_bug(self):
     # Load our agent for BMO
     bmo = BMOAgent()
     # Get the bugs from the api
     bug = bmo.get_bug(656222)
     assert bug != []
示例#22
0
def findbugs(cfg):

    server = cfg["server"].encode("utf8")
    owner = cfg["owner"].encode("utf8")
    user =  cfg["user"]
    password =  cfg["password"]

    try:
        bzagent = BMOAgent(user,password)
        logging.info("Connected to " + str(server) )
    except:
        logging.info("Failed to connect to " + str(server))
        exit(-1)

    # We're picking our options about what bugs to search for now.
    # We're hardcoding some assumptions about interesting date range
    # and bug categories here.
    # Those components are:
    # - Firefox, Core and Triaged "Untriaged", respectively, or
    # - In one of the Firefox, Core or Toolkit categories, and UNCONFIRMED

    # This is today-1 and today-3 because it's intended to run in a cron job at 3 AM,
    # and have some overlap with the previous day, so we get a floating window across
    # our incoming bugs. 

    date_to    = str(date.isoformat(date.today() - timedelta(1))).encode("utf8")
    date_from  = str(date.isoformat(date.today() - timedelta(3))).encode("utf8")

    # Not proud of this next part. Store this properly in a file somewhere, you donkus.

    # NOTE: The reason it's laid out like this is because bztools doesn't,
    # seem to work with the "product=foo,bar" syntax, despite what the docs say

    option_sets = {
         'firefox': {
            'changed_field':'[Bug creation]',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Firefox',
            'status':   'UNCONFIRMED'  },
        'core': {
            'changed_field':'[Bug creation]',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Core',
            'status':   'UNCONFIRMED'  },
        'toolkit': {
            'changed_field':'[Bug creation]',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Toolkit',
            'status':   'UNCONFIRMED'},
        'firefox_untriaged': {
            'changed_field':'[Bug creation]',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Firefox',
            'component':'Untriaged'},
        'core_untriaged': {
            'changed_field':'[Bug creation]',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Toolkit',
            'component':'Untriaged'},
        'toolkit_untriaged': {
            'changed_field':'[Bug creation]',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Core',
            'component':'Untriaged'
           },
        }

    buglist = list()

    # Get the bugs from the bugzilla API
 
    for options in option_sets.values():
        bugs = bzagent.get_bug_list(options) 
        buglist = list(set(buglist + bugs)) #add and dedupe

    logging.info("Found %s bugs in %s components." % (len(buglist), (len(option_sets)))) 

    # let's open this up a bit.

    date_to    = str(date.isoformat(date.today() - timedelta(1))).encode("utf8")
    date_from  = str(date.isoformat(date.today() - timedelta(40))).encode("utf8")


    stepslist = list()
    option_sets = {
         'firefox': {
            'changed_field':'keywords',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Firefox',
            'keywords':   'steps-wanted'  },
        'core': {
            'changed_field':'keywords',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Core',
            'keywords':   'steps-wanted'  },
        'toolkit': {
            'changed_field':'keywords',
            'changed_after':date_from,
            'changed_before':   date_to,
           'product':  'Toolkit',
            'keywords':   'steps-wanted'},
        }


    for options in option_sets.values():
        steps = bzagent.get_bug_list(options) 
        stepslist = list(set(stepslist + steps)) #add and dedupe

    logging.info("Found %s steps-wanted in %s components." % (len(stepslist), (len(option_sets)))) 


    regressionlist = list()

    option_sets = {
         'firefox': {
            'changed_field':'keywords',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Firefox',
            'keywords':   'regressionwindow-wanted'  },
        'core': {
            'changed_field':'keywords',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Core',
            'keywords':   'regressionwindow-wanted'  },
        'toolkit': {
            'changed_field':'keywords',
            'changed_after':date_from,
            'changed_before':   date_to,
            'product':  'Toolkit',
            'keywords':   'regressionwindow-wanted'},
        }

    for options in option_sets.values():
        regression = bzagent.get_bug_list(options) 
        regressionlist = list(set(regressionlist + regression)) #add and dedupe

    logging.info("Found %s regression-wanted in %s components." % (len(regressionlist), (len(option_sets)))) 

    return ( buglist, stepslist, regressionlist ) 
示例#23
0
def initializeSession():
    if 'initialized' not in session.keys():
        session['initialized'] = True
        session['bmo'] = BMOAgent('', '')
        session['vt'] = VersionTracker()
示例#24
0
    
    d["include_fields"] = "_default, attachments, history"

    return d

if __name__ == '__main__':

    query = sys.argv[1]
    
    if query == None:
        sys.exit("Please specify a query")
    
    username, password = get_credentials()
    
    # Load our agent for BMO
    bmo = BMOAgent(username, password)
    
    # Get the buglist(s)
    # import the query
    buglist = []

    if os.path.exists(query):
        info = {}
        execfile(query, info)
        query_name = info['query_name']
        if info.has_key('query_url'):
            buglist = bmo.get_bug_list(query_url_to_dict(info['query_url'])) 
        else:
            print "Error - no valid query params or url in the config file"
            sys.exit(1)
    else:
示例#25
0
def nagEmailScript():
    print "*******In nagEmailScript"
    email_cc_list=['*****@*****.**']
    print "*******In nagEmailScript2"
    # Load our agent for BMO
    username = flask.session['username']
    print "*******In nagEmailScript", username
    password = flask.session['password']
    print "*******In nagEmailScript", password
    print "\n\nbefore bmo"
    bmo = BMOAgent(username, password)
    people = flask.session["people"]
    queries = flask.session['queries'] 
    print "\n\nafter BMO"
    # Get the buglist(s)
    collected_queries = {}
    print queries
    for query in queries:
    # import the query
        print "*****",query
        query_name = query['query_name']
        print "\nquery_name\n",query_name
        print "\nquery_channel\n",query['query_channel']
        collected_queries[query_name] = {
            'channel': query['query_channel'],
            'bugs' : [],
            }
        print "\n\nafter import query"
        if query.has_key('query_params'):
            print "Gathering bugs from query_params in %s" % query
            collected_queries[query_name]['bugs'] = bmo.get_bug_list(query['query_params'])
        elif query.has_key('query_url'):
            print "Gathering bugs from query_url in %s" % query
            collected_queries[query_name]['bugs'] = bmo.get_bug_list(query_url_to_dict(query['query_url'])) 
        else:
            raise Exception("Error - no valid query params or url in the config file")
            
    print "After collected queries",   collected_queries  
    total_bugs = 0
    for channel in collected_queries.keys():
        total_bugs += len(collected_queries[channel]['bugs'])

    print "Found %s bugs total for %s queries" % (total_bugs, len(collected_queries.keys()))
    print "Queries to collect: %s" % collected_queries.keys()
    managers = people.managers
    manual_notify = []
    counter = 0
    print "\najajajakakka"
    
    def add_to_managers(manager_email, query):
        if managers[manager_email].has_key('nagging'):
            if managers[manager_email]['nagging'].has_key(query):
                managers[manager_email]['nagging'][query]['bugs'].append(bug)
                print "Adding %s to %s in nagging for %s" % (bug.id, query, manager_email)
            else:
                managers[manager_email]['nagging'][query] = { 'bugs': [bug] }
                print "Adding new query key %s for bug %s in nagging and %s" % (query, bug.id, manager_email)
        else:
            managers[manager_email]['nagging'] = {
                    query : { 'bugs': [bug] },
                }
            print "Creating query key %s for bug %s in nagging and %s" % (query, bug.id, manager_email)
    
  
    verbose = False
    for query in collected_queries.keys():
        print "\nBNBNBNNBN\n"
        
        for b in collected_queries[query]['bugs']:
            if verbose:
                print "\nb::::",b
            counter = counter + 1
            send_mail = True
            bug = bmo.get_bug(b.id)
            if verbose:
                print "\nYYYYYYYYYYYYYYYYYYYYY210\n"
            manual_notify.append(bug)
            assignee = bug.assigned_to.name
            if people.people_by_bzmail.has_key(assignee):
                person = dict(people.people_by_bzmail[assignee])
            else:
                person = None
            if verbose:
                print "\nYYYYYYYYYYYYYYYYYYYYY217\n"
            if send_mail:
                if verbose:
                    print "\nYYYYYYYYYYYYYYYYYYYYY219\n"
                if 'nobody' in assignee:
                    assignee = None
                # TODO - get rid of this, SUCH A HACK!
                elif '*****@*****.**' in assignee:
                    print "No one assigned to JS bug: %s, adding to dmandelin's list..." % bug.id
                    add_to_managers('*****@*****.**', query)
                else:
                    if bug.assigned_to.real_name != None:
                        if person != None:
                            # check if assignee is already a manager, add to their own list
                            if managers.has_key(person['mozillaMail']):
                                add_to_managers(person['mozillaMail'], query)
                            # otherwise we search for the assignee's manager
                            else:
                                # check for manager key first, a few people don't have them
                                if person.has_key('manager') and person['manager'] != None:
                                    manager_email = person['manager']['dn'].split('mail=')[1].split(',')[0]
                                    if managers.has_key(manager_email):
                                        add_to_managers(manager_email, query)
                                    elif people.vices.has_key(manager_email):
                                        # we're already at the highest level we'll go
                                        if managers.has_key(assignee):
                                            add_to_managers(assignee, query)
                                        else:
                                            managers[person['mozillaMail']] = {}
                                            add_to_managers(person['mozillaMail'], query)
                                    else:
                                        # try to go up one level and see if we find a manager
                                        if people.people.has_key(manager_email):
                                            person = dict(people.people[manager_email])
                                            manager_email = person['manager']['dn'].split('mail=')[1].split(',')[0]
                                            if managers.has_key(manager_email):
                                                add_to_managers(manager_email, query)
                                        else:
                                            print "Manager could not be found: %s" % manager_email
                                else:
                                    print "%s's entry doesn't list a manager! Let's ask them to update phonebook." % person['name']
                                    
    flask.session['manual_notify'] = manual_notify
    flask.session['managers'] = managers
    flask.session["counter"] = counter
    flask.session['total_bugs'] = total_bugs
示例#26
0
文件: bznag.py 项目: mhoye/Canutist
def findbugs(cfg,recs):

    server = cfg["server"].encode("utf8")
    owner = cfg["owner"].encode("utf8")
    user =  cfg["user"]
    password =  cfg["password"]

    try:
        bzagent = BMOAgent(user,password)
        logging.info("Connected to " + str(server) )
    except:
        logging.info("Failed to connect to " + str(server))
        exit(-1)

    notif = dict() # key = intended recipient, value = list of bugs

    for ppl in recs.keys():

        buglist = list()
    # For each person, get the bugs have aged untouched to their level.
    # I'm making a design decision here to make this range window only
    # 2 days long - bugs older than that are being actively ignored.

        sla = recs[ppl]
        print str(ppl) + " " + str(sla)
        inc = 1

    # If it's a Monday, scan the last three days. Otherwise only the last one.
    # The cron job that kicks off this clownshow should only be running mon/fri.

        if (date.today().weekday() == 0):
            inc = 3
        week_inc = inc + 5
        date_to    = str(date.isoformat(date.today() - timedelta(sla + 1) )).encode("utf8")
        date_from  = str(date.isoformat(date.today() - timedelta(sla + inc + 1) )).encode("utf8")
        stale_time = str(date.isoformat(date.today() - timedelta(sla + week_inc + inc + 1) )).encode("utf8")

        print str("Stale date:") + str(stale_time)
    # Not proud of this next part. Store this properly in a file somewhere, you donkus.

        untriaged_bugs = list()

        untriaged_params= {
             'firefox_untriaged': {
                 'changed_field':'[Bug creation]',
                 'changed_after':date_from,
                 'changed_before':date_to,
                 'product':  'Firefox',
                 'component':'Untriaged'},
             'core_untriaged': {
                 'changed_field':'[Bug creation]',
                 'changed_after':date_from,
                 'changed_before':date_to,
                 'product':  'Toolkit',
                 'component':'Untriaged'},
             'toolkit_untriaged': {
                 'changed_field':'[Bug creation]',
                 'changed_after':date_from,
                 'changed_before':date_to,
                 'product':  'Core',
                 'component':'Untriaged' }
              }

        bugs = set()
        for options in untriaged_params.values():
            for b in bzagent.get_bug_list(options):
                if str(b.creation_time) == str(b.last_change_time):
                    bugs.add(b)
                    print "Untriaged:" + str(b.id) + " - " + str(b.creation_time) + " - " + str(b.last_change_time)

        untriaged_bugs = list(bugs) #add and dedupe

        stale_bugs = list()
        stale_params = {
            "firefox_stale_bug": {
                "product":  "Core",
                "bug_status": "UNCONFIRMED,NEW,ASSIGNED",
                "component":"Untriaged" },
            "core_stale_bug": {
                "bug_status": "UNCONFIRMED,NEW,ASSIGNED",
                "product":  "Core",
                "component":"Untriaged" },
            "toolkit_stale_bug": {
                "product":  "Core",
                "bug_status": "UNCONFIRMED,NEW,ASSIGNED",
                "component":"Untriaged" }
            }

        bugs = set()

        # juuuust subtly different.
        for options in stale_params.values():
            for b in bzagent.get_bug_list(options):
                if str(b.creation_time) == stale_time:
                    bugs.add(b)
                    print "Stale:" + str(b.id) + " - " + str(b.last_change_time)

        stale_bugs = list(bugs) # (this is so sloppy)


        notif[ppl] = { "untriaged": untriaged_bugs, "stale": stale_bugs }

    return ( notif )