Пример #1
0
def is_component_maintainer(db, user, component):
    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and user is not None:
        if user.admin or user.privileged or user_is_maintainer(
                db, user.username, component.id):
            is_maintainer = True
    return is_maintainer
Пример #2
0
Файл: utils.py Проект: abrt/faf
def is_component_maintainer(db, user, component):
    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and user is not None:
        if (user.admin
                or user.privileged
                or queries.user_is_maintainer(db, user.username, component.id)):
            is_maintainer = True
    return is_maintainer
Пример #3
0
def is_problem_maintainer(db, user, problem):
    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and user is not None:
        if user.admin or user.privileged:
            is_maintainer = True
        else:
            component_ids = set(c.id for c in problem.components)
            if any(user_is_maintainer(db, user.username, component_id)
                   for component_id in component_ids):
                is_maintainer = True
    return is_maintainer
Пример #4
0
def is_problem_maintainer(db, user, problem):
    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and user is not None:
        if user.admin or user.privileged:
            is_maintainer = True
        else:
            component_ids = set(c.id for c in problem.components)
            if any(
                    user_is_maintainer(db, user.username, component_id)
                    for component_id in component_ids):
                is_maintainer = True
    return is_maintainer
Пример #5
0
def associate_bug(report_id):
    result = (db.session.query(Report,
                               OpSysComponent).join(OpSysComponent).filter(
                                   Report.id == report_id).first())

    if result is None:
        abort(404)

    report, component = result

    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and g.user is not None:
        if user_is_maintainer(db, g.user.username, component.id):
            is_maintainer = True

    if not is_maintainer:
        flash("You are not the maintainer of this component.", "danger")
        return redirect(url_for("reports.item", report_id=report_id))

    form = AssociateBzForm(request.form)
    if request.method == "POST" and form.validate():
        bug_id = form.bug_id.data

        reportbug = (db.session.query(
            ReportBz).filter((ReportBz.report_id == report.id)
                             & (ReportBz.bzbug_id == bug_id)).first())

        if reportbug:
            flash("Bug already associated.", "danger")
        else:
            bug = get_bz_bug(db, bug_id)
            if not bug:
                tracker = bugtrackers[form.bugtracker.data]

                try:
                    bug = tracker.download_bug_to_storage_no_retry(db, bug_id)
                except Exception as e:
                    flash("Failed to fetch bug. {0}".format(str(e)), "danger")
                    raise

            if bug:
                new = ReportBz()
                new.report = report
                new.bzbug = bug
                db.session.add(new)
                db.session.flush()
                db.session.commit()

                flash("Bug successfully associated.", "success")
                return redirect(url_for("reports.item", report_id=report_id))
            else:
                flash("Failed to fetch bug.", "danger")

    bthash_url = url_for("reports.bthash_forward",
                         bthash=report.hashes[0].hash,
                         _external=True)
    new_bug_params = {
        "component":
        component.name,
        "short_desc":
        "[abrt] [faf] {0}: {1}(): {2} killed by {3}".format(
            component.name, report.crash_function,
            ",".join(exe.path for exe in report.executables), report.errname),
        "comment":
        "This bug has been created based on an anonymous crash "
        "report requested by the package maintainer.\n\n"
        "Report URL: {0}".format(bthash_url),
        "bug_file_loc":
        bthash_url
    }

    new_bug_urls = []
    for rosr in report.opsysreleases:
        osr = rosr.opsysrelease
        for bugtracker in bugtrackers.keys():
            try:
                params = new_bug_params.copy()
                if osr.opsys.name.startswith("Red Hat"):
                    params.update(product="{0} {1}".format(
                        osr.opsys.name, osr.version[0]),
                                  version=osr.version)
                else:
                    params.update(product=osr.opsys.name, version=osr.version)
                print(params)
                new_bug_urls.append(
                    ("{0} {1} in {2}".format(osr.opsys.name, osr.version,
                                             bugtracker),
                     "{0}?{1}".format(bugtrackers[bugtracker].new_bug_url,
                                      urllib.urlencode(params))))
            except:
                pass

    return render_template("reports/associate_bug.html",
                           form=form,
                           report=report,
                           new_bug_urls=new_bug_urls)
