Replace bunch of trivial regexps with simple string searches.
git-svn-id: svn+ssh://rpmlint.zarb.org/home/projects/rpmlint/svn/trunk@1675 9bc8b190-ac0f-0410-8968-dc7d1f502856
This commit is contained in:
parent
853b0c7b5d
commit
c8b21eda64
|
@ -33,10 +33,8 @@ class BinaryInfo:
|
|||
# GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x4
|
||||
stack_regex = re.compile('^\s+GNU_STACK\s+(?:(?:\S+\s+){5}(\S+)\s+)?')
|
||||
stack_exec_regex = re.compile('^..E$')
|
||||
non_pic_regex = re.compile('TEXTREL', re.MULTILINE)
|
||||
undef_regex = re.compile('^undefined symbol:\s+(\S+)')
|
||||
unused_regex = re.compile('^\s+(\S+)')
|
||||
debug_file_regex = re.compile('\.debug$')
|
||||
exit_call_regex = re.compile('\s+FUNC\s+.*?\s+(_?exit(?:@\S+)?)(?:\s|$)')
|
||||
fork_call_regex = re.compile('\s+FUNC\s+.*?\s+(fork(?:@\S+)?)(?:\s|$)')
|
||||
|
||||
|
@ -55,7 +53,7 @@ class BinaryInfo:
|
|||
fork_called = False
|
||||
self.tail = ''
|
||||
|
||||
is_debug = BinaryInfo.debug_file_regex.search(path)
|
||||
is_debug = path.endswith('.debug')
|
||||
|
||||
cmd = ['env', 'LC_ALL=C', 'readelf', '-W', '-S', '-l', '-d', '-s']
|
||||
cmd.append(path)
|
||||
|
@ -106,7 +104,7 @@ class BinaryInfo:
|
|||
continue
|
||||
|
||||
if self.non_pic:
|
||||
self.non_pic = BinaryInfo.non_pic_regex.search(res[1])
|
||||
self.non_pic = 'TEXTREL' in res[1]
|
||||
|
||||
# Ignore all exit() calls if fork() is being called.
|
||||
# Does not have any context at all but without this kludge, the
|
||||
|
@ -164,12 +162,8 @@ class BinaryInfo:
|
|||
path_regex = re.compile('(.*/)([^/]+)')
|
||||
numeric_dir_regex = re.compile('/usr(?:/share)/man/man./(.*)\.[0-9](?:\.gz|\.bz2)')
|
||||
versioned_dir_regex = re.compile('[^.][0-9]')
|
||||
usr_share = re.compile('^/usr/share/')
|
||||
etc = re.compile('^/etc/')
|
||||
not_stripped = re.compile('not stripped')
|
||||
unstrippable = re.compile('\.o$|\.static$')
|
||||
shared_object_regex = re.compile('shared object')
|
||||
executable_regex = re.compile('executable')
|
||||
libc_regex = re.compile('libc\.')
|
||||
ldso_soname_regex = re.compile('^ld(-linux(-(ia|x86_)64))?\.so')
|
||||
so_regex = re.compile('/lib(64)?/[^/]+\.so(\.[0-9]+)*$')
|
||||
|
@ -239,11 +233,11 @@ class BinariesCheck(AbstractCheck.AbstractCheck):
|
|||
printError(pkg, 'arch-independent-package-contains-binary-or-object', fname)
|
||||
else:
|
||||
# in /usr/share ?
|
||||
if usr_share.search(fname):
|
||||
if fname.startswith('/usr/share/'):
|
||||
printError(
|
||||
pkg, 'arch-dependent-file-in-usr-share', fname)
|
||||
# in /etc ?
|
||||
if etc.search(fname):
|
||||
if fname.startswith('/etc/'):
|
||||
printError(pkg, 'binary-in-etc', fname)
|
||||
|
||||
if pkg.arch == 'sparc' and \
|
||||
|
@ -252,7 +246,7 @@ class BinariesCheck(AbstractCheck.AbstractCheck):
|
|||
|
||||
# stripped ?
|
||||
if not is_ocaml_native and not unstrippable.search(fname):
|
||||
if not_stripped.search(pkgfile.magic):
|
||||
if 'not stripped' in pkgfile.magic:
|
||||
printWarning(
|
||||
pkg, 'unstripped-binary-or-object', fname)
|
||||
|
||||
|
@ -307,7 +301,7 @@ class BinariesCheck(AbstractCheck.AbstractCheck):
|
|||
printWarning(
|
||||
pkg, 'shared-lib-calls-exit', fname, ec)
|
||||
|
||||
is_exec = executable_regex.search(pkgfile.magic)
|
||||
is_exec = 'executable' in pkgfile.magic
|
||||
if is_exec or \
|
||||
shared_object_regex.search(pkgfile.magic):
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import Config
|
|||
|
||||
man_regex = re.compile("/man(?:\d[px]?|n)/")
|
||||
info_regex = re.compile("(/usr/share|/usr)/info/")
|
||||
info_dir_regex = re.compile("/info/dir$")
|
||||
vendor = Config.getOption("Vendor")
|
||||
distribution = Config.getOption("Distribution")
|
||||
use_bzip2 = Config.getOption("UseBzip2", True)
|
||||
|
@ -62,7 +61,7 @@ class DistributionCheck(AbstractCheck.AbstractCheck):
|
|||
printWarning(pkg, "manpage-not-compressed-with-gzip",
|
||||
fname)
|
||||
|
||||
if info_regex.search(fname) and not info_dir_regex.search(fname):
|
||||
if info_regex.search(fname) and not fname.endswith("/info/dir"):
|
||||
if use_bzip2:
|
||||
if not fname.endswith('.bz2'):
|
||||
printWarning(pkg, "infopage-not-compressed-with-bzip2",
|
||||
|
|
|
@ -207,7 +207,6 @@ log_regex = re.compile('^/var/log/[^/]+$')
|
|||
lib_path_regex = re.compile('^(/usr(/X11R6)?)?/lib(64)?')
|
||||
lib_package_regex = re.compile('^(lib|.+-libs)')
|
||||
hidden_file_regex = re.compile('/\.[^/]*$')
|
||||
siteperl_perl_regex = re.compile('/site_perl/')
|
||||
manifest_perl_regex = re.compile('^/usr/share/doc/perl-.*/MANIFEST(\.SKIP)?$')
|
||||
shebang_regex = re.compile('^#!\s*(\S*)')
|
||||
interpreter_regex = re.compile('^/(usr/)?(s?bin|games|libexec(/.+)?|(lib(64)?|share)/.+)/[^/]+$')
|
||||
|
@ -373,7 +372,7 @@ class FilesCheck(AbstractCheck.AbstractCheck):
|
|||
printWarning(pkg, 'hidden-file-or-dir', f)
|
||||
elif manifest_perl_regex.search(f):
|
||||
printWarning(pkg, 'manifest-in-perl-module', f)
|
||||
elif siteperl_perl_regex.search(f):
|
||||
elif '/site_perl/' in f:
|
||||
printWarning(pkg, 'siteperl-in-perl-module', f)
|
||||
elif f == '/usr/info/dir' or f == '/usr/share/info/dir':
|
||||
printError(pkg, 'info-dir-file', f)
|
||||
|
|
|
@ -20,7 +20,6 @@ import Config
|
|||
import Pkg
|
||||
|
||||
|
||||
rc_regex = re.compile('^/etc(/rc\.d)?/init\.d/')
|
||||
chkconfig_content_regex = re.compile('^\s*#\s*chkconfig:\s*([-0-9]+)\s+[-0-9]+\s+[-0-9]+')
|
||||
subsys_regex = re.compile('/var/lock/subsys/([^/"\'\n\s;&|]+)', re.MULTILINE)
|
||||
chkconfig_regex = re.compile('^[^#]*(chkconfig|add-service|del-service)', re.MULTILINE)
|
||||
|
@ -49,7 +48,8 @@ class InitScriptCheck(AbstractCheck.AbstractCheck):
|
|||
|
||||
initscript_list = []
|
||||
for fname, pkgfile in pkg.files().items():
|
||||
if rc_regex.search(fname):
|
||||
if fname.startswith('/etc/init.d/') or \
|
||||
fname.startswith('/etc/rc.d/init.d/'):
|
||||
basename = os.path.basename(fname)
|
||||
initscript_list.append(basename)
|
||||
if pkgfile.mode & 0500 != 0500:
|
||||
|
|
|
@ -148,8 +148,6 @@ xpm_ext_regex = re.compile('/usr/share/icons/(mini/|large/).*\.xpm$')
|
|||
icon_ext_regex = re.compile(Config.getOption('IconFilename', '.*\.png$'))
|
||||
version_regex = re.compile('([0-9.][0-9.]+)($|\s)')
|
||||
launchers = Config.getOption('MenuLaunchers', DEFAULT_LAUNCHERS)
|
||||
bad_title_regex = re.compile('/')
|
||||
menu64_file_regex = re.compile('^/usr/lib64/menu')
|
||||
xdg_migrated_regex = re.compile('xdg=\"?([^\" ]+)')
|
||||
|
||||
# compile regexps
|
||||
|
@ -198,7 +196,7 @@ class MenuCheck(AbstractCheck.AbstractCheck):
|
|||
if res:
|
||||
if stat.S_ISREG(mode) and not pkg.grep('None",', fname):
|
||||
printWarning(pkg, 'non-transparent-xpm', fname)
|
||||
if menu64_file_regex.search(fname):
|
||||
if fname.startswith('/usr/lib64/menu'):
|
||||
printError(pkg, 'menu-in-wrong-dir', fname)
|
||||
|
||||
if menus:
|
||||
|
@ -287,7 +285,7 @@ class MenuCheck(AbstractCheck.AbstractCheck):
|
|||
res = version_regex.search(title)
|
||||
if res:
|
||||
printWarning(pkg, 'version-in-menu-title', title)
|
||||
if bad_title_regex.search(title):
|
||||
if '/' in title:
|
||||
printError(pkg, 'invalid-title', title)
|
||||
else:
|
||||
printError(pkg, 'no-title-in-menu', f)
|
||||
|
|
|
@ -43,7 +43,6 @@ home_regex = re.compile('[^a-zA-Z]+~/|\${?HOME(\W|$)', re.MULTILINE)
|
|||
dangerous_command_regex = re.compile("(^|[;\|`]|&&|$\()\s*(?:\S*/s?bin/)?(cp|mv|ln|tar|rpm|chmod|chown|rm|cpio|install|perl|userdel|groupdel)\s", re.MULTILINE)
|
||||
selinux_regex = re.compile("(^|[;\|`]|&&|$\()\s*(?:\S*/s?bin/)?(chcon|runcon)\s", re.MULTILINE)
|
||||
single_command_regex = re.compile("^[ \n]*([^ \n]+)[ \n]*$")
|
||||
update_menu_regex = re.compile('update-menus', re.MULTILINE)
|
||||
tmp_regex = re.compile('\s(/var)?/tmp', re.MULTILINE)
|
||||
menu_regex = re.compile('^/usr/lib/menu/|^/etc/menu-methods/|^/usr/share/applications/')
|
||||
bogus_var_regex = re.compile('(\${?RPM_BUILD_(ROOT|DIR)}?)')
|
||||
|
@ -154,7 +153,7 @@ class PostCheck(AbstractCheck.AbstractCheck):
|
|||
if res:
|
||||
printError(pkg, 'forbidden-selinux-command-in-' + tag[2], res.group(2))
|
||||
|
||||
if update_menu_regex.search(script):
|
||||
if 'update-menus' in script:
|
||||
menu_error = True
|
||||
for f in files:
|
||||
if menu_regex.search(f):
|
||||
|
|
|
@ -36,10 +36,8 @@ noarch_regex = re.compile('^BuildArch(?:itectures)?\s*:\s*\\bnoarch\\b', re.IGNO
|
|||
make_check_regex = re.compile('(^|\s|%{?__)make}?\s+(check|test)')
|
||||
rm_regex = re.compile('(^|\s)((.*/)?rm|%{?__rm}?) ')
|
||||
rpm_buildroot_regex = re.compile('(\\\*)\${?RPM_BUILD_ROOT}?|(%+){?buildroot}?')
|
||||
configure_start_regex = re.compile('\./configure')
|
||||
configure_libdir_spec_regex = re.compile('ln |\./configure[^#]*--libdir=([^\s]+)[^#]*')
|
||||
lib_package_regex = re.compile('^%package.*\Wlib')
|
||||
mklibname_regex = re.compile('%mklibname')
|
||||
ifarch_regex = re.compile('%ifn?arch\s+')
|
||||
if_regex = re.compile('%if\s+')
|
||||
endif_regex = re.compile('%endif\\b')
|
||||
|
@ -323,7 +321,7 @@ class SpecCheck(AbstractCheck.AbstractCheck):
|
|||
printError(pkg, "hardcoded-library-path", res.group(1), "in configure options")
|
||||
configure_linenum = None
|
||||
|
||||
if current_section != 'changelog' and configure_start_regex.search(line):
|
||||
if current_section != 'changelog' and './configure' in line:
|
||||
configure_linenum = pkg.current_linenum # store line where it started
|
||||
configure_cmdline = line.strip()
|
||||
|
||||
|
@ -331,7 +329,7 @@ class SpecCheck(AbstractCheck.AbstractCheck):
|
|||
if current_section != 'changelog' and res and not (biarch_package_regex.match(pkg.name) or hardcoded_lib_path_exceptions_regex.search(res.group(1).lstrip())):
|
||||
printError(pkg, "hardcoded-library-path", "in", res.group(1).lstrip())
|
||||
|
||||
if mklibname_regex.search(line):
|
||||
if '%mklibname' in line:
|
||||
mklibname = True
|
||||
|
||||
if current_section == 'package':
|
||||
|
|
Loading…
Reference in New Issue