### Eclipse Workspace Patch 1.0
# Alphonse Van Assche: This patch backport the rpmlint on specfiles functionnality
#P rpmlint-0.80
Index: Filter.py
===================================================================
RCS file: /srv/cvs/rpmlint-0.80/Filter.py,v
retrieving revision 1.1
diff -u -r1.1 Filter.py
--- Filter.py	29 Aug 2007 09:58:17 -0000	1.1
+++ Filter.py	29 Aug 2007 10:54:38 -0000
@@ -24,7 +24,13 @@
         printDescriptions(reason)
 
 def _print(type, pkg, reason, details):
-    s="%s: %s %s" % (type, pkg.name, reason)
+    ln = ""
+    if pkg.current_linenum is not None:
+        ln = "%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, type, reason)
     for d in details:
         s = s + " %s" % d
     if Testing.isTest():
Index: SpecCheck.py
===================================================================
RCS file: /srv/cvs/rpmlint-0.80/SpecCheck.py,v
retrieving revision 1.1
diff -u -r1.1 SpecCheck.py
--- SpecCheck.py	29 Aug 2007 09:58:17 -0000	1.1
+++ SpecCheck.py	29 Aug 2007 10:54:38 -0000
@@ -127,6 +127,7 @@
 
     def __init__(self):
         AbstractCheck.AbstractCheck.__init__(self, "SpecCheck")
+        self._spec_file = None
 
     def check(self, pkg):
         if not pkg.isSource():
@@ -134,19 +135,21 @@
 
         # lookup spec file
         files = pkg.files()
-        spec_file = None
         for f in files.keys():
             if f.endswith('.spec'):
-                spec_file = pkg.dirName() + "/" + f
+                self._spec_file = pkg.dirName() + "/" + f
                 break
-        if not spec_file:
+        if not self._spec_file:
             printError(pkg, "no-spec-file")
         else:
             if f != pkg.name + ".spec":
                 printError(pkg, "invalid-spec-name", f)
 
+            spec_lines = file2string(self._spec_file)
             # check content of spec file
-            spec = file2string(spec_file)
+            self.check_spec(pkg, spec_lines)
+            
+    def check_spec(self, pkg, spec_lines):
             patches = {}
             applied_patches = []
             applied_patches_ifarch = []
@@ -171,16 +174,17 @@
                     'count': 0,
                     're': re.compile('^%' + sec + '(?:\s|$)'),
                     }
-
-            if use_utf8 and not is_utf8(spec_file):
-                printError(pkg, "non-utf8-spec-file", f)
+            
+            if self._spec_file:
+                if use_utf8 and not is_utf8(self._spec_file):
+                    printError(pkg, "non-utf8-spec-file", f)
 
             # gather info from spec lines
 
-            linenum = 0
-            for line in spec:
+            pkg.current_linenum = 0
+            for line in spec_lines:
 
-                linenum += 1
+                pkg.current_linenum += 1
                 section_marker = 0
                 for i in section.keys():
                     if section[i]['re'].search(line):
@@ -317,9 +321,12 @@
                             printWarning(pkg, 'unversioned-explicit-obsoletes', obs)
 
                 if not indent_tabs and indent_tabs_regex.search(line):
-                    indent_tabs = linenum
+                    indent_tabs = pkg.current_linenum
                 if not indent_spaces and indent_spaces_regex.search(line):
-                    indent_spaces = linenum
+                    indent_spaces = pkg.current_linenum
+
+            # No useful line number info beyond this point.
+            pkg.current_linenum = None
 
             for sect in buildroot_clean:
                 if not buildroot_clean[sect]:
Index: rpmlint.py
===================================================================
RCS file: /srv/cvs/rpmlint-0.80/rpmlint.py,v
retrieving revision 1.1
diff -u -r1.1 rpmlint.py
--- rpmlint.py	29 Aug 2007 09:58:17 -0000	1.1
+++ rpmlint.py	29 Aug 2007 10:54:38 -0000
@@ -18,13 +18,14 @@
 import stat
 import rpm
 from Filter import *
+import SpecCheck
 
 version='@VERSION@'
 policy=None
 
 # Print usage information
 def usage(name):
-    print 'usage:', name, '[<options>] <rpm files>'
+    print 'usage:', name, '[<options>] <rpm files|specfile>'
     print '  options in:'
     print '\t[-i|--info]\n\t[-I <error,error,>]\n\t[-c|--check <check>]\n\t[-a|--all]\n\t[-C|--checkdir <checkdir>]\n\t[-h|--help]\n\t[-v|--verbose]\n\t[-E|--extractdir <dir>]\n\t[-p|--profile]\n\t[-V|--version]\n\t[-n|--noexception]\n\t[-P|--policy <policy>]\n\t[-f|--file <config file to use instead of ~/.rpmlintrc>]'
 
@@ -63,7 +64,14 @@
                     st=os.stat(f)
                     isfile = True
                     if stat.S_ISREG(st[stat.ST_MODE]):
-                        pkgs.append(Pkg.Pkg(f, extract_dir))
+                        if not f.endswith(".spec"):
+                            pkgs.append(Pkg.Pkg(f, extract_dir))
+                        else:
+                            # Short-circuit spec file checks
+                            pkg = Pkg.FakePkg(f)
+                            check = SpecCheck.SpecCheck()
+                            check.check_spec(pkg, Pkg.readlines(f))
+                            
                     elif stat.S_ISDIR(st[stat.ST_MODE]):
                         dirs.append(f)
                         continue
Index: Pkg.py
===================================================================
RCS file: /srv/cvs/rpmlint-0.80/Pkg.py,v
retrieving revision 1.1
diff -u -r1.1 Pkg.py
--- Pkg.py	29 Aug 2007 09:58:17 -0000	1.1
+++ Pkg.py	29 Aug 2007 10:54:38 -0000
@@ -115,6 +115,13 @@
         return 0
     return 1
 
+def readlines(path):
+    fobj = open(path, "r")
+    try:
+        return fobj.readlines()
+    finally:
+        fobj.close()
+
 # classes representing package
 
 class Pkg:
@@ -125,6 +132,7 @@
         self.extracted=0
         self.dirname=dirname
         self.file_info=None
+        self.current_linenum=None
         self._config_files=None
         self._doc_files=None
         self._ghost_files=None
@@ -494,6 +502,15 @@
             #print self.file_info
         return self.file_info
 
+# Class to provide an API to a "fake" package, eg. for specfile-only checks
+class FakePkg:
+    def __init__(self, name):
+        self.name = name
+        self.arch = None
+
+    def cleanup(self):
+        pass
+
 if __name__ == '__main__':
     for p in sys.argv[1:]:
         pkg=Pkg(sys.argv[1], '/tmp')