Пример #6
0
def item(report_id):
    result = (db.session.query(Report,
                               OpSysComponent).join(OpSysComponent).filter(
                                   Report.id == report_id).first())

    if result is None:
        abort(404)

    report, component = result

    releases = (db.session.query(
        ReportOpSysRelease, ReportOpSysRelease.count).filter(
            ReportOpSysRelease.report_id == report_id).order_by(
                desc(ReportOpSysRelease.count)).all())

    arches = (db.session.query(
        ReportArch,
        ReportArch.count).filter(ReportArch.report_id == report_id).order_by(
            desc(ReportArch.count)).all())

    modes = (db.session.query(
        ReportSelinuxMode, ReportSelinuxMode.count).filter(
            ReportSelinuxMode.report_id == report_id).order_by(
                desc(ReportSelinuxMode.count)).all())

    history_select = lambda table: (db.session.query(table).filter(
        table.report_id == report_id).all())

    daily_history = history_select(ReportHistoryDaily)
    weekly_history = history_select(ReportHistoryWeekly)
    monthly_history = history_select(ReportHistoryMonthly)

    packages = load_packages(db, report_id)

    # creates a package_counts list with this structure:
    # [(package name, count, [(package version, count in the version)])]
    names = defaultdict(lambda: {"count": 0, "versions": defaultdict(int)})
    for pkg in packages:
        names[pkg.iname]["name"] = pkg.iname
        names[pkg.iname]["count"] += pkg.count
        names[pkg.iname]["versions"]["{0}:{1}-{2}".format(
            pkg.iepoch, pkg.iversion, pkg.irelease)] += pkg.count

    package_counts = []
    for pkg in sorted(names.values(), key=itemgetter("count"), reverse=True):
        package_counts.append((pkg["name"], pkg["count"],
                               sorted(pkg["versions"].items(),
                                      key=itemgetter(1),
                                      reverse=True)))

    try:
        backtrace = report.backtraces[0].frames
    except:
        backtrace = []

    fid = 0
    for frame in backtrace:
        fid += 1
        frame.nice_order = fid

    contact_emails = []
    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and g.user is not None:
        if user_is_maintainer(db, g.user.username, component.id):
            is_maintainer = True
    if is_maintainer:
        contact_emails = [
            email_address for (email_address, ) in (db.session.query(
                ContactEmail.email_address).join(ReportContactEmail).filter(
                    ReportContactEmail.report == report))
        ]

    forward = dict(report=report,
                   component=component,
                   releases=metric(releases),
                   arches=metric(arches),
                   modes=metric(modes),
                   daily_history=daily_history,
                   weekly_history=weekly_history,
                   monthly_history=monthly_history,
                   crashed_packages=packages,
                   package_counts=package_counts,
                   backtrace=backtrace,
                   contact_emails=contact_emails)

    if request_wants_json():
        return jsonify(forward)

    forward["is_maintainer"] = is_maintainer
    forward["extfafs"] = get_external_faf_instances(db)
    return render_template("reports/item.html", **forward)
Пример #7
0
def associate_bug(report_id):
    result = (db.session.query(Report, OpSysComponent)
              .join(OpSysComponent)
              .filter(Report.id == report_id)
              .first())

    if result is None:
        abort(404)

    report, component = result

    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and g.user is not None:
        if user_is_maintainer(db, g.user.username, component.id):
            is_maintainer = True

    if not is_maintainer:
        flash("You are not the maintainer of this component.", "danger")
        return redirect(url_for("reports.item", report_id=report_id))

    form = AssociateBzForm(request.form)
    if request.method == "POST" and form.validate():
        bug_id = form.bug_id.data

        reportbug = (db.session.query(ReportBz)
                     .filter(
                         (ReportBz.report_id == report.id) &
                         (ReportBz.bzbug_id == bug_id))
                     .first())

        if reportbug:
            flash("Bug already associated.", "danger")
        else:
            bug = get_bz_bug(db, bug_id)
            if not bug:
                tracker = bugtrackers[form.bugtracker.data]

                try:
                    bug = tracker.download_bug_to_storage_no_retry(db, bug_id)
                except Exception as e:
                    flash("Failed to fetch bug. {0}".format(str(e)), "danger")
                    raise

            if bug:
                new = ReportBz()
                new.report = report
                new.bzbug = bug
                db.session.add(new)
                db.session.flush()
                db.session.commit()

                flash("Bug successfully associated.", "success")
                return redirect(url_for("reports.item", report_id=report_id))
            else:
                flash("Failed to fetch bug.", "danger")

    bthash_url = url_for("reports.bthash_forward",
                         bthash=report.hashes[0].hash,
                         _external=True)
    new_bug_params = {
        "component": component.name,
        "short_desc": "[abrt] [faf] {0}: {1}(): {2} killed by {3}"
                      .format(component.name,
                              report.crash_function,
                              ",".join(exe.path for exe in report.executables),
                              report.errname
                              ),
        "comment": "This bug has been created based on an anonymous crash "
                   "report requested by the package maintainer.\n\n"
                   "Report URL: {0}"
                   .format(bthash_url),
        "bug_file_loc": bthash_url
    }

    new_bug_urls = []
    for rosr in report.opsysreleases:
        osr = rosr.opsysrelease
        for bugtracker in bugtrackers.keys():
            try:
                params = new_bug_params.copy()
                if osr.opsys.name.startswith("Red Hat"):
                    params.update(product="{0} {1}".format(osr.opsys.name,
                                                           osr.version[0]),
                                  version=osr.version)
                else:
                    params.update(product=osr.opsys.name, version=osr.version)
                print(params)
                new_bug_urls.append(
                    ("{0} {1} in {2}".format(osr.opsys.name, osr.version,
                                             bugtracker),
                     "{0}?{1}".format(
                        bugtrackers[bugtracker].new_bug_url,
                        urllib.urlencode(params))
                     )
                )
            except:
                pass

    return render_template("reports/associate_bug.html",
                           form=form,
                           report=report,
                           new_bug_urls=new_bug_urls)
