How to use the rpmlint.helpers.ENGLISH_ENVIROMENT 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 / AppDataCheck.py View on Github external
def check_file(self, pkg, filename):
        root = pkg.dirName()
        f = root + filename
        cmd = self.cmd + f

        validation_failed = False
        try:
            r = subprocess.run(cmd.split(), env=ENGLISH_ENVIROMENT)
            if r.returncode != 0:
                validation_failed = True
        except FileNotFoundError:
            # appstream-util is not installed
            # validate the xml format only
            try:
                ElementTree.parse(f)
            except ElementTree.ParseError:
                validation_failed = True
        if validation_failed:
            self.output.add_info('E', pkg, 'invalid-appdata-file', filename)
github rpm-software-management / rpmlint / rpmlint / checks / MenuXDGCheck.py View on Github external
def check_file(self, pkg, filename):
        root = pkg.dirName()
        f = root + filename
        command = subprocess.run(('desktop-file-validate', f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=ENGLISH_ENVIROMENT)
        text = command.stdout.decode()
        if command.returncode:
            error_printed = False
            for line in text.splitlines():
                if 'error: ' in line:
                    self.output.add_info('E', pkg, 'invalid-desktopfile', filename,
                                         line.split('error: ')[1])
                    error_printed = True
            if not error_printed:
                self.output.add_info('E', pkg, 'invalid-desktopfile', filename)

        self.parse_desktop_file(pkg, root, f, filename)
github rpm-software-management / rpmlint / rpmlint / objdumpparser.py View on Github external
def parse_dwarf_compilation_units(self):
        r = subprocess.run(['objdump', '--dwarf=info', '--dwarf-depth=1', self.pkgfile_path], encoding='utf8',
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT)
        # here ldd should always return 0
        if r.returncode != 0:
            self.parsing_failed_reason = r.stderr
            return

        lines = r.stdout.splitlines()
        for i, line in enumerate(lines):
            if 'DW_TAG_compile_unit' in line:
                # We parse all DW_at_ flags that follow the DW_TAG_compile_unit
                i += 1
                cu_data = {}
                while self.dw_at_prefix in lines[i]:
                    current_line = lines[i]
                    current_line = current_line[current_line.find(self.dw_at_prefix) + len(self.dw_at_prefix):]
                    parts = [t.strip() for t in current_line.split(':')]
                    cu_data[parts[0]] = parts[-1]
github rpm-software-management / rpmlint / rpmlint / checks / BashismsCheck.py View on Github external
def check_bashisms(self, pkg, filepath, filename):
        """
        Run dash and then checkbashism on file

        We need to see if it is valid syntax of bash and if there are no
        potential bash issues.
        """
        try:
            r = subprocess.run(['dash', '-n', filepath], env=ENGLISH_ENVIROMENT)
            if r.returncode == 2:
                self.output.add_info('W', pkg, 'bin-sh-syntax-error', filename)
        except (FileNotFoundError, UnicodeDecodeError):
            pass

        try:
            r = subprocess.run(['checkbashisms', filepath], env=ENGLISH_ENVIROMENT)
            if r.returncode == 1:
                self.output.add_info('W', pkg, 'potential-bashisms', filename)
        except (FileNotFoundError, UnicodeDecodeError):
            pass
github rpm-software-management / rpmlint / rpmlint / stringsparser.py View on Github external
def parse(self):
        r = subprocess.run(['strings', self.pkgfile_path], encoding='utf8',
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT)
        if r.returncode != 0:
            self.parsing_failed_reason = r.stderr
            return

        self.strings = r.stdout.splitlines()
github rpm-software-management / rpmlint / rpmlint / pkg.py View on Github external
def _extract(self, dirname):
        if not Path(dirname).is_dir():
            print_warning('Unable to access dir %s' % dirname)
        else:
            dirname = dirname if dirname != '/' else None
            self.__tmpdir = tempfile.TemporaryDirectory(
                prefix='rpmlint.%s.' % Path(self.filename).name, dir=dirname
            )
            dirname = self.__tmpdir.name
            # TODO: sequence based command invocation
            # TODO: warn some way if this fails (e.g. rpm2cpio not installed)
            command_str = \
                'rpm2cpio %(f)s | cpio -id -D %(d)s ; chmod -R +rX %(d)s' % \
                {'f': quote(str(self.filename)), 'd': quote(dirname)}
            subprocess.run(command_str, shell=True, env=ENGLISH_ENVIROMENT)
            self.extracted = True
        return dirname
github rpm-software-management / rpmlint / rpmlint / checks / BashismsCheck.py View on Github external
def check_bashisms(self, pkg, filepath, filename):
        """
        Run dash and then checkbashism on file

        We need to see if it is valid syntax of bash and if there are no
        potential bash issues.
        """
        try:
            r = subprocess.run(['dash', '-n', filepath], env=ENGLISH_ENVIROMENT)
            if r.returncode == 2:
                self.output.add_info('W', pkg, 'bin-sh-syntax-error', filename)
        except (FileNotFoundError, UnicodeDecodeError):
            pass

        try:
            r = subprocess.run(['checkbashisms', filepath], env=ENGLISH_ENVIROMENT)
            if r.returncode == 1:
                self.output.add_info('W', pkg, 'potential-bashisms', filename)
        except (FileNotFoundError, UnicodeDecodeError):
            pass
github rpm-software-management / rpmlint / rpmlint / checks / MenuCheck.py View on Github external
if not postin:
                self.output.add_info('E', pkg, 'menu-without-postin')
            elif not update_menus_regex.search(postin):
                self.output.add_info('E', pkg, 'postin-without-update-menus')

            postun = pkg[rpm.RPMTAG_POSTUN] or \
                pkg.scriptprog(rpm.RPMTAG_POSTUNPROG)
            if not postun:
                self.output.add_info('E', pkg, 'menu-without-postun')
            elif not update_menus_regex.search(postun):
                self.output.add_info('E', pkg, 'postun-without-update-menus')

            directory = pkg.dirName()
            for f in menus:
                # remove comments and handle cpp continuation lines
                text = subprocess.run(('/lib/cpp', directory + f), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=ENGLISH_ENVIROMENT).stdout.decode()
                if text.endswith('\n'):
                    text = text[:-1]

                for line in text.splitlines():
                    if not line.startswith('?'):
                        continue
                    res = package_regex.search(line)
                    if res:
                        package = res.group(1)
                        if package != pkg.name:
                            self.output.add_info('W', pkg,
                                                 'incoherent-package-value-in-menu',
                                                 package, f)
                    else:
                        self.output.add_info('I', pkg, 'unable-to-parse-menu-entry', line)
github rpm-software-management / rpmlint / rpmlint / checks / PostCheck.py View on Github external
def check_syntax_script(prog, commandline, script):
    if not script:
        return False
    if isinstance(script, str):
        script = script.encode('utf-8')
    # TODO: test that 'prog' is available/executable
    tmpfd, tmpname = tempfile.mkstemp(prefix='rpmlint.')
    tmpfile = os.fdopen(tmpfd, 'wb')
    try:
        tmpfile.write(script)
        tmpfile.close()
        ret = subprocess.run((prog, commandline, tmpname), env=ENGLISH_ENVIROMENT)
    finally:
        tmpfile.close()
        os.remove(tmpname)
    return ret.returncode
github rpm-software-management / rpmlint / rpmlint / readelfparser.py View on Github external
def parse(self):
        r = subprocess.run(['readelf', '-W', '-l', self.path], encoding='utf8',
                           stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENGLISH_ENVIROMENT)
        if r.returncode != 0:
            self.parsing_failed_reason = r.stderr
            return

        lines = r.stdout.splitlines()
        needle = 'Program Headers:'

        while len(lines) > 0:
            lines = list(dropwhile(lambda x: needle not in x, lines))

            # skip header
            lines = lines[2:]

            sections = list(takewhile(lambda x: x.strip() != '', lines))
            for s in sections:
                r = self.header_regex.search(s)