How to use the rpmlint.checks.AbstractCheck.AbstractCheck function in rpmlint

To help you get started, we’ve selected a few rpmlint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rpm-software-management / rpmlint / rpmlint / checks / AbstractCheck.py View on Github external
def check(self, pkg):
        if pkg.is_source:
            return self.check_source(pkg)
        return self.check_binary(pkg)

    def check_source(self, pkg):
        return

    def check_binary(self, pkg):
        return

    def check_spec(self, pkg):
        return


class AbstractFilesCheck(AbstractCheck):
    def __init__(self, config, output, file_regexp):
        self.__files_re = re.compile(file_regexp)
        super().__init__(config, output)

    def check_binary(self, pkg):
        for filename in (x for x in pkg.files if x not in pkg.ghost_files):
            if self.__files_re.match(filename):
                self.check_file(pkg, filename)

    def check_file(self, pkg, filename):
        """Virtual method called for each file that match the regexp passed
        to the constructor.
        """
        raise NotImplementedError('check must be implemented in subclass')
github rpm-software-management / rpmlint / rpmlint / checks / LSBCheck.py View on Github external
import re

import rpm
from rpmlint.checks.AbstractCheck import AbstractCheck


class LSBCheck(AbstractCheck):
    """
    Validate that package name, version and release number are LSB compliant.

    The rules are the intersection of compatible NVRs between RPM v3 and DPKG
    for supporting portability across RPM and Debian systems through tools
    like alien.

    Note: It uses values gained from rpm (RPMTAGs) not parsed from .rpm
    filename.
    """
    name_regex = re.compile('^[a-z0-9.+-]+$')
    version_regex = re.compile('^[a-zA-Z0-9.+]+$')

    def check(self, pkg):
        self._check_lsb_name(pkg)
        self._check_lsb_version(pkg)
github rpm-software-management / rpmlint / rpmlint / checks / FilesCheck.py View on Github external
return res.group(1) + '/' + res.group(2) + '.py'

    res = python_bytecode_regex.search(path)
    if res:
        return res.group(1) + '.py'

    return None


def script_interpreter(chunk):
    res = shebang_regex.search(chunk) if chunk else None
    return (byte_to_string(res.group(1)), byte_to_string(res.group(2)).strip()) \
        if res and res.start() == 0 else (None, '')


class FilesCheck(AbstractCheck):

    man_regex = re.compile(r'/man(?:\d[px]?|n)/')
    info_regex = re.compile(r'(/usr/share|/usr)/info/')

    def __init__(self, config, output):
        super().__init__(config, output)
        self.use_debugsource = self.config.configuration['UseDebugSource']
        self.games_group_regex = re.compile(self.config.configuration['RpmGamesGroup'])
        self.dangling_exceptions = self.config.configuration['DanglingSymlinkExceptions']
        self.module_rpms_ok = self.config.configuration['KernelModuleRPMsOK']
        self.python_default_version = self.config.configuration['PythonDefaultVersion']
        self.perl_version_trick = self.config.configuration['PerlVersionTrick']
        self.skipdocs_regex = re.compile(self.config.configuration['SkipDocsRegexp'], re.IGNORECASE)
        self.meta_package_regex = re.compile(self.config.configuration['MetaPackageRegexp'])
        self.use_relative_symlinks = self.config.configuration['UseRelativeSymlinks']
        self.standard_groups = self.config.configuration['StandardGroups']
github rpm-software-management / rpmlint / rpmlint / checks / NamingPolicyCheck.py View on Github external
# File            : NamingPolicyCheck.py
# Author          : Michael Scherer
# Created On      : Mon May 19 11:25:37 2003
# Purpose         : Check package names according to their content.
#############################################################################

import re

from rpmlint.checks.AbstractCheck import AbstractCheck


class NamingPolicyNotAppliedException(Exception):
    pass


class NamingPolicyCheck(AbstractCheck):
    simple_naming_policy_re = re.compile(r'\^[a-zA-Z1-9-_]*$')
    checks_ = []

    def __init__(self, config, output):
        super().__init__(config, output)
        # TODO: rewrite this sanely
        self.add_check('xmms', '^xmms(-|$)', '^/usr/lib(64)?/xmms/')
        self.add_check('python', '^python(-|$)', '^/usr/lib(64)?/python[1-9](-[1-9])?')
        self.add_check('perl5', '^perl(-|$)', '^/usr/lib(64)?/perl5/vendor_perl')
        self.add_check('apache2', '^apache2-mod_', '^/usr/lib(64)?/apache2-')
        self.add_check('fortune', '^fortune(-|$)', '^/usr/share/games/fortunes/')
        self.add_check('php', '^php(-|$)', '/usr/lib(64)?/php/extensions/')
        self.add_check('ruby', '^ruby(-|$)', '/usr/lib(64)?/ruby/[1-9](-[1-9])?/')
        self.add_check('ocaml', '^ocaml(-|$)', '/usr/lib(64)?/ocaml/')

    def add_check(self, pkg_name, name_re, file_re):
github rpm-software-management / rpmlint / rpmlint / checks / I18NCheck.py View on Github external
if ix == -1:
        return False

    # TODO: don't accept all lang_COUNTRY combinations
    country = lang[ix + 1:]
    if country not in COUNTRIES:
        return False

    lang = lang[0:ix]
    if lang not in LANGUAGES:
        return False

    return True


