Commit fa7260de authored by Duncan Macleod's avatar Duncan Macleod
Browse files

gwkoji: reimplemented verbose mode

parent 09679e64
......@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import os.path
import pathlib
import re
......@@ -36,7 +37,7 @@ RPMBUILD_TS_RESP = re.compile(r'\AWrote: (?P<srcrpm>\S+)\Z')
def _rpmbuild_args(*args, tmpdir=None):
"""Construct a command-line call to ``rpmbuild``
"""
rpmbargs = [find_executable('rpmbuild')]
rpmbargs = [find_executable('rpmbuild'), '--verbose']
if tmpdir:
rpmbargs.extend(('--define', '_topdir {0}'.format(tmpdir)))
return rpmbargs + list(args)
......@@ -63,8 +64,6 @@ def download_spec_sources(spec, outdir, logger=None):
]
return logged_check_call(
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
logger=logger,
)
......
......@@ -19,7 +19,6 @@
"""Interactions with koji
"""
import subprocess
from distutils.spawn import find_executable
from .utils import logged_check_call
......@@ -27,16 +26,13 @@ from .utils import logged_check_call
def _koji_call(
*args,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
**kwargs,
):
koji = find_executable("koji")
koji = find_executable("echo")
if koji is None:
raise FileNotFoundError("No such file or directory: 'koji'")
cmd = (koji,) + args
return logged_check_call(cmd, stdout=stdout, stderr=stderr, **kwargs)
return logged_check_call(cmd, **kwargs)
def moshimoshi(*args, **kwargs):
......
......@@ -44,10 +44,14 @@ logger = logging.getLogger("gwkoji")
try:
import coloredlogs
except ImportError:
logger.setLevel(logging.DEBUG)
set_logger_level = logger.setLevel
else:
coloredlogs.install(level='DEBUG', logger=logger,
fmt=LOGGER_FORMAT, datefmt=LOGGER_DATEFMT)
coloredlogs.install(
logger=logger,
fmt=LOGGER_FORMAT,
datefmt=LOGGER_DATEFMT,
)
set_logger_level = coloredlogs.set_level
#
# metadata
......@@ -64,7 +68,11 @@ DEFAULT_TARGET = "sandox"
def parse_options():
# define option parser
parser = argparse.ArgumentParser(description='Build RPMs using Koji')
parser.add_argument('--version', action='version', version=__version__)
parser.add_argument('-V', '--version', action='version', version=__version__,
help='show version number and exit')
parser.add_argument('-v', '--verbose', action='count', default=2,
help='show verbose output, give once for INFO, '
'give twice for DEBUG')
# koji options
koji_options = parser.add_argument_group('Koji Options')
......@@ -132,6 +140,12 @@ def get_package_name_from_source_rpm(source):
def main():
args = parse_options()
# set verbosity
set_logger_level(10 * max(5 - args.verbose, 0))
# print info
logger.info('-- gwkoji-packager -----')
logger.info('source = %s' % args.source)
logger.info('target tag = %s' % args.target)
......@@ -175,6 +189,7 @@ def main():
sys.exit(1)
koji.add_pkg(args.owner, pkg_name, logger=logger)
logger.info('-- Complete -----')
#
# main program entry point
......
......@@ -32,7 +32,5 @@ def test_download_spec_sources(call, _):
call.assert_called_once_with(
["/usr/bin/spectool", "--get-files", "--directory",
"outdir", "test.spec"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
logger=1,
)
......@@ -18,17 +18,31 @@
import logging
import pathlib
import sys
from functools import wraps
from subprocess import (check_call, check_output, call)
from subprocess import (check_call, check_output, call, STDOUT, DEVNULL)
def _logged_call(func):
@wraps(func)
def decorated(cmd, *args, logger=logging.getLogger(),
loglevel=logging.DEBUG, **kwargs):
# get logging level
if not isinstance(loglevel, int):
loglevel = logging.getLevelName(loglevel)
# set default streams based on logging level
if logger.getEffectiveLevel() > logging.INFO:
kwargs.setdefault('stderr', subprocess.DEVNULL)
if func != check_output:
kwargs.setdefault('stdout', subprocess.DEVNULL)
elif func != check_output:
kwargs.setdefault('stdout', sys.stderr)
# log the command
logger.log(loglevel, '$ {0}'.format(' '.join(cmd)))
# run it
return func(cmd, *args, **kwargs)
return decorated
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment