beautify logged commands issued by koji
Related: https://pagure.io/koji/issue/929
This commit is contained in:
parent
234cefdf1c
commit
9e741bfb9e
3 changed files with 56 additions and 5 deletions
|
|
@ -80,7 +80,7 @@ from koji.tasks import (
|
||||||
ServerExit,
|
ServerExit,
|
||||||
ServerRestart
|
ServerRestart
|
||||||
)
|
)
|
||||||
from koji.util import dslice, dslice_ex, isSuccess, parseStatus, to_list
|
from koji.util import dslice, dslice_ex, isSuccess, parseStatus, to_list, format_shell_cmd
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import requests_gssapi as reqgssapi
|
import requests_gssapi as reqgssapi
|
||||||
|
|
@ -445,7 +445,7 @@ class BuildRoot(object):
|
||||||
else:
|
else:
|
||||||
cmd.append('--old-chroot')
|
cmd.append('--old-chroot')
|
||||||
cmd.extend(args)
|
cmd.extend(args)
|
||||||
self.logger.info(' '.join(cmd))
|
self.logger.info(format_shell_cmd(cmd))
|
||||||
workdir = getattr(self, 'workdir', None)
|
workdir = getattr(self, 'workdir', None)
|
||||||
mocklog = 'mock_output.log'
|
mocklog = 'mock_output.log'
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
|
|
@ -5638,7 +5638,7 @@ class CreaterepoTask(BaseTaskHandler):
|
||||||
status = log_output(self.session, cmd[0], cmd, logfile, self.getUploadDir(), logerror=True)
|
status = log_output(self.session, cmd[0], cmd, logfile, self.getUploadDir(), logerror=True)
|
||||||
if not isSuccess(status):
|
if not isSuccess(status):
|
||||||
raise koji.GenericError('failed to create repo: %s'
|
raise koji.GenericError('failed to create repo: %s'
|
||||||
% parseStatus(status, ' '.join(cmd)))
|
% parseStatus(status, format_shell_cmd(cmd)))
|
||||||
|
|
||||||
def _get_mergerepo_c_version(self):
|
def _get_mergerepo_c_version(self):
|
||||||
cmd = ['/usr/bin/mergerepo_c', '--version']
|
cmd = ['/usr/bin/mergerepo_c', '--version']
|
||||||
|
|
@ -5737,7 +5737,7 @@ class CreaterepoTask(BaseTaskHandler):
|
||||||
logerror=True, env=env)
|
logerror=True, env=env)
|
||||||
if not isSuccess(status):
|
if not isSuccess(status):
|
||||||
raise koji.GenericError('failed to merge repos: %s'
|
raise koji.GenericError('failed to merge repos: %s'
|
||||||
% parseStatus(status, ' '.join(cmd)))
|
% parseStatus(status, format_shell_cmd(cmd)))
|
||||||
|
|
||||||
|
|
||||||
class NewDistRepoTask(BaseTaskHandler):
|
class NewDistRepoTask(BaseTaskHandler):
|
||||||
|
|
@ -5988,7 +5988,7 @@ class createDistRepoTask(BaseTaskHandler):
|
||||||
status = log_output(self.session, cmd[0], cmd, logfile, self.getUploadDir(), logerror=True)
|
status = log_output(self.session, cmd[0], cmd, logfile, self.getUploadDir(), logerror=True)
|
||||||
if not isSuccess(status):
|
if not isSuccess(status):
|
||||||
raise koji.GenericError('failed to create repo: %s'
|
raise koji.GenericError('failed to create repo: %s'
|
||||||
% parseStatus(status, ' '.join(cmd)))
|
% parseStatus(status, format_shell_cmd(cmd)))
|
||||||
|
|
||||||
def do_multilib(self, arch, ml_arch, conf):
|
def do_multilib(self, arch, ml_arch, conf):
|
||||||
repodir = koji.pathinfo.distrepo(self.rinfo['id'], self.rinfo['tag_name'])
|
repodir = koji.pathinfo.distrepo(self.rinfo['id'], self.rinfo['tag_name'])
|
||||||
|
|
|
||||||
25
koji/util.py
25
koji/util.py
|
|
@ -940,3 +940,28 @@ def to_list(lst):
|
||||||
return lst
|
return lst
|
||||||
else:
|
else:
|
||||||
return list(lst)
|
return list(lst)
|
||||||
|
|
||||||
|
|
||||||
|
def format_shell_cmd(cmd, text_width=80):
|
||||||
|
"""
|
||||||
|
Helper for wrapping shell command lists to human-readable form, while
|
||||||
|
they still can be copied (from logs) and run in shell.
|
||||||
|
|
||||||
|
:param [str] cmd: command list
|
||||||
|
:returns str:
|
||||||
|
"""
|
||||||
|
# account for " \"
|
||||||
|
text_width -= 2
|
||||||
|
s = []
|
||||||
|
line = ''
|
||||||
|
for bit in cmd:
|
||||||
|
if len(line + bit) > text_width:
|
||||||
|
if line:
|
||||||
|
s.append(line)
|
||||||
|
line = ''
|
||||||
|
if line:
|
||||||
|
line += ' '
|
||||||
|
line += bit
|
||||||
|
if line:
|
||||||
|
s.append(line)
|
||||||
|
return ' \\\n'.join(s)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from __future__ import absolute_import
|
||||||
import calendar
|
import calendar
|
||||||
import errno
|
import errno
|
||||||
import locale
|
import locale
|
||||||
|
from unittest.case import TestCase
|
||||||
import mock
|
import mock
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
|
|
@ -20,6 +21,8 @@ from datetime import datetime
|
||||||
import koji
|
import koji
|
||||||
import koji.util
|
import koji.util
|
||||||
|
|
||||||
|
from koji.util import format_shell_cmd
|
||||||
|
|
||||||
|
|
||||||
class EnumTestCase(unittest.TestCase):
|
class EnumTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -1600,5 +1603,28 @@ class TestMoveAndSymlink(unittest.TestCase):
|
||||||
ensuredir.assert_called_once_with('b')
|
ensuredir.assert_called_once_with('b')
|
||||||
|
|
||||||
|
|
||||||
|
class TestFormatShellCmd(unittest.TestCase):
|
||||||
|
def test_formats(self):
|
||||||
|
cases = (
|
||||||
|
([], ''),
|
||||||
|
(['random cmd'], 'random cmd'),
|
||||||
|
(['aa', 'bb'], 'aa bb'),
|
||||||
|
(['long', 'command', 'with', 'many', 'simple', 'options',
|
||||||
|
'like', '--option', 'x', '--another-option=x', 'and',
|
||||||
|
'many', 'more', 'others'],
|
||||||
|
'long command with many simple options \\\n'
|
||||||
|
'like --option x --another-option=x and \\\n'
|
||||||
|
'many more others'),
|
||||||
|
(['one long line which exceeds the text_width by some amount'],
|
||||||
|
'one long line which exceeds the text_width by some amount'),
|
||||||
|
(['one long line which exceeds the text_width by some amount',
|
||||||
|
'second long line which exceeds the text_width by some amount'],
|
||||||
|
'one long line which exceeds the text_width by some amount \\\n'
|
||||||
|
'second long line which exceeds the text_width by some amount'),
|
||||||
|
)
|
||||||
|
for inp, out in cases:
|
||||||
|
self.assertEqual(koji.util.format_shell_cmd(inp, text_width=40), out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue