diff --git a/rpmlint.yml b/rpmlint.yml --- a/rpmlint.yml +++ b/rpmlint.yml @@ -25,6 +25,7 @@ callable: run workdir: ${workdir} koji_build: ${koji_build} + artifactsdir: ${artifactsdir} export: rpmlint_output - name: report results to resultsdb diff --git a/run_rpmlint.py b/run_rpmlint.py --- a/run_rpmlint.py +++ b/run_rpmlint.py @@ -1,27 +1,74 @@ +import logging +if __name__ == '__main__': + # Set up logging ASAP to see potential problems during import. + # Don't set it up when not running as the main script, someone else handles + # that then. + logging.basicConfig() + import subprocess import os +import sys + from libtaskotron import check -def run(koji_build, workdir = u'.'): - retcode = subprocess.call(['rpmlint', '%s' % os.path.abspath(workdir)]) +log = logging.getLogger('rpmlint') +log.setLevel(logging.DEBUG) +log.addHandler(logging.NullHandler()) + + +def run(koji_build, workdir='.', artifactsdir='artifacts'): + '''The main method to run from Taskotron''' + + if not os.path.exists(artifactsdir): + os.makedirs(artifactsdir) + + command = ['rpmlint', '%s' % os.path.abspath(workdir)] - if retcode == 0: + # run rpmlint + log.debug('Running command: %s', command) + proc = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, bufsize=1, + close_fds=True) + output = [] + for line in iter(proc.stdout.readline, ''): + print line, + output.append(line) + stdout, stderr = proc.communicate() + + # stdout and stderr should be empty, because we printed them out + # before calling .communicate() + if stdout or stderr: + log.warn("Extra stdout or stderr found, this shouldn't happen:") + print 'STDOUT:\n%s' % stdout + print >> sys.stderr, 'STDERR:\n%s' % stderr + output.append(stdout) + output.append(stderr) + + if proc.returncode == 0: result = 'PASSED' else: - if retcode == 64 or retcode == 66: + if proc.returncode == 64 or proc.returncode == 66: result = 'FAILED' else: result = 'ABORTED' summary = 'rpmlint %s for %s' % (result, koji_build) + log.info(summary) + detail = check.CheckDetail(koji_build, check.ReportType.KOJI_BUILD, - result, summary) + result, summary) - tapdetail = check.export_TAP(detail, checkname='rpmlint') - return tapdetail + # store logs + log_path = os.path.join(artifactsdir, '%s.log' % koji_build) + log.debug('Saving log to: %s', log_path) + with open(log_path, 'w') as log_file: + log_file.writelines(output) + detail.artifact = log_path + + tap = check.export_TAP(detail, checkname='rpmlint') + return tap -if __name__ == '__main__': - tapout = run() - for result in tapout: - print result +if __name__ == '__main__': + tap = run('local-run') + print tap