#2340 Show the import.log to all users
Merged 2 years ago by praiskup. Opened 2 years ago by praiskup.
Unknown source import-log  into  main

@@ -139,6 +139,11 @@

  MIN_BUILD_TIMEOUT = 0

  MAX_BUILD_TIMEOUT = 108000

  

+ # The import log is automatically removed after some time, depending on

+ # dist-git-configuration.  It doesn't make sense to show it any longer, it would

+ # only point users to 404 error page.

+ HIDE_IMPORT_LOG_AFTER_DAYS = 14

+ 

  

  #############################

  ##### DEBUGGING Section #####

@@ -147,6 +147,8 @@

  

      FAS_SIGNUP_URL = "https://accounts.fedoraproject.org/"

  

+     HIDE_IMPORT_LOG_AFTER_DAYS = 14

+ 

  

  class ProductionConfig(Config):

      DEBUG = False

@@ -73,6 +73,16 @@

  

      return None

  

+ @app.template_filter("fix_import_log_name")

+ def fix_import_log_name(log_basename):

+     """

+     Transform the log basename to "import.log" for import log, or keep

+     unchanged.

+     """

+     parts = log_basename.split(".")

+     if all(c.isdigit() for c in parts[0]):

+         return "import.log"

+     return log_basename

  

  @app.template_filter("perm_type_from_num")

  def perm_type_from_num(num):

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

  import os

  from urllib.parse import urljoin

  import uuid

+ import time

  import zlib

  

  import modulemd_tools.yaml
@@ -1095,18 +1096,25 @@

      def id_fixed_width(self):

          return "{:08d}".format(self.id)

  

-     def get_source_log_urls(self, admin=False):

+     @property

+     def get_source_log_urls(self):

          """

          Return a list of URLs to important build _source_ logs.  The list is

          changing as the state of build is changing.

          """

-         logs = [self.source_live_log_url, self.source_backend_log_url]

-         if admin:

-             logs.append(self.import_log_url_distgit)

+         logs = [self.source_live_log_url, self.source_backend_log_url,

+                 self.import_log_url_distgit]

          return list(filter(None, logs))

  

      @property

      def import_log_url_distgit(self):

+         if self.source_state not in ["importing", "succeeded", "failed"]:

+             return None

+ 

+         days = app.config["HIDE_IMPORT_LOG_AFTER_DAYS"]

+         if (time.time() - self.submitted_on) > days*24*3600:

+             return None

+ 

          if app.config["COPR_DIST_GIT_LOGS_URL"]:

              return "{}/{}.log".format(app.config["COPR_DIST_GIT_LOGS_URL"],

                                        self.task_id.replace('/', '_'))

@@ -201,8 +201,8 @@

              #{{ build.resubmitted_from_id }}

            {% endif %}

          {% else %}

-           {% for url in build.get_source_log_urls(g.user.admin) %}

-             <a href="{{ url }}">{{ url | basename }}</a> {{ "," if not loop.last }}

+           {% for url in build.get_source_log_urls %}

+             <a href="{{ url }}">{{ url | basename | fix_import_log_name }}</a> {{ "," if not loop.last }}

            {% else %}

              Source build has not started yet

            {% endfor %}

@@ -1,3 +1,4 @@

+ import time

  from datetime import datetime, timedelta

  import pytest

  import coprs
@@ -119,8 +120,9 @@

          assert self.b1.source_backend_log_url == _pfxd("backend.log")

  

          # importing state

+         self.b1.submitted_on = int(time.time()) - 24*3600

          self.b1.source_status = StatusEnum("importing")

-         assert self.b1.get_source_log_urls(admin=True) == [

+         assert self.b1.get_source_log_urls == [

              _pfxd("builder-live.log.gz"),

              _pfxd("backend.log.gz"),

              "http://example-dist-git/url/1.log",