From 44b6a0518df4bf65ba5b30cb161fbd427edb9fef Mon Sep 17 00:00:00 2001 From: Lukas Brabec Date: Feb 23 2018 20:39:03 +0000 Subject: Use rpmlintrc file if it exists in distgit Fixes: https://pagure.io/taskotron/task-rpmlint/issue/5 --- diff --git a/download_rpmlintconf.py b/download_rpmlintconf.py new file mode 100755 index 0000000..dda6bc5 --- /dev/null +++ b/download_rpmlintconf.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python2 +'''Script for downloading .rpmlintrc file from distgit''' + +import sys +import os + +from libtaskotron.directives import distgit_directive +from libtaskotron.ext.fedora import rpm_utils +from libtaskotron.exceptions import TaskotronRemoteError + +def download_rpmlintconf(koji_build, workdir='.'): + '''If it exists, download .rpmlint file from distgit. If it + doesn't, do nothing. + + :param str koji_build: NVR used to determine distgit repo and + :param str workdir: directory into which to download the file + ''' + distgit = distgit_directive.DistGitDirective() + + pkgname = rpm_utils.rpmformat(koji_build, fmt='n') + + params = {"nvr": koji_build, + "path": ["%s.rpmlintrc" % pkgname], + "target_dir": workdir} + + try: + print "Trying to download %s.rpmlintrc ..." % pkgname + distgit.process(params, {"workdir": workdir}) + print "%s.rpmlintrc downloaded successfully into %s" % (pkgname, + os.path.abspath(workdir)) + except TaskotronRemoteError as e: + print "Failed to download %s.rpmlintrc: %s" % (pkgname, e) + + +if __name__ == "__main__": + download_rpmlintconf(koji_build=sys.argv[1], workdir=sys.argv[2]) diff --git a/run_rpmlint.py b/run_rpmlint.py index b23e8f4..7028669 100755 --- a/run_rpmlint.py +++ b/run_rpmlint.py @@ -15,6 +15,7 @@ from collections import namedtuple from libtaskotron import check from libtaskotron import os_utils +from libtaskotron.ext.fedora import rpm_utils log = logging.getLogger('rpmlint') log.setLevel(logging.DEBUG) @@ -44,11 +45,20 @@ def run(koji_build, workdir='.', artifactsdir='artifacts', rpms.append(filepath) else: log.debug('Ignoring non-rpm file: %s', filepath) + pkgname = rpm_utils.rpmformat(koji_build, fmt='n') + rpmlintconf = os.path.join(workdir, "%s.rpmlintrc" % pkgname) + if os.path.isfile(rpmlintconf): + log.debug('Found rpmlint config file: %s', rpmlintconf) + else: + rpmlintconf = None + + command = ['rpmlint'] + if rpmlintconf: + command.extend(['--file', rpmlintconf]) # run rpmlint on SRPMs if srpms: - command = ['rpmlint'] + srpms - srpm_result = run_rpmlint(command) + srpm_result = run_rpmlint(command + srpms) else: log.critical('No .src.rpm files found in: %s', workdir) log.debug('Files available in the workdir:\n%s', '\n'.join(files)) @@ -60,8 +70,8 @@ def run(koji_build, workdir='.', artifactsdir='artifacts', # network checks were already) performed on the SRPM. # See https://phab.qa.fedoraproject.org/T760 if rpms: - command = ['rpmlint', '-o', 'NetworkEnabled False'] + rpms - rpm_result = run_rpmlint(command) + command.extend(['--option', 'NetworkEnabled False']) + rpm_result = run_rpmlint(command + rpms) else: log.warn('No binary rpm files found in: %s', workdir) rpm_result = Result('PASSED', "", 0, 0) diff --git a/tests.yml b/tests.yml index 39241bb..34cc1ab 100644 --- a/tests.yml +++ b/tests.yml @@ -19,6 +19,7 @@ - rpmlint - koji - libtaskotron-core + - libtaskotron-fedora - name: Make sure taskotron results dir exists # this is for placing results.yml file @@ -56,6 +57,11 @@ args: chdir: "{{ workdir.path }}" + - name: Download rpmlint conf from distgit + shell: > + ./download_rpmlintconf.py {{ taskotron_item }} {{ workdir.path }} + &>> {{ artifacts }}/test.log + - name: Run rpmlint shell: > ./run_rpmlint.py {{ taskotron_item }} {{ workdir.path }}