#1967 rpmbuild: drop ANSI control sequences from log again
Merged 2 years ago by praiskup. Opened 2 years ago by praiskup.
Unknown source loggify  into  main

@@ -0,0 +1,19 @@

+ #! /bin/bash

+ 

+ # copr-rpmbuild-loggify - filter-out terminal output so it is nicely loggable

+ # Copyright (C) 2021 Red Hat, Inc.

+ #

+ # Use like:

+ # $ some_terminal_app_with_output | copr-loggify > /var/log/the.log

+ 

+ cmd=(

+     sed --unbuffered

+     # Strings terminated by CR, aka "live progress bars"

+     -e 's/.*\x0D\([^\x0a]\)/\1/g'

+     # Terminal control sequences (e.g. colors)

+     -e 's|\x1B\[[0-9;]*[a-zA-Z]||g'

+     # Carriage Return, Shift Out, Shift In

+     -e 's/[\x0d\x0e\x0f]*//g'

TERM=dumb .. is an alternative to this?

+ )

+ 

+ exec "${cmd[@]}"

file modified
+3 -1
@@ -71,6 +71,7 @@

  # for the /bin/unbuffer binary

  Requires: expect

  Requires: qemu-user-static

+ Requires: sed

  

  %if 0%{?fedora} || 0%{?rhel} > 7

  Recommends: rpkg
@@ -180,7 +181,7 @@

  for script in bin/copr-rpmbuild* \

                bin/copr-distgit*

  do

-     sed -i '1 s|#.*|#! /usr/bin/%python|' "$script"

+     sed -i '1 s|#.*python.*|#! /usr/bin/%python|' "$script"

  done

  

  
@@ -253,6 +254,7 @@

  install -p -m 755 bin/copr-sources-custom %buildroot%_bindir

  install -p -m 755 bin/copr-rpmbuild-cancel %buildroot%_bindir

  install -p -m 755 bin/copr-rpmbuild-log %buildroot%_bindir

+ install -p -m 755 bin/copr-rpmbuild-loggify %buildroot%_bindir

  

  name="%{name}" version="%{version}" summary="%{summary}" %py_install

  

@@ -234,7 +234,7 @@

  

  

  def dump_live_log(logfile):

-     filter_continuing_lines = r"sed 's/.*\x0D\([^\x0a]\)/\1/g' --unbuffered"

+     filter_continuing_lines = "/usr/bin/copr-rpmbuild-loggify"

      tee_output = "tee -a {0}".format(pipes.quote(logfile))

      cmd = filter_continuing_lines + "|" + tee_output

      tee = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True)

@@ -0,0 +1,44 @@

+ """

+ Test the bin/copr-rpmbuild-loggify filter

+ """

+ 

+ import os

+ import shutil

+ import subprocess

+ import tempfile

+ 

+ INPUT = """

+ This is \x1b\x5b\x33\x34\x6dblue\x1b\x5b\x30\x6d text

+ WIP progress-bar\x0dprogress-bar

+ trailing SO/SI/CR\x0e\x0f\r

+ end

+ """

+ 

+ OUTPUT = """

+ This is blue text

+ progress-bar

+ trailing SO/SI/CR

+ end

+ """

+ 

+ 

+ def test_loggify():

+     tmpdir = tempfile.mkdtemp(prefix="copr-rpmbuild-test-loggify-")

+     input_file = os.path.join(tmpdir, "input")

+     output_file = os.path.join(tmpdir, "output")

+     with open(input_file, "w") as fd:

+         fd.write(INPUT)

+ 

+     subprocess.call(

+         "copr-rpmbuild-loggify < {0} > {1}".format(

+             input_file, output_file,

+         ),

+         shell=True,

+         cwd=os.path.dirname(__file__),

+     )

+ 

+     with open(output_file, "r") as fd:

+         output = fd.read()

+ 

+     assert output == OUTPUT

+     shutil.rmtree(tmpdir)

Originally added in f4561c1, lost while
reimplementing builder from Bash to Python, then partly re-added
0573d06.

Fixes: #1961

Build succeeded.

rebased onto a4f2758d025363d35960c176a55702fd9faed1c7

2 years ago

Build succeeded.

rebased onto 0f2f23e4274db166d7872c0d505bbf6ad78d5adf

2 years ago

Build succeeded.

rebased onto 46ddaeb4d99e968d722035ca09b1ce86f90e474c

2 years ago

Build succeeded.

rebased onto 34fe6547cdc28b9c1bd78a92dcddb8a2060ea6fa

2 years ago

Build succeeded.

rebased onto 3400b0f2930eef8148ef1102c26b58ec55d315ce

2 years ago

Build succeeded.

TERM=dumb .. is an alternative to this?

rebased onto c040676

2 years ago

Pull-Request has been merged by praiskup

2 years ago

Build succeeded.