+++ /dev/null
-#!/usr/bin/python -tt
-# vim: ai ts=4 sts=4 et sw=4
-#
-# Copyright (c) 2011 Intel, Inc.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the Free
-# Software Foundation; version 2 of the License
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-"""A rpmlint wrapper"""
-
-import sys
-import os
-
-sys.path.insert(1, '/usr/share/rpmlint')
-
-from Filter import printed_messages, badnessThreshold
-import SpecCheck
-import Config
-import Pkg
-import Filter
-
-from common.git import clone_gitproject
-
-def rpmlint(spec_file):
- """Lint a spec file"""
-
- def _print(msgtype, pkg, reason, details):
- """Print datail information"""
-
- threshold = badnessThreshold()
-
- badness = 0
- if threshold >= 0:
- badness = Config.badness(reason)
- # anything with badness is an error
- if badness:
- msgtype = 'E'
- # errors without badness become warnings
- elif msgtype == 'E':
- msgtype = 'W'
-
- line_num = ""
- if pkg.current_linenum is not None:
- line_num = "%s:" % pkg.current_linenum
- arch = ""
- if pkg.arch is not None:
- arch = ".%s" % pkg.arch
- state = "%s%s:%s %s: %s" % (pkg.name, arch, line_num, msgtype, reason)
- if badness:
- state = state + " (Badness: %d)" % badness
- for detail in details:
- state = state + " %s" % detail
- else:
- if not Config.isFiltered(state):
- outputs.append(state)
- printed_messages[msgtype] += 1
- if threshold >= 0:
- _diagnostic.append(state + "\n")
- else:
- if Config.info:
- printDescriptions(reason)
- return True
-
- return False
-
-
- Filter._print = _print
- # spec_file=sys.argv[1]
-
- # the tempfile is designed for python policycheck.py,
- # bash script doesn't use it
-
- rpmlint_prj = os.getenv('RPMLINT_PRJ')
- git_cache_dir = os.getenv('GIT_CACHE_DIR')
- rpmlint_config_dir = os.path.join(git_cache_dir, rpmlint_prj)
-
- # if rpmlint_config does NOT exist, then clone it from gerrit projects.
- if not os.path.isdir(rpmlint_config_dir):
- clone_gitproject(rpmlint_prj, rpmlint_config_dir)
-
- try:
- rpmlint_config = os.path.join(git_cache_dir, rpmlint_prj, 'rpmlint')
- if not os.path.isfile(rpmlint_config):
- rpmlint_config = '~/.config/rpmlint'
- execfile(os.path.expanduser(rpmlint_config))
- except IOError:
- pass
-
- outputs = []
-
- pkg = Pkg.FakePkg(spec_file)
- check = SpecCheck.SpecCheck()
- check.check_spec(pkg, spec_file)
- pkg.cleanup()
-
- msg = 'rpmlint checked %s: %d errors, %s warnings.' % (
- spec_file, printed_messages["E"], printed_messages["W"])
- for line in outputs:
- line = line.strip().lstrip(spec_file+':').strip()
- if not line.startswith('W:') and not line.startswith('E:'):
- line = 'line '+line
- msg += '\n- '+line
- return msg