<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import, unicode_literals

import subprocess

from .common import CommonEnvironment
from ..package_info import PackageInfo, FileInfo


class RpmEnvironment(CommonEnvironment):
    """
    Environment class for distributions using RPM as package manager (e.g.
    Fedora, Red Hat or OpenSUSE).

    The packages are retrieved from the database directly using the ``rpm``
    command.

    """
    executable = 'rpm'

    @classmethod
    def get_package_list(cls):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """
        """
        command_args = [cls.executable, '-qa', '--queryformat', '%{name}\n%{version}-%{release}\t -c']
        data = subprocess.check_output(command_args)
        if isinstance(data, bytes):  # convert to unicode
            data = data.decode('utf-8')


        line_list = data.split('\n')
        result = []
        """
        result = []

        with open('rpm-output3.txt', 'r') as content_file:
            content = content_file.read()

        line_list = content.split('\t')

        for line in line_list:
            split_line = line.replace('\n', " ").split()

            if len(split_line) >= 4:
                package_info = PackageInfo()
                package_info.package = split_line[0]
                package_info.version = split_line[1]

                # if Config-Files exists
                if len(split_line) >= 3:
                    config_files = []
                    for file_path in split_line[2:len(split_line)]:
                        file_info = FileInfo(file_path)
                        file_info.mutable = True
                        config_files.append(file_info)

                package_info.files.extend(config_files)

                result.append(package_info)

        return result

    @classmethod
    def get_files_for_package(cls, package_name):
        command_args = [cls.executable, '-ql', package_name]
        data = subprocess.check_output(command_args)
        if isinstance(data, bytes):  # convert to unicode
            data = data.decode('utf-8')
        lines = data.rstrip().split('\n')
        files = filter(cls._is_file, lines)<commit_msg>Rpm-Environment File_listing and Configuartion-Files recognition finished; Tests with RPM --queryformat<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import, unicode_literals

import subprocess

from .common import CommonEnvironment
from ..package_info import PackageInfo, FileInfo


class RpmEnvironment(CommonEnvironment):
    """
    Environment class for distributions using RPM as package manager (e.g.
    Fedora, Red Hat or OpenSUSE).

    The packages are retrieved from the database directly using the ``rpm``
    command.

    """
    executable = 'rpm'

    @classmethod
    def get_package_list(cls):
        """
        Get list of installed packages.

        Returns:
            List of ``PackageInfo`` instances.

        """

        command_args = [cls.executable, '-qa', '--queryformat', '\t%{name} %{version}-%{release}', '-c']
        data = subprocess.check_output(command_args)
        if isinstance(data, bytes):  # convert to unicode
            data = data.decode('utf-8')

        line_list = data.split('\t')
        result = []

        for line in line_list:
            split_line = line.replace('\n', " ").split()
            if len(split_line) >= 2:
                package_info = PackageInfo()
                package_info.package = split_line[0]
                package_info.version = split_line[1]

                # if Config-Files exists
                if len(split_line) >= 3:
                    config_files = []
                    for file_path in split_line[2:len(split_line)]:
                        file_info = FileInfo(file_path)
                        file_info.mutable = True
                        config_files.append(file_info)

                    package_info.files.extend(config_files)

                result.append(package_info)

        return result

    @classmethod
    def get_files_for_package(cls, package_name):
        command_args = [cls.executable, '-ql', package_name]
        data = subprocess.check_output(command_args)
        if isinstance(data, bytes):  # convert to unicode
            data = data.decode('utf-8')
        lines = data.rstrip().split('\n')
        files = filter(cls._is_file, lines)
{'fraction_non_alphanumeric': 0.10492740871095468, 'fraction_numerical': 0.003739551253849538, 'mean_word_length': 2.059892328398385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4432995', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1213, 'n_words': 305}