How to use the rpmlint.helpers.byte_to_string 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 / test / test_helpers.py View on Github external
def test_bytetostr():
    """
    Test bytetostr function
    """
    list_items = (
        b'\xc5\xbe\xc3\xad\xc5\xbeala',
        'texty',
    )
    item = b'p\xc5\x99\xc3\xad\xc5\xa1ern\xc4\x9b \xc5\xbelu\xc5\xa5ou\xc4\x8dk\xc3\xbd k\xc5\xaf\xc5\x88'

    result = helpers.byte_to_string(item)
    assert isinstance(result, str)
    assert result == 'příšerně žluťoučký kůň'

    result = helpers.byte_to_string(list_items)
    assert isinstance(result, list)
    assert result[0] == 'žížala'
github rpm-software-management / rpmlint / rpmlint / checks / TagsCheck.py View on Github external
Pkg.formatRequire(*prov)))

        expfmt = rpm.expandMacro('%{_build_name_fmt}')
        if pkg.is_source:
            # _build_name_fmt often (always?) ends up not outputting src/nosrc
            # as arch for source packages, do it ourselves
            expfmt = re.sub(r'(?i)%\{?ARCH\b\}?', pkg.arch, expfmt)
        expected = pkg.header.sprintf(expfmt).split('/')[-1]
        basename = Path(pkg.filename).parent
        if basename != expected:
            self.output.add_info('W', pkg, 'non-coherent-filename', basename, expected)

        for tag in ('Distribution', 'DistTag', 'ExcludeArch', 'ExcludeOS',
                    'Vendor'):
            if hasattr(rpm, 'RPMTAG_%s' % tag.upper()):
                res = byte_to_string(pkg[getattr(rpm, 'RPMTAG_%s' % tag.upper())])
                self._unexpanded_macros(pkg, tag, res)
github rpm-software-management / rpmlint / rpmlint / checks / ErlangCheck.py View on Github external
def check_file(self, pkg, filename):
        beam = BeamFile(pkg.files[filename].path)
        compile_state = byte_to_string(beam.compileinfo['source'].value)
        if 'debug_info' not in beam.compileinfo['options']:
            self.output.add_info('E', pkg, 'beam-compiled-without-debuginfo', filename)
        # This can't be an error as builddir can be user specific and vary between users
        # it could be error in OBS where all the builds are done by user abuild, not in
        # general.
        if not self.source_re.match(compile_state):
            self.output.add_info('W', pkg, 'beam-was-not-recompiled', filename, compile_state)
github rpm-software-management / rpmlint / rpmlint / checks / AlternativesCheck.py View on Github external
def _normalize_script(self, script):
        """
        Remove "backslash+newline" to keep all commands as oneliners.
        Remove single and double quotes everywhere.
        Keep only the line that contains the update-alternatives call.
        Return the list of lines that contain update-alternatives calls
        """
        # with old rpm we get wrong type
        script = byte_to_string(script)
        script.replace('\\\n', '')
        script.replace('"', '')
        script.replace("'", '')
        script.strip()
        return [i for i in script.splitlines() if self.command in i]
github rpm-software-management / rpmlint / rpmlint / checks / FilesCheck.py View on Github external
def check(self, pkg):

        for filename in pkg.header[rpm.RPMTAG_FILENAMES] or ():
            if not is_utf8_bytestr(filename):
                self.output.add_info('E', pkg, 'filename-not-utf8', byte_to_string(filename))

        # Rest of the checks are for binary packages only
        if pkg.is_source:
            return

        files = pkg.files

        # Check if the package is a development package
        devel_pkg = devel_regex.search(pkg.name)

        if not devel_pkg:
            for p in pkg.provides:
                if devel_regex.search(p[0]):
                    devel_pkg = True
                    break
github rpm-software-management / rpmlint / rpmlint / checks / TagsCheck.py View on Github external
ignored_words.update((x[0] for x in pkg.conflicts))
        ignored_words.update((x[0] for x in pkg.obsoletes))

        langs = pkg[rpm.RPMTAG_HEADERI18NTABLE]

        summary = byte_to_string(pkg[rpm.RPMTAG_SUMMARY])
        if summary:
            if not langs:
                self._unexpanded_macros(pkg, 'Summary', summary)
            else:
                for lang in langs:
                    self.check_summary(pkg, lang, ignored_words)
        else:
            self.output.add_info('E', pkg, 'no-summary-tag')

        description = byte_to_string(pkg[rpm.RPMTAG_DESCRIPTION])
        if description:
            if not langs:
                self._unexpanded_macros(pkg, '%description', description)
            else:
                for lang in langs:
                    self.check_description(pkg, lang, ignored_words)

            if len(description) < len(pkg[rpm.RPMTAG_SUMMARY]):
                self.output.add_info('W', pkg, 'description-shorter-than-summary')
        else:
            self.output.add_info('E', pkg, 'no-description-tag')

        group = pkg[rpm.RPMTAG_GROUP]
        self._unexpanded_macros(pkg, 'Group', group)
        if not group:
            self.output.add_info('E', pkg, 'no-group-tag')