Пример #8
0
def item(report_id):
    result = (db.session.query(Report, OpSysComponent)
              .join(OpSysComponent)
              .filter(Report.id == report_id)
              .first())

    if result is None:
        abort(404)

    report, component = result

    releases = (db.session.query(ReportOpSysRelease, ReportOpSysRelease.count)
                .filter(ReportOpSysRelease.report_id == report_id)
                .order_by(desc(ReportOpSysRelease.count))
                .all())

    arches = (db.session.query(ReportArch, ReportArch.count)
              .filter(ReportArch.report_id == report_id)
              .order_by(desc(ReportArch.count))
              .all())

    modes = (db.session.query(ReportSelinuxMode, ReportSelinuxMode.count)
             .filter(ReportSelinuxMode.report_id == report_id)
             .order_by(desc(ReportSelinuxMode.count))
             .all())

    history_select = lambda table: (db.session.query(table).
                                    filter(table.report_id == report_id)
                                    .all())

    daily_history = history_select(ReportHistoryDaily)
    weekly_history = history_select(ReportHistoryWeekly)
    monthly_history = history_select(ReportHistoryMonthly)

    packages = load_packages(db, report_id)

    # creates a package_counts list with this structure:
    # [(package name, count, [(package version, count in the version)])]
    names = defaultdict(lambda: {"count": 0, "versions": defaultdict(int)})
    for pkg in packages:
        names[pkg.iname]["name"] = pkg.iname
        names[pkg.iname]["count"] += pkg.count
        names[pkg.iname]["versions"]["{0}:{1}-{2}"
            .format(pkg.iepoch, pkg.iversion, pkg.irelease)] += pkg.count

    package_counts = []
    for pkg in sorted(names.values(), key=itemgetter("count"), reverse=True):
        package_counts.append((
            pkg["name"],
            pkg["count"],
            sorted(pkg["versions"].items(), key=itemgetter(1), reverse=True)))

    try:
        backtrace = report.backtraces[0].frames
    except:
        backtrace = []

    fid = 0
    for frame in backtrace:
        fid += 1
        frame.nice_order = fid

    contact_emails = []
    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and g.user is not None:
        if user_is_maintainer(db, g.user.username, component.id):
            is_maintainer = True
    if is_maintainer:
        contact_emails = [email_address for (email_address, ) in
                          (db.session.query(ContactEmail.email_address)
                                     .join(ReportContactEmail)
                                     .filter(ReportContactEmail.report == report))]

    forward = dict(report=report,
                   component=component,
                   releases=metric(releases),
                   arches=metric(arches),
                   modes=metric(modes),
                   daily_history=daily_history,
                   weekly_history=weekly_history,
                   monthly_history=monthly_history,
                   crashed_packages=packages,
                   package_counts=package_counts,
                   backtrace=backtrace,
                   contact_emails=contact_emails)

    if request_wants_json():
        return jsonify(forward)

    forward["is_maintainer"] = is_maintainer
    forward["extfafs"] = get_external_faf_instances(db)
    return render_template("reports/item.html", **forward)
