def copr_build_monitor(username, coprname): try: copr = coprs_logic.CoprsLogic.get( flask.g.user, username, coprname, with_mock_chroots=True).one() except sqlalchemy.orm.exc.NoResultFound: return page_not_found( "Copr with name {0} does not exist.".format(coprname)) form = forms.CoprLegalFlagForm() monitor = builds_logic.BuildsMonitorLogic.get_monitor_data(copr) md_chroots = monitor["chroots"] active_chroots = sorted( copr.active_chroots, key=lambda chroot: md_chroots.index(chroot.name) ) oses = [chroot.os for chroot in active_chroots] oses_grouped = [(len(list(group)), key) for key, group in groupby(oses)] archs = [chroot.arch for chroot in active_chroots] kwargs = dict(copr=copr, oses=oses_grouped, archs=archs, form=form) kwargs.update(monitor) kwargs["build"] = kwargs["latest_build"] del kwargs["latest_build"] return flask.render_template("coprs/detail/monitor.html", **kwargs)
def process_legal_flag(contact_info, copr): form = forms.CoprLegalFlagForm() legal_flag = models.LegalFlag(raise_message=form.comment.data, raised_on=int(time.time()), copr=copr, reporter=flask.g.user) db.session.add(legal_flag) db.session.commit() send_to = app.config["SEND_LEGAL_TO"] or ["root@localhost"] hostname = platform.node() navigate_to = "\nNavigate to http://{0}{1}".format( hostname, flask.url_for("admin_ns.legal_flag")) contact = "\nContact on owner is: {}".format(contact_info) reported_by = "\nReported by {0} <{1}>".format(flask.g.user.name, flask.g.user.mail) try: msg = MIMEText(form.comment.data + navigate_to + contact + reported_by, "plain") except UnicodeEncodeError: msg = MIMEText( form.comment.data.encode("utf-8") + navigate_to + contact + reported_by, "plain", "utf-8") msg["Subject"] = "Legal flag raised on {0}".format(copr.name) msg["From"] = "root@{0}".format(hostname) msg["To"] = ", ".join(send_to) s = smtplib.SMTP("localhost") s.sendmail("root@{0}".format(hostname), send_to, msg.as_string()) s.quit() flask.flash("Admin has been noticed about your report" " and will investigate the project shortly.") return flask.redirect(url_for_copr_details(copr))
def render_copr_detail(copr): repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr) form = forms.CoprLegalFlagForm() repos_info = {} for chroot in copr.active_chroots: chroot_rpms_dl_stat_key = CHROOT_RPMS_DL_STAT_FMT.format( copr_user=copr.owner_name, copr_project_name=copr.name, copr_chroot=chroot.name, ) chroot_rpms_dl_stat = TimedStatEvents.get_count( rconnect=rcp.get_connection(), name=chroot_rpms_dl_stat_key, ) logoset = set() logodir = app.static_folder + "/chroot_logodir" for logo in os.listdir(logodir): # glob.glob() uses listdir() and fnmatch anyways if fnmatch.fnmatch(logo, "*.png"): logoset.add(logo[:-4]) if chroot.name_release not in repos_info: logo = None if chroot.name_release in logoset: logo = chroot.name_release + ".png" elif chroot.os_release in logoset: logo = chroot.os_release + ".png" repos_info[chroot.name_release] = { "name_release": chroot.name_release, "os_release": chroot.os_release, "os_version": chroot.os_version, "logo": logo, "arch_list": [chroot.arch], "repo_file": "{}-{}.repo".format(copr.repo_id, chroot.name_release), "dl_stat": repo_dl_stat[chroot.name_release], "rpm_dl_stat": { chroot.arch: chroot_rpms_dl_stat } } else: repos_info[chroot.name_release]["arch_list"].append(chroot.arch) repos_info[chroot.name_release]["rpm_dl_stat"][ chroot.arch] = chroot_rpms_dl_stat repos_info_list = sorted(repos_info.values(), key=lambda rec: rec["name_release"]) builds = builds_logic.BuildsLogic.get_multiple_by_copr( copr=copr).limit(1).all() return flask.render_template( "coprs/detail/overview.html", copr=copr, user=flask.g.user, form=form, repo_dl_stat=repo_dl_stat, repos_info_list=repos_info_list, latest_build=builds[0] if len(builds) == 1 else None, )
def render_copr_detail(copr): repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr) form = forms.CoprLegalFlagForm() repos_info = {} for chroot in copr.active_chroots: # chroot_rpms_dl_stat_key = CHROOT_REPO_MD_DL_STAT_FMT.format( # copr_user=copr.owner.name, # copr_project_name=copr.name, # copr_chroot=chroot.name, # ) chroot_rpms_dl_stat_key = CHROOT_RPMS_DL_STAT_FMT.format( copr_user=copr.owner.name, copr_project_name=copr.name, copr_chroot=chroot.name, ) chroot_rpms_dl_stat = TimedStatEvents.get_count( rconnect=rcp.get_connection(), name=chroot_rpms_dl_stat_key, ) if chroot.name_release not in repos_info: repos_info[chroot.name_release] = { "name_release": chroot.name_release, "name_release_human": chroot.name_release_human, "os_release": chroot.os_release, "os_version": chroot.os_version, "arch_list": [chroot.arch], "repo_file": "{}-{}-{}.repo".format(copr.owner.name, copr.name, chroot.name_release), "dl_stat": repo_dl_stat[chroot.name_release], "rpm_dl_stat": { chroot.arch: chroot_rpms_dl_stat } } else: repos_info[chroot.name_release]["arch_list"].append(chroot.arch) repos_info[chroot.name_release]["rpm_dl_stat"][ chroot.arch] = chroot_rpms_dl_stat repos_info_list = sorted(repos_info.values(), key=lambda rec: rec["name_release"]) builds = builds_logic.BuildsLogic.get_multiple_by_copr( copr=copr).limit(1).all() return flask.render_template( "coprs/detail/overview.html", copr=copr, user=flask.g.user, form=form, repo_dl_stat=repo_dl_stat, repos_info_list=repos_info_list, latest_build=builds[0] if len(builds) == 1 else None, )
def process_legal_flag(copr): form = forms.CoprLegalFlagForm() legal_flag = models.LegalFlag(raise_message=form.comment.data, raised_on=int(time.time()), copr=copr, reporter=flask.g.user) db.session.add(legal_flag) db.session.commit() send_to = app.config["SEND_LEGAL_TO"] or ["root@localhost"] msg = LegalFlagMessage(copr, flask.g.user, form.comment.data) send_mail(send_to, msg) flask.flash("Admin has been noticed about your report" " and will investigate the project shortly.") return flask.redirect(url_for_copr_details(copr))
def copr_detail(username, coprname): query = coprs_logic.CoprsLogic.get( flask.g.user, username, coprname, with_mock_chroots=True) form = forms.CoprLegalFlagForm() try: copr = query.one() except sqlalchemy.orm.exc.NoResultFound: return page_not_found( "Copr with name {0} does not exist.".format(coprname)) repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr) repos_info = {} for chroot in copr.active_chroots: chroot_rpms_dl_stat_key = CHROOT_REPO_MD_DL_STAT_FMT.format( copr_user=copr.owner.name, copr_project_name=copr.name, copr_chroot=chroot.name, ) chroot_rpms_dl_stat = TimedStatEvents.get_count( rconnect=rcp.get_connection(), name=chroot_rpms_dl_stat_key, ) if chroot.name_release not in repos_info: repos_info[chroot.name_release] = { "name_release": chroot.name_release, "name_release_human": chroot.name_release_human, "arch_list": [chroot.arch], "repo_file": "{}-{}-{}.repo".format(copr.owner.name, copr.name, chroot.name_release), "dl_stat": repo_dl_stat[chroot.name_release], "rpm_dl_stat": { chroot.arch: chroot_rpms_dl_stat } } else: repos_info[chroot.name_release]["arch_list"].append(chroot.arch) repos_info[chroot.name_release]["rpm_dl_stat"][chroot.arch] = chroot_rpms_dl_stat repos_info_list = sorted(repos_info.values(), key=lambda rec: rec["name_release"]) return flask.render_template("coprs/detail/overview.html", copr=copr, form=form, repo_dl_stat=repo_dl_stat, repos_info_list=repos_info_list, )
def render_copr_report_abuse(copr): form = forms.CoprLegalFlagForm() return render_template("coprs/report_abuse.html", copr=copr, form=form)