github rpm-software-management / rpmlint / rpmlint / checks / TagsCheck.py View on Github external
def check_description(self, pkg, lang, ignored_words):
        description = pkg.langtag(rpm.RPMTAG_DESCRIPTION, lang)
        if not Pkg.is_utf8_bytestr(description):
            self.output.add_info('E', pkg, 'tag-not-utf8', '%description', lang)
        description = byte_to_string(description)
        self._unexpanded_macros(pkg, '%%description -l %s' % lang, description)
        if self.spellcheck:
            pkgname = byte_to_string(pkg.header[rpm.RPMTAG_NAME])
            typos = self.spellchecker.spell_check(description, '%description -l {}', lang, pkgname, ignored_words)
            for typo in typos.items():
                self.output.add_info('E', pkg, 'spelling-error', typo)
        for i in description.splitlines():
            if len(i) > self.max_line_len:
                self.output.add_info('E', pkg, 'description-line-too-long', lang, i)
            res = self.forbidden_words_regex.search(i)
            if res and self.config.configuration['ForbiddenWords']:
                self.output.add_info('W', pkg, 'description-use-invalid-word', lang,
                                     res.group(1))
            res = tag_regex.search(i)
            if res:
                self.output.add_info('W', pkg, 'tag-in-description', lang, res.group(1))
github rpm-software-management / rpmlint / rpmlint / rpmdiff.py View on Github external
for oldentry in o:
            if oldentry not in n:
                namestr = name
                if namestr == 'REQUIRES':
                    namestr = self.req2str(oldentry[1])
                self.__add(self.DEPFORMAT,
                           (self.REMOVED, namestr, byte_to_string(oldentry[0]),
                            self.sense2str(oldentry[1]), byte_to_string(oldentry[2])))
        for newentry in n:
            if newentry not in o:
                namestr = name
                if namestr == 'REQUIRES':
                    namestr = self.req2str(newentry[1])
                self.__add(self.DEPFORMAT,
                           (self.ADDED, namestr, byte_to_string(newentry[0]),
                            self.sense2str(newentry[1]), byte_to_string(newentry[2])))
github rpm-software-management / rpmlint / rpmlint / pkg.py View on Github external
pkgfile = PkgFile(files[idx])
                pkgfile.path = os.path.normpath(os.path.join(
                    self.dirName() or '/', pkgfile.name.lstrip('/')))
                pkgfile.flags = flags[idx]
                pkgfile.mode = modes[idx]
                pkgfile.user = byte_to_string(users[idx])
                pkgfile.group = byte_to_string(groups[idx])
                pkgfile.linkto = links[idx] and os.path.normpath(links[idx])
                pkgfile.size = sizes[idx]
                pkgfile.md5 = md5s[idx]
                pkgfile.mtime = mtimes[idx]
                pkgfile.rdev = rdevs[idx]
                pkgfile.inode = inodes[idx]
                pkgfile.requires = parse_deps(requires[idx])
                pkgfile.provides = parse_deps(provides[idx])
                pkgfile.lang = byte_to_string(langs[idx])
                pkgfile.magic = magics[idx]
                if not pkgfile.magic:
                    if stat.S_ISDIR(pkgfile.mode):
                        pkgfile.magic = 'directory'
                    elif stat.S_ISLNK(pkgfile.mode):
                        pkgfile.magic = "symbolic link to `%s'" % pkgfile.linkto
                    elif not pkgfile.size:
                        pkgfile.magic = 'empty'
                if (not pkgfile.magic and
                        not pkgfile.is_ghost and _magic):
                    # file() method evaluates every file twice with python2,
                    # use descriptor() method instead
                    try:
                        fd = os.open(pkgfile.path, os.O_RDONLY)
                        pkgfile.magic = byte_to_string(_magic.descriptor(fd))
                        os.close(fd)