Move regex that matches macros to AbstractCheck, use it, improve misspelled-macro info message.

git-svn-id: svn+ssh://rpmlint.zarb.org/home/projects/rpmlint/svn/trunk@1619 9bc8b190-ac0f-0410-8968-dc7d1f502856
This commit is contained in:
Ville Skyttä 2009-07-21 18:16:25 +00:00
parent ad0d6a882c
commit 005b606122
3 changed files with 9 additions and 7 deletions

View File

@ -11,6 +11,8 @@
import re import re
macro_regex = re.compile('(%+)[{(]?(\w+)')
class AbstractCheck: class AbstractCheck:
known_checks = {} known_checks = {}

View File

@ -205,7 +205,6 @@ log_regex = re.compile('^/var/log/[^/]+$')
lib_path_regex = re.compile('^(/usr(/X11R6)?)?/lib(64)?') lib_path_regex = re.compile('^(/usr(/X11R6)?)?/lib(64)?')
lib_package_regex = re.compile('^(lib|.+-libs)') lib_package_regex = re.compile('^(lib|.+-libs)')
hidden_file_regex = re.compile('/\.[^/]*$') hidden_file_regex = re.compile('/\.[^/]*$')
misspelled_macro_regex = re.compile('%{.*}')
siteperl_perl_regex = re.compile('/site_perl/') siteperl_perl_regex = re.compile('/site_perl/')
manifest_perl_regex = re.compile('^/usr/share/doc/perl-.*/MANIFEST(\.SKIP)?$') manifest_perl_regex = re.compile('^/usr/share/doc/perl-.*/MANIFEST(\.SKIP)?$')
shebang_regex = re.compile('^#!\s*(\S*)') shebang_regex = re.compile('^#!\s*(\S*)')
@ -329,8 +328,9 @@ class FilesCheck(AbstractCheck.AbstractCheck):
is_doc = f in doc_files is_doc = f in doc_files
nonexec_file = False nonexec_file = False
if misspelled_macro_regex.search(f): res = AbstractCheck.macro_regex.search(f)
printWarning(pkg, 'misspelled-macro', f) if res:
printWarning(pkg, 'misspelled-macro', f, res.group(2))
if standard_users and user not in standard_users: if standard_users and user not in standard_users:
printWarning(pkg, 'non-standard-uid', f, user) printWarning(pkg, 'non-standard-uid', f, user)
if standard_groups and group not in standard_groups: if standard_groups and group not in standard_groups:
@ -969,8 +969,9 @@ for the wrong kernel.''',
configuration for them.''', configuration for them.''',
'misspelled-macro', 'misspelled-macro',
'''This package contains a file which matches %{.*}; this is often the sign '''This package contains a file which contains something that looks like an
of a misspelled macro. Please check your spec file.''', unexpanded macro; this is often the sign of a misspelling. Please check your
specfile.''',
'manifest-in-perl-module', 'manifest-in-perl-module',
'''This perl module package contains a MANIFEST or a MANIFEST.SKIP file '''This perl module package contains a MANIFEST or a MANIFEST.SKIP file

View File

@ -48,7 +48,6 @@ hardcoded_lib_path_exceptions_regex = re.compile(Config.getOption('HardcodedLibP
prereq_regex = re.compile('^PreReq(\(.*\))?:\s*(.+?)\s*$', re.IGNORECASE) prereq_regex = re.compile('^PreReq(\(.*\))?:\s*(.+?)\s*$', re.IGNORECASE)
buildprereq_regex = re.compile('^BuildPreReq:\s*(.+?)\s*$', re.IGNORECASE) buildprereq_regex = re.compile('^BuildPreReq:\s*(.+?)\s*$', re.IGNORECASE)
use_utf8 = Config.getOption('UseUTF8', Config.USEUTF8_DEFAULT) use_utf8 = Config.getOption('UseUTF8', Config.USEUTF8_DEFAULT)
macro_regex = re.compile('(%+)[{(]?(\w+)')
libdir_regex = re.compile('%{?_lib(?:dir)?\}?\\b') libdir_regex = re.compile('%{?_lib(?:dir)?\}?\\b')
comment_or_empty_regex = re.compile('^\s*(#|$)') comment_or_empty_regex = re.compile('^\s*(#|$)')
defattr_regex = re.compile('^\s*%defattr\\b') defattr_regex = re.compile('^\s*%defattr\\b')
@ -409,7 +408,7 @@ class SpecCheck(AbstractCheck.AbstractCheck):
conf) conf)
if current_section == 'changelog': if current_section == 'changelog':
res = macro_regex.search(line) res = AbstractCheck.macro_regex.search(line)
if res and len(res.group(1)) % 2: if res and len(res.group(1)) % 2:
printWarning(pkg, 'macro-in-%changelog', res.group(2)) printWarning(pkg, 'macro-in-%changelog', res.group(2))
else: else: