#257 [frontend] add status_icon for build_id
Merged 6 years ago by praiskup. Opened 6 years ago by praiskup.
Unknown source status-icons  into  master

@@ -18,7 +18,8 @@

  from coprs.logic.builds_logic import BuildsLogic

  from coprs.logic.complex_logic import ComplexLogic

  

- from coprs.views.misc import login_required, page_not_found, req_with_copr, req_with_copr

+ from coprs.views.misc import (login_required, page_not_found, req_with_copr,

+         req_with_copr, send_build_icon)

  from coprs.views.coprs_ns import coprs_ns

  

  from coprs.exceptions import (ActionInProgressException,
@@ -33,6 +34,11 @@

      return flask.redirect(helpers.copr_url("coprs_ns.copr_build", copr, build_id=build_id))

  

  

+ @coprs_ns.route("/build/<int:build_id>/status_image.png")

+ def copr_build_icon(build_id):

+     return send_build_icon(BuildsLogic.get_by_id(int(build_id)).first())

+ 

+ 

  ################################ Build detail ################################

  

  @coprs_ns.route("/<username>/<coprname>/build/<int:build_id>/")

@@ -6,10 +6,9 @@

  from coprs import db

  from coprs import forms

  from coprs import helpers

- from coprs.models import Package, Build

  from coprs.views.coprs_ns import coprs_ns

  from coprs.views.coprs_ns.coprs_builds import render_add_build_scm, render_add_build_pypi, render_add_build_custom

- from coprs.views.misc import login_required, page_not_found, req_with_copr, req_with_copr

+ from coprs.views.misc import login_required, page_not_found, req_with_copr, req_with_copr, send_build_icon

  from coprs.logic.complex_logic import ComplexLogic

  from coprs.logic.packages_logic import PackagesLogic

  from coprs.logic.users_logic import UsersLogic
@@ -42,19 +41,7 @@

      except ObjectNotFound:

          return send_file("static/status_images/bad_url.png", mimetype='image/png')

  

-     last_build = package.last_build()

-     if last_build:

-         if last_build.state in ["importing", "pending", "starting", "running"]:

-             return send_file("static/status_images/in_progress.png", mimetype='image/png')

- 

-         if last_build.state in ["succeeded", "skipped"]:

-             return send_file("static/status_images/succeeded.png", mimetype='image/png')

- 

-         if last_build.state == "failed":

-             return send_file("static/status_images/failed.png", mimetype='image/png')

- 

-         else:

-             return send_file("static/status_images/unknown.png", mimetype='image/png')

+     return send_build_icon(package.last_build())

  

  

  @coprs_ns.route("/<username>/<coprname>/packages/rebuild-all/", methods=["GET", "POST"])

@@ -7,6 +7,7 @@

  from netaddr import IPAddress, IPNetwork

  import re

  import flask

+ from flask import send_file

  

  from openid_teams.teams import TeamsRequest

  
@@ -392,3 +393,28 @@

                                   user=user,

                                   group=group,

                                   coprs=coprs)

+ 

+ 

+ def send_build_icon(build):

+     if not build:

+         return send_file("static/status_images/unknown.png",

+                          mimetype='image/png')

+ 

+     if build.state in ["importing", "pending", "starting", "running"]:

+         # The icon is about to change very soon, disable caches:

+         # https://help.github.com/articles/about-anonymized-image-urls/

+         response = send_file("static/status_images/in_progress.png",

+                              mimetype='image/png')

+         response.headers['Cache-Control'] = 'no-cache'

+         return response

+ 

+     if build.state in ["succeeded", "skipped"]:

+         return send_file("static/status_images/succeeded.png",

+                          mimetype='image/png')

+ 

+     if build.state == "failed":

+         return send_file("static/status_images/failed.png",

+                          mimetype='image/png')

+ 

+     return send_file("static/status_images/unknown.png",

+                      mimetype='image/png')

And don't cache the "in_progress" icon, which is soon to be
replaced by skip/success/fail icon.

What if the build is canceled? It would be good to have `send_file("static/status_images/unknown.png", mimetype='image/png') at the end of this function.

Instead of this pass you can just return the bad_url file and omit the currently last line in this function.

this function should be in coprs.views.misc so that it can be shared between a package view and build view.

I've had a few notes but thanks for this PR!

rebased onto 74939785c6c37f23f6edff577703106a2b227377

6 years ago

Thanks you for the very valid comments!

This try-except is actually unnecessary. But that's really a tiny nitpick.

rebased onto d4344eb

6 years ago

I dropped the try-except block.

.. and merging, thanks!

Pull-Request has been merged by praiskup

6 years ago