Пример #9
0
def item(problem_id):
    problem = db.session.query(Problem).filter(
        Problem.id == problem_id).first()

    if problem is None:
        raise abort(404)

    report_ids = [report.id for report in problem.reports]

    sub = (db.session.query(
        ReportOpSysRelease.opsysrelease_id,
        func.sum(ReportOpSysRelease.count).label("cnt")).join(Report).filter(
            Report.id.in_(report_ids)).group_by(
                ReportOpSysRelease.opsysrelease_id).subquery())

    osreleases = (db.session.query(OpSysRelease, sub.c.cnt).join(sub).order_by(
        desc("cnt")).all())

    sub = (db.session.query(
        ReportArch.arch_id,
        func.sum(ReportArch.count).label("cnt")).join(Report).filter(
            Report.id.in_(report_ids)).group_by(ReportArch.arch_id).subquery())

    arches = (db.session.query(Arch, sub.c.cnt).join(sub).order_by(
        desc("cnt")).all())

    exes = (db.session.query(
        ReportExecutable.path,
        func.sum(ReportExecutable.count).label("cnt")).join(Report).filter(
            Report.id.in_(report_ids)).group_by(
                ReportExecutable.path).order_by(desc("cnt")).all())

    sub = (db.session.query(
        ReportPackage.installed_package_id,
        func.sum(ReportPackage.count).label("cnt")).join(Report).filter(
            Report.id.in_(report_ids)).group_by(
                ReportPackage.installed_package_id).subquery())
    packages_known = db.session.query(Package, sub.c.cnt).join(sub).all()

    packages_unknown = (db.session.query(
        ReportUnknownPackage, ReportUnknownPackage.count).join(Report).filter(
            Report.id.in_(report_ids))).all()

    packages = packages_known + packages_unknown

    # creates a package_counts list with this structure:
    # [(package name, count, [(package version, count in the version)])]
    names = defaultdict(lambda: {"count": 0, "versions": defaultdict(int)})
    for (pkg, cnt) in packages:
        names[pkg.name]["name"] = pkg.name
        names[pkg.name]["count"] += cnt
        names[pkg.name]["versions"][pkg.evr()] += cnt

    package_counts = []
    for pkg in sorted(names.values(), key=itemgetter("count"), reverse=True):
        package_counts.append((pkg["name"], pkg["count"],
                               sorted(pkg["versions"].items(),
                                      key=itemgetter(1),
                                      reverse=True)))

    for report in problem.reports:
        for backtrace in report.backtraces:
            fid = 0
            for frame in backtrace.frames:
                fid += 1
                frame.nice_order = fid

    bt_hashes = (db.session.query(
        ReportHash.hash).join(Report).join(Problem).filter(
            Problem.id == problem_id).distinct(ReportHash.hash).all())
    # Limit to 10 bt_hashes (otherwise the URL can get too long)
    # Select the 10 hashes uniformly from the entire list to make sure it is a
    # good representation. (Slicing the 10 first could mean the 10 oldest
    # are selected which is not a good representation.)
    k = min(len(bt_hashes), 10)
    a = 0
    d = len(bt_hashes) / float(k)
    bt_hashes_limited = []
    for i in range(k):
        bt_hashes_limited.append("bth=" + bt_hashes[int(a)][0])
        a += d
    bt_hash_qs = "&".join(bt_hashes_limited)

    forward = {
        "problem": problem,
        "osreleases": metric(osreleases),
        "arches": metric(arches),
        "exes": metric(exes),
        "package_counts": package_counts,
        "bt_hash_qs": bt_hash_qs
    }

    if request_wants_json():
        return jsonify(forward)

    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and g.user is not None:
        component_ids = set(c.id for c in problem.components)
        if any(
                user_is_maintainer(db, g.user.username, component_id)
                for component_id in component_ids):
            is_maintainer = True
    forward["is_maintainer"] = is_maintainer

    forward["extfafs"] = get_external_faf_instances(db)

    if report_ids:
        bt_diff_form = BacktraceDiffForm()
        bt_diff_form.lhs.choices = [(id, id) for id in report_ids]
        bt_diff_form.rhs.choices = bt_diff_form.lhs.choices
        forward['bt_diff_form'] = bt_diff_form

    return render_template("problems/item.html", **forward)