class I18NCheck(AbstractCheck):
    def check_binary(self, pkg):
        files = list(pkg.files.keys())
        files.sort()
        locales = []                      # list of locales for this packages
        webapp = False

        i18n_tags = pkg[rpm.RPMTAG_HEADERI18NTABLE] or ()

        for i in i18n_tags:
            try:
                correct = INCORRECT_LOCALES[i]
                self.output.add_info('E', pkg, 'incorrect-i18n-tag-' + correct, i)
            except KeyError:
                pass

        # as some webapps have their files under /var/www/html, and
github rpm-software-management / rpmlint / rpmlint / checks / ConfigFilesCheck.py View on Github external
from rpmlint.checks.AbstractCheck import AbstractCheck


class ConfigFilesCheck(AbstractCheck):
    """
    Check that configuration files are in a proper location and marked as
    'noreplace'.
    """
    def check_binary(self, pkg):
        for filename in pkg.config_files:
            self._check_non_confdir_files(pkg, filename)
            self._check_noreplace_files(pkg, filename)

    def _check_non_confdir_files(self, pkg, fn):
        """
        Check if the configuration file is in /etc or /var directory.

        Print a warning if it's not.
        """
        if not fn.startswith('/etc/') and not fn.startswith('/var/'):
github rpm-software-management / rpmlint / rpmlint / checks / BinariesCheck.py View on Github external
import concurrent.futures
from pathlib import Path
import re
import stat

import rpm
from rpmlint.checks.AbstractCheck import AbstractCheck
from rpmlint.lddparser import LddParser
from rpmlint.objdumpparser import ObjdumpParser
from rpmlint.readelfparser import ReadelfParser
from rpmlint.stringsparser import StringsParser


class BinariesCheck(AbstractCheck):
    """
    Checks for binary files in the package.
    """
    srcname_regex = re.compile(r'(.*?)-[0-9]')
    validso_regex = re.compile(r'(\.so\.\d+(\.\d+)*|\d\.so)$')
    soversion_regex = re.compile(r'.*?([0-9][.0-9]*)\.so|.*\.so\.([0-9][.0-9]*).*')
    usr_lib_regex = re.compile(r'^/usr/lib(64)?/')
    ldso_soname_regex = re.compile(r'^ld(-linux(-(ia|x86_)64))?\.so')

    numeric_dir_regex = re.compile(r'/usr(?:/share)/man/man./(.*)\.[0-9](?:\.gz|\.bz2)')
    versioned_dir_regex = re.compile(r'[^.][0-9]')
    so_regex = re.compile(r'/lib(64)?/[^/]+\.so(\.[0-9]+)*$')
    bin_regex = re.compile(r'^(/usr(/X11R6)?)?/s?bin/')
    la_file_regex = re.compile(r'\.la$')
    invalid_dir_ref_regex = re.compile(r'/(home|tmp)(\W|$)')
    usr_arch_share_regex = re.compile(r'/share/.*/(?:x86|i.86|x86_64|ppc|ppc64|s390|s390x|ia64|m68k|arm|aarch64|mips|riscv)')
github rpm-software-management / rpmlint / rpmlint / checks / ConfigCheck.py View on Github external
#############################################################################
# File          : ConfigCheck.py
# Package       : rpmlint
# Author        : Frederic Lepied
# Created on    : Sun Oct  3 21:48:20 1999
# Purpose       :
#############################################################################

from rpmlint.checks.AbstractCheck import AbstractCheck


class ConfigCheck(AbstractCheck):
    def __init__(self, config, output):
        super().__init__(config, output)
        self.output.error_details.update(config_details_dict)

    def check_binary(self, pkg):
        config_files = pkg.configFiles()
        noreplace_files = pkg.noreplaceFiles()

        for c in config_files:
            if c.startswith('/var/lib/games/'):
                self.output.add_info('E', pkg, 'score-file-must-not-be-conffile', c)
            elif not c.startswith('/etc/') and not c.startswith('/var/'):
                self.output.add_info('W', pkg, 'non-etc-or-var-file-marked-as-conffile', c)
            if c not in noreplace_files:
                self.output.add_info('W', pkg, 'conffile-without-noreplace-flag', c)
github rpm-software-management / rpmlint / scripts / lint.py View on Github external
def runSpecChecks(pkg, fname, spec_lines=None):
    for name in cfg.configuration['Checks']:
        check = AbstractCheck.known_checks.get(name)
        if check:
            check.verbose = verbose
            check.check_spec(pkg, fname, spec_lines)
        else:
            print_warning('(none): W: unknown check %s, skipping' % name)
github rpm-software-management / rpmlint / rpmlint / checks / SysVInitOnSystemdCheck.py View on Github external
from pathlib import Path

from rpmlint.checks.AbstractCheck import AbstractCheck


class SysVInitOnSystemdCheck(AbstractCheck):
    def __init__(self, config, output):
        super().__init__(config, output)
        self.initscripts = set()
        self.bootscripts = set()
        self.systemdscripts = set()

    def check(self, pkg):
        if pkg.is_source:
            return

        self._find_services_and_scripts(pkg)

        for req in pkg.requires + pkg.prereq:
            if req[0] == 'insserv':
                self.output.add_info('E', pkg, 'obsolete-insserv-requirement')