Pylint for common/rpmlint.py
authorLingchaox Xin <lingchaox.xin@intel.com>
Thu, 13 Jun 2013 07:38:45 +0000 (15:38 +0800)
committerLingchaox Xin <lingchaox.xin@intel.com>
Fri, 14 Jun 2013 00:38:26 +0000 (08:38 +0800)
Change-Id: Ib69c6c20cc6db5191517e1c49e0e14a854b745e0

common/rpmlint.py

index c1d2ded..fc9bb9a 100644 (file)
 # 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 setRawOut, printed_messages, badnessThreshold, _badness_score
+from Filter import printed_messages, badnessThreshold
 import SpecCheck
 import Config
 import Pkg
@@ -30,12 +32,10 @@ import Filter
 from common.git import clone_gitproject
 
 def rpmlint(spec_file):
-
-    def __print(s):
-        pass
+    """Lint a spec file"""
 
     def _print(msgtype, pkg, reason, details):
-        global _badness_score
+        """Print datail information"""
 
         threshold = badnessThreshold()
 
@@ -49,26 +49,24 @@ def rpmlint(spec_file):
             elif msgtype == 'E':
                 msgtype = 'W'
 
-        ln = ""
+        line_num = ""
         if pkg.current_linenum is not None:
-            ln = "%s:" % pkg.current_linenum
+            line_num = "%s:" % pkg.current_linenum
         arch = ""
         if pkg.arch is not None:
             arch = ".%s" % pkg.arch
-        s = "%s%s:%s %s: %s" % (pkg.name, arch, ln, msgtype, reason)
+        state = "%s%s:%s %s: %s" % (pkg.name, arch, line_num, msgtype, reason)
         if badness:
-            s = s + " (Badness: %d)" % badness
-        for d in details:
-            s = s + " %s" % d
+            state = state + " (Badness: %d)" % badness
+        for detail in details:
+            state = state + " %s" % detail
         else:
-            if not Config.isFiltered(s):
-                outputs.append(s)
+            if not Config.isFiltered(state):
+                outputs.append(state)
                 printed_messages[msgtype] += 1
-                _badness_score += badness
                 if threshold >= 0:
-                    _diagnostic.append(s + "\n")
+                    _diagnostic.append(state + "\n")
                 else:
-                    __print(s)
                     if Config.info:
                         printDescriptions(reason)
                 return True
@@ -76,10 +74,11 @@ def rpmlint(spec_file):
         return False
 
 
-    Filter._print=_print
-    #spec_file=sys.argv[1]
+    Filter._print = _print
+    # spec_file=sys.argv[1]
 
-    # the tempfile is designed for python policycheck.py, bash script doesn't use it
+    # 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')
@@ -104,7 +103,8 @@ def rpmlint(spec_file):
     check.check_spec(pkg, spec_file)
     pkg.cleanup()
 
-    msg = 'rpmlint checked %s: %d errors, %s warnings.' % (spec_file, printed_messages["E"], printed_messages["W"])
+    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:'):