Пример #10
0
def item(problem_id):
    problem = db.session.query(Problem).filter(
        Problem.id == problem_id).first()

    if problem is None:
        raise abort(404)

    report_ids = [report.id for report in problem.reports]

    sub = (db.session.query(ReportOpSysRelease.opsysrelease_id,
                            func.sum(ReportOpSysRelease.count).label("cnt"))
           .join(Report)
           .filter(Report.id.in_(report_ids))
           .group_by(ReportOpSysRelease.opsysrelease_id)
           .subquery())

    osreleases = (db.session.query(OpSysRelease, sub.c.cnt)
                            .join(sub)
                            .order_by(desc("cnt"))
                            .all())

    sub = (db.session.query(ReportArch.arch_id,
                            func.sum(ReportArch.count).label("cnt"))
           .join(Report)
           .filter(Report.id.in_(report_ids))
           .group_by(ReportArch.arch_id)
           .subquery())

    arches = (db.session.query(Arch, sub.c.cnt).join(sub)
                        .order_by(desc("cnt"))
                        .all())

    exes = (db.session.query(ReportExecutable.path,
                             func.sum(ReportExecutable.count).label("cnt"))
            .join(Report)
            .filter(Report.id.in_(report_ids))
            .group_by(ReportExecutable.path)
            .order_by(desc("cnt"))
            .all())

    sub = (db.session.query(ReportPackage.installed_package_id,
                            func.sum(ReportPackage.count).label("cnt"))
           .join(Report)
           .filter(Report.id.in_(report_ids))
           .group_by(ReportPackage.installed_package_id)
           .subquery())
    packages_known = db.session.query(Package, sub.c.cnt).join(sub).all()

    packages_unknown = (db.session.query(ReportUnknownPackage,
                                         ReportUnknownPackage.count)
                                  .join(Report)
                                  .filter(Report.id.in_(report_ids))).all()

    packages = packages_known + packages_unknown

    # creates a package_counts list with this structure:
    # [(package name, count, [(package version, count in the version)])]
    names = defaultdict(lambda: {"count": 0, "versions": defaultdict(int)})
    for (pkg, cnt) in packages:
        names[pkg.name]["name"] = pkg.name
        names[pkg.name]["count"] += cnt
        names[pkg.name]["versions"][pkg.evr()] += cnt

    package_counts = []
    for pkg in sorted(names.values(), key=itemgetter("count"), reverse=True):
        package_counts.append((
            pkg["name"],
            pkg["count"],
            sorted(pkg["versions"].items(), key=itemgetter(1), reverse=True)))

    for report in problem.reports:
        for backtrace in report.backtraces:
            fid = 0
            for frame in backtrace.frames:
                fid += 1
                frame.nice_order = fid

    bt_hashes = (db.session.query(ReportHash.hash)
                           .join(Report)
                           .join(Problem)
                           .filter(Problem.id == problem_id)
                           .distinct(ReportHash.hash).all())
    # Limit to 10 bt_hashes (otherwise the URL can get too long)
    # Select the 10 hashes uniformly from the entire list to make sure it is a
    # good representation. (Slicing the 10 first could mean the 10 oldest
    # are selected which is not a good representation.)
    k = min(len(bt_hashes), 10)
    a = 0
    d = len(bt_hashes)/float(k)
    bt_hashes_limited = []
    for i in range(k):
        bt_hashes_limited.append("bth=" + bt_hashes[int(a)][0])
        a += d
    bt_hash_qs = "&".join(bt_hashes_limited)

    forward = {"problem": problem,
               "osreleases": metric(osreleases),
               "arches": metric(arches),
               "exes": metric(exes),
               "package_counts": package_counts,
               "bt_hash_qs": bt_hash_qs
               }

    if request_wants_json():
        return jsonify(forward)

    is_maintainer = app.config["EVERYONE_IS_MAINTAINER"]
    if not is_maintainer and g.user is not None:
        component_ids = set(c.id for c in problem.components)
        if any(user_is_maintainer(db, g.user.username, component_id)
               for component_id in component_ids):
            is_maintainer = True
    forward["is_maintainer"] = is_maintainer

    forward["extfafs"] = get_external_faf_instances(db)

    if report_ids:
        bt_diff_form = BacktraceDiffForm()
        bt_diff_form.lhs.choices = [(id, id) for id in report_ids]
        bt_diff_form.rhs.choices = bt_diff_form.lhs.choices
        forward['bt_diff_form'] = bt_diff_form

    return render_template("problems/item.html", **forward)