Exemplo n.º 1
0
    def test_problem_json(self):
        problem = get_problem_by_id(self.db, 1)

        build = Build()
        build.base_package_name = "kernel"
        build.epoch = 0
        build.version = "3.12.10"
        build.release = "301.fc20"
        self.db.session.add(build)

        release = ProblemOpSysRelease()
        release.opsysrelease = get_releases(self.db, 'Fedora', '20').first()
        release.probable_fix_build = build
        release.problem = problem
        self.db.session.add(release)

        problem.reports[0].max_certainty = 99

        self.db.session.commit()

        response = self.app.get('/problems/%d/' % problem.id,
                                headers=([('Accept', 'application/json')]))

        self.assertEqual(response.mimetype, "application/json")

        data = json.loads(response.get_data(as_text=True))

        self.assertIn("solutions", data)
        self.assertEqual(len(data["solutions"]), 1)
        self.assertIn("note_text", data["solutions"][0])
        self.assertIn("%s-%s" % (build.version, build.release),
                      data["solutions"][0]["note_text"])
Exemplo n.º 2
0
def by_daterange(since, to):
    '''
    Render date-based report statistics including reports `since` date
    until `to` date.
    '''

    try:
        if isinstance(since, str) or isinstance(since, unicode):
            since = datetime.datetime.strptime(since, "%Y-%m-%d").date()

        if isinstance(to, str) or isinstance(to, unicode):
            to = datetime.datetime.strptime(to, "%Y-%m-%d").date()
    except:
        return abort(400)

    since = min(since, to)
    to = max(since, to)

    history = 'daily'
    day_count = (to - since).days
    if day_count > 30:
        history = 'weekly'
    if day_count > 360:
        history = 'monthly'

    def date_filter(query):
        return query.filter(hist_field >= since).filter(hist_field < to)

    hist_table, hist_field = queries.get_history_target(history)
    total_query = queries.get_history_sum(db, history=history)
    total = date_filter(total_query).one()[0]

    release_data = []

    for release in queries.get_releases(db):
        release_sum = queries.get_history_sum(db,
                                              release.opsys.name,
                                              release.version,
                                              history=history)

        release_sum = date_filter(release_sum).one()[0]
        if not release_sum:
            continue

        percentage = int(release_sum * 100.0 / total)

        comps = queries.get_report_count_by_component(db,
                                                      release.opsys.name,
                                                      release.version,
                                                      history=history)

        comp_data = []
        for comp, count in date_filter(comps).all():
            comp_percentage = int(count * 100.0 / release_sum)
            comp_data.append((comp, count, comp_percentage))

        release_data.append({
            'release': release,
            'sum': release_sum,
            'comps': comp_data,
            'percentage': percentage,
        })

    data = {
        'since': since,
        'to': to,
        'total': total,
        'releases': sorted(release_data, key=lambda x: x['sum'], reverse=True),
    }

    if request_wants_json():
        return jsonify(data)

    return render_template("stats/by_date.html", **data)
Exemplo n.º 3
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases if
                          release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error("Operating system '{0}' is not installed"
                               .format(shortname))
                return 1

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_error("Operating system '{0}' is not initialized"
                               .format(shortname))
                return 1

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            for shortname in cmdline.opsys:
                if shortname not in systems:
                    self.log_warn("Operating system '{0}' is not installed"
                                  .format(shortname))
                    continue

                opsys = systems[shortname]
                db_opsys = get_opsys_by_name(db, opsys.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not initialized"
                                  .format(shortname))
                    continue

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

            self.log_info("[{0} / {1}] Processing {2} {3}"
                          .format(i, len(tasks), opsys.nice_name,
                                  db_release.version))

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(db_release.components), name))

                acls = opsys.get_component_acls(name,
                                                release=db_release.version)
                k = 0
                for associate in acls:
                    k += 1
                    self.log_debug("    [{0} / {1}] Processing associate '{2}'"
                                   .format(k, len(acls), associate))

                    db_associate = get_associate_by_name(db, associate)
                    if db_associate is None:
                        if associate in new_associates:
                            db_associate = new_associates[associate]
                        else:
                            db_associate = AssociatePeople()
                            db_associate.name = associate
                            db.session.add(db_associate)
                            new_associates[associate] = db_associate

                            self.log_info("Adding a new associate '{0}'"
                                          .format(associate))

                    associates = [a.associates for a in db_component.associates]
                    if db_associate not in associates:
                        db_associate_comp = OpSysReleaseComponentAssociate()
                        db_associate_comp.component = db_component
                        db_associate_comp.associates = db_associate
                        db.session.add(db_associate_comp)

                        self.log_info("Assigning associate '{0}' to component "
                                      "'{1}'".format(associate, name))

                db.session.flush()
Exemplo n.º 4
0
def by_daterange(request,
                 since,
                 to,
                 template_name='stats/by_date.html',
                 extra_context={}):
    '''
    Render date-based report statistics including reports `since` date
    until `to` date.

    View accepts `template_name` to be used and `extra_context` to pass
    to it.
    '''

    if isinstance(since, str) or isinstance(since, unicode):
        since = datetime.datetime.strptime(since, "%Y-%m-%d").date()

    if isinstance(to, str) or isinstance(to, unicode):
        to = datetime.datetime.strptime(to, "%Y-%m-%d").date()

    db = pyfaf.storage.getDatabase()
    since = min(since, to)
    to = max(since, to)

    history = 'daily'
    day_count = (to - since).days
    if day_count > 30:
        history = 'weekly'
    if day_count > 360:
        history = 'monthly'

    def date_filter(query):
        return query.filter(hist_field >= since).filter(hist_field < to)

    hist_table, hist_field = queries.get_history_target(history)
    total_query = queries.get_history_sum(db, history=history)
    total = date_filter(total_query).one()[0]

    release_data = []

    for release in queries.get_releases(db):
        release_sum = queries.get_history_sum(db,
                                              release.opsys.name,
                                              release.version,
                                              history=history)

        release_sum = date_filter(release_sum).one()[0]
        if not release_sum:
            continue

        percentage = int(release_sum * 100.0 / total)

        comps = queries.get_report_count_by_component(db,
                                                      release.opsys.name,
                                                      release.version,
                                                      history=history)

        comp_data = []
        for comp, count in date_filter(comps).all():
            comp_percentage = int(count * 100.0 / release_sum)
            comp_data.append((comp, count, comp_percentage))

        release_data.append({
            'release': release,
            'sum': release_sum,
            'comps': comp_data,
            'percentage': percentage,
        })

    data = {
        'since': since,
        'to': to,
        'total': total,
        'releases': sorted(release_data, key=lambda x: x['sum'], reverse=True),
    }
    data.update(extra_context)

    if "application/json" in request.META.get("HTTP_ACCEPT"):
        return HttpResponse(json.dumps(data, cls=WebfafJSONEncoder),
                            status=200,
                            mimetype="application/json")
    else:
        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
Exemplo n.º 5
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases
                          if release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error(
                    "Operating system '{0}' is not installed".format(
                        shortname))
                return 1

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_error(
                    "Operating system '{0}' is not initialized".format(
                        shortname))
                return 1

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            for shortname in cmdline.opsys:
                if shortname not in systems:
                    self.log_warn(
                        "Operating system '{0}' is not installed".format(
                            shortname))
                    continue

                opsys = systems[shortname]
                db_opsys = get_opsys_by_name(db, opsys.nice_name)
                if db_opsys is None:
                    self.log_warn(
                        "Operating system '{0}' is not initialized".format(
                            shortname))
                    continue

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

            self.log_info("[{0} / {1}] Processing {2} {3}".format(
                i, len(tasks), opsys.nice_name, db_release.version))

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug(
                    "  [{0} / {1}] Processing component '{2}'".format(
                        j, len(db_release.components), name))
                try:
                    acls = opsys.get_component_acls(name,
                                                    release=db_release.version)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists = {"watchbugzilla": [], "commit": []}

                for associate in acls.keys():
                    for permission in acl_lists.keys():
                        if acls[associate].get(permission, False):
                            acl_lists[permission].append(associate)

                for permission in acl_lists.keys():
                    k = 0
                    for associate in acl_lists[permission]:
                        k += 1
                        self.log_debug(
                            "    [{0} / {1}] Processing associate '{2}' "
                            "permission {3}".format(k,
                                                    len(acl_lists[permission]),
                                                    associate, permission))

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info(
                                    "Adding a new associate '{0}'".format(
                                        associate))

                        associates = [
                            a.associates for a in db_component.associates
                            if a.permission == permission
                        ]
                        if db_associate not in associates:
                            db_associate_comp = OpSysReleaseComponentAssociate(
                            )
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info(
                                "Assigning associate '{0}' to component "
                                "'{1}' with permission {2}".format(
                                    associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                                and db_associate_comp.associates.name
                                not in acl_lists[permission]):
                            db.session.delete(db_associate_comp)
                            self.log_info(
                                "Removing associate '{0}' permission "
                                "{1} from component '{2}'".format(
                                    db_associate_comp.associates.name,
                                    permission, name))

                db.session.flush()
Exemplo n.º 6
0
Arquivo: stats.py Projeto: sorki/faf
def by_daterange(since, to):
    """
    Render date-based report statistics including reports `since` date
    until `to` date.
    """

    try:
        if isinstance(since, str) or isinstance(since, unicode):
            since = datetime.datetime.strptime(since, "%Y-%m-%d").date()

        if isinstance(to, str) or isinstance(to, unicode):
            to = datetime.datetime.strptime(to, "%Y-%m-%d").date()
    except:
        return abort(400)

    since = min(since, to)
    to = max(since, to)

    history = "daily"
    day_count = (to - since).days
    if day_count > 30:
        history = "weekly"
    if day_count > 360:
        history = "monthly"

    def date_filter(query):
        return query.filter(hist_field >= since).filter(hist_field < to)

    hist_table, hist_field = queries.get_history_target(history)
    total_query = queries.get_history_sum(db, history=history)
    total = date_filter(total_query).one()[0]

    release_data = []

    for release in queries.get_releases(db):
        release_sum = queries.get_history_sum(db, release.opsys.name, release.version, history=history)

        release_sum = date_filter(release_sum).one()[0]
        if not release_sum:
            continue

        percentage = int(release_sum * 100.0 / total)

        comps = queries.get_report_count_by_component(db, release.opsys.name, release.version, history=history)

        comp_data = []
        for comp, count in date_filter(comps).all():
            comp_percentage = int(count * 100.0 / release_sum)
            comp_data.append((comp, count, comp_percentage))

        release_data.append({"release": release, "sum": release_sum, "comps": comp_data, "percentage": percentage})

    data = {
        "since": since,
        "to": to,
        "total": total,
        "releases": sorted(release_data, key=lambda x: x["sum"], reverse=True),
    }

    if request_wants_json():
        return jsonify(data)

    return render_template("stats/by_date.html", **data)
Exemplo n.º 7
0
def by_daterange(request, since, to,
                 template_name='stats/by_date.html',
                 extra_context={}):
    '''
    Render date-based report statistics including reports `since` date
    until `to` date.

    View accepts `template_name` to be used and `extra_context` to pass
    to it.
    '''

    if isinstance(since, str) or isinstance(since, unicode):
        since = datetime.datetime.strptime(since, "%Y-%m-%d").date()

    if isinstance(to, str) or isinstance(to, unicode):
        to = datetime.datetime.strptime(to, "%Y-%m-%d").date()

    db = pyfaf.storage.getDatabase()
    since = min(since, to)
    to = max(since, to)

    history = 'daily'
    day_count = (to - since).days
    if day_count > 30:
        history = 'weekly'
    if day_count > 360:
        history = 'monthly'

    def date_filter(query):
        return query.filter(hist_field >= since).filter(hist_field < to)

    hist_table, hist_field = queries.get_history_target(history)
    total_query = queries.get_history_sum(db, history=history)
    total = date_filter(total_query).one()[0]

    release_data = []

    for release in queries.get_releases(db):
        release_sum = queries.get_history_sum(
            db, release.opsys.name, release.version, history=history)

        release_sum = date_filter(release_sum).one()[0]
        if not release_sum:
            continue

        percentage = int(release_sum * 100.0 / total)

        comps = queries.get_report_count_by_component(
            db, release.opsys.name, release.version, history=history)

        comp_data = []
        for comp, count in date_filter(comps).all():
            comp_percentage = int(count * 100.0 / release_sum)
            comp_data.append((comp, count, comp_percentage))

        release_data.append({
            'release': release,
            'sum': release_sum,
            'comps': comp_data,
            'percentage': percentage,
        })

    data = {
        'since': since,
        'to': to,
        'total': total,
        'releases': sorted(release_data, key=lambda x: x['sum'], reverse=True),
    }
    data.update(extra_context)

    if "application/json" in request.META.get("HTTP_ACCEPT"):
        return HttpResponse(json.dumps(data, cls=WebfafJSONEncoder),
                            status=200, mimetype="application/json")
    else:
        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
Exemplo n.º 8
0
Arquivo: stats.py Projeto: abrt/faf
def by_daterange(since, to):
    '''
    Render date-based report statistics including reports `since` date
    until `to` date.
    '''

    try:
        if isinstance(since, str):
            since = datetime.datetime.strptime(since, "%Y-%m-%d").date()

        if isinstance(to, str):
            to = datetime.datetime.strptime(to, "%Y-%m-%d").date()
    except: # pylint: disable=bare-except
        return abort(400)

    since = min(since, to)
    to = max(since, to)

    history = 'daily'
    day_count = (to - since).days
    if day_count > 30:
        history = 'weekly'
    if day_count > 360:
        history = 'monthly'

    def date_filter(query):
        return query.filter(hist_field >= since).filter(hist_field < to)

    _, hist_field = queries.get_history_target(history)
    total_query = queries.get_history_sum(db, history=history)
    total = date_filter(total_query).one()[0]

    release_data = []

    for release in queries.get_releases(db):
        release_sum = queries.get_history_sum(
            db, release.opsys.name, release.version, history=history)

        release_sum = date_filter(release_sum).one()[0]
        if not release_sum:
            continue

        percentage = int(release_sum * 100.0 / total)

        comps = queries.get_report_count_by_component(
            db, release.opsys.name, release.version, history=history)

        comp_data = []
        for comp, count in date_filter(comps).all():
            comp_percentage = int(count * 100.0 / release_sum)
            comp_data.append((comp, count, comp_percentage))

        release_data.append({
            'release': release,
            'sum': release_sum,
            'comps': comp_data,
            'percentage': percentage,
        })

    data = {
        'since': since,
        'to': to,
        'total': total,
        'releases': sorted(release_data, key=lambda x: x['sum'], reverse=True),
    }

    if request_wants_json():
        return jsonify(data)

    return render_template("stats/by_date.html", **data)
Exemplo n.º 9
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases if
                          release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error("Operating system '{0}' is not installed"
                               .format(shortname))
                return 1

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_error("Operating system '{0}' is not initialized"
                               .format(shortname))
                return 1

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            for shortname in cmdline.opsys:
                if shortname not in systems:
                    self.log_warn("Operating system '{0}' is not installed"
                                  .format(shortname))
                    continue

                opsys = systems[shortname]
                db_opsys = get_opsys_by_name(db, opsys.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not initialized"
                                  .format(shortname))
                    continue

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

            self.log_info("[{0} / {1}] Processing {2} {3}"
                          .format(i, len(tasks), opsys.nice_name,
                                  db_release.version))

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(db_release.components), name))
                try:
                    acls = opsys.get_component_acls(name,
                                                    release=db_release.version)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists = {
                    "watchbugzilla": [],
                    "commit": []
                }

                for associate in acls.keys():
                    for permission in acl_lists.keys():
                        if acls[associate].get(permission, False):
                            acl_lists[permission].append(associate)

                for permission in acl_lists.keys():
                    k = 0
                    for associate in acl_lists[permission]:
                        k += 1
                        self.log_debug("    [{0} / {1}] Processing associate '{2}' "
                                       "permission {3}"
                                       .format(k, len(acl_lists[permission]),
                                               associate, permission))

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info("Adding a new associate '{0}'"
                                              .format(associate))

                        associates = [a.associates for a in db_component.associates
                                      if a.permission == permission]
                        if db_associate not in associates:
                            db_associate_comp = OpSysReleaseComponentAssociate()
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info("Assigning associate '{0}' to component "
                                          "'{1}' with permission {2}"
                                          .format(associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                            and db_associate_comp.associates.name not in acl_lists[permission]):
                            db.session.delete(db_associate_comp)
                            self.log_info("Removing associate '{0}' permission "
                                          "{1} from component '{2}'"
                                          .format(db_associate_comp.associates.name,
                                                  permission, name))

                db.session.flush()