2000-10-11 14:03:08 +08:00
|
|
|
#############################################################################
|
|
|
|
# File : SpecCheck.py
|
|
|
|
# Package : rpmlint
|
|
|
|
# Author : Frederic Lepied
|
|
|
|
# Created on : Thu Oct 7 17:06:14 1999
|
|
|
|
# Version : $Id$
|
|
|
|
# Purpose : check the spec file of a source rpm.
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
from Filter import *
|
|
|
|
import AbstractCheck
|
|
|
|
import commands
|
|
|
|
import re
|
|
|
|
import sys
|
2000-10-11 16:41:39 +08:00
|
|
|
import rpm
|
2000-10-11 14:03:08 +08:00
|
|
|
|
|
|
|
spec_regex=re.compile(".spec$")
|
|
|
|
patch_regex=re.compile("^\s*Patch(.*?)\s*:\s*([^\s]+)")
|
|
|
|
applied_patch_regex=re.compile("^\s*%patch([^\s]*)\s")
|
2000-10-11 14:12:27 +08:00
|
|
|
source_dir_regex=re.compile("[^#]*\$RPM_SOURCE_DIR")
|
2001-06-20 19:33:02 +08:00
|
|
|
obsolete_tags_regex=re.compile("^\s*(Copyright|Serial)\s*:\s*([^\s]+)")
|
2000-10-11 14:03:08 +08:00
|
|
|
|
|
|
|
def file2string(file):
|
|
|
|
fd=open(file, "r")
|
|
|
|
content=fd.readlines()
|
|
|
|
fd.close()
|
|
|
|
return content
|
|
|
|
|
|
|
|
class SpecCheck(AbstractCheck.AbstractCheck):
|
|
|
|
|
|
|
|
def __init__(self):
|
2000-10-11 14:12:27 +08:00
|
|
|
AbstractCheck.AbstractCheck.__init__(self, "SpecCheck")
|
2000-10-11 14:03:08 +08:00
|
|
|
|
|
|
|
def check(self, pkg, verbose):
|
|
|
|
if not pkg.isSource():
|
|
|
|
return
|
|
|
|
|
|
|
|
# lookup spec file
|
|
|
|
files=pkg.files()
|
|
|
|
spec_file=None
|
|
|
|
for f in files.keys():
|
|
|
|
if spec_regex.search(f):
|
|
|
|
spec_file=pkg.dirName() + "/" + f
|
|
|
|
break
|
|
|
|
if not spec_file:
|
|
|
|
printError(pkg, "no-spec-file")
|
|
|
|
else:
|
2000-10-11 16:41:39 +08:00
|
|
|
if f != pkg[rpm.RPMTAG_NAME] + ".spec":
|
|
|
|
printError(pkg, "invalid-spec-name", f)
|
|
|
|
|
2000-10-11 14:03:08 +08:00
|
|
|
# check content of spec file
|
|
|
|
spec=file2string(spec_file)
|
|
|
|
patches={}
|
|
|
|
applied_patches=[]
|
2000-10-11 14:12:27 +08:00
|
|
|
source_dir=None
|
2000-10-11 14:03:08 +08:00
|
|
|
# gather info from spec lines
|
|
|
|
for line in spec:
|
|
|
|
res=patch_regex.search(line)
|
|
|
|
if res:
|
|
|
|
patches[res.group(1)]=res.group(2)
|
|
|
|
else:
|
|
|
|
res=applied_patch_regex.search(line)
|
|
|
|
if res:
|
|
|
|
applied_patches.append(res.group(1))
|
2000-10-11 14:12:27 +08:00
|
|
|
elif not source_dir:
|
|
|
|
res=source_dir_regex.search(line)
|
|
|
|
if res:
|
|
|
|
source_dir=1
|
|
|
|
printError(pkg, "use-of-RPM_SOURCE_DIR")
|
2001-06-20 19:33:02 +08:00
|
|
|
res=obsolete_tags_regex.search(line)
|
|
|
|
if res:
|
|
|
|
printWarning(pkg, "obsolete-tag", res.group(1))
|
2000-10-11 14:12:27 +08:00
|
|
|
|
2000-10-11 14:03:08 +08:00
|
|
|
# process gathered info
|
|
|
|
for p in patches.keys():
|
|
|
|
if p not in applied_patches:
|
|
|
|
if p == "" and "0" in applied_patches:
|
|
|
|
continue
|
|
|
|
if p == "0" and "" in applied_patches:
|
|
|
|
continue
|
|
|
|
printWarning(pkg, "patch-not-applied", "Patch" + p + ":", patches[p])
|
|
|
|
|
|
|
|
# Create an object to enable the auto registration of the test
|
|
|
|
check=SpecCheck()
|
|
|
|
|
2001-06-20 19:33:02 +08:00
|
|
|
# Add information about checks
|
|
|
|
if Config.info:
|
|
|
|
addDetails(
|
|
|
|
'obsolete-tag',
|
|
|
|
'''The following tags are obsolete: Copyright and Serial. They must
|
|
|
|
be replaced by License and Epoch respectively.''',
|
|
|
|
)
|
|
|
|
|
2000-10-11 14:03:08 +08:00
|
|
|
# SpecCheck.py ends here
|