<commit_before>#!/usr/bin/env python3
import pyexifinfo
import magic
import os

from cortexutils.analyzer import Analyzer
from submodules import available_submodules
from submodules.submodule_metadata import MetadataSubmodule
from submodules.submodule_manalyze import ManalyzeSubmodule


class FileInfoAnalyzer(Analyzer):
    def __init__(self):
        Analyzer.__init__(self)
        self.filepath = self.get_param('file', None, 'File parameter is missing.')
        self.filename = self.get_param('filename', None, 'Filename is missing.')
        self.filetype = pyexifinfo.fileType(self.filepath)
        self.mimetype = magic.Magic(mime=True).from_file(self.filepath)

        # Check if manalyze submodule is enabled
        if self.get_param('config.manalyze_enable', False, 'Parameter manalyze_enable not given.'
                                                           'Please enable or disable manalyze submodule explicitly.'):
            if self.get_param('config.manalyze_enable_docker', False):
                available_submodules.append(
                    ManalyzeSubmodule(
                        use_docker=True
                    )
                )
            elif self.get_param('config.manalyze_enable_binary', False) \
                    and self.get_param('manalyze_binary_path', None) \
                    and os.path.isfile(self.get_param('manalyze_binary_path')):
                available_submodules.append(
                    ManalyzeSubmodule(
                        use_binary=True,
                        binary_path=self.get_param('manalyze_binary_path')
                    )
                )
            else:
                self.error('Manalyze submodule is enabled, but either there is no method allowed (docker or binary)'
                           'or the path to binary is not correct.')

    def summary(self, raw):
        taxonomies = []
        for submodule in raw['results']:
            taxonomies += submodule['summary']['taxonomies']
        return {'taxonomies': taxonomies}

    def run(self):
        results = []

        # Add metadata to result directly as it's mandatory
        m = MetadataSubmodule()
        metadata_results = m.analyze_file(self.filepath)
        results.append({
            'submodule_name': m.name,<commit_msg>WIP: Manalyze FileInfo submodule, changed binary path handling<commit_after>#!/usr/bin/env python3
import pyexifinfo
import magic
import os

from cortexutils.analyzer import Analyzer
from submodules import available_submodules
from submodules.submodule_metadata import MetadataSubmodule
from submodules.submodule_manalyze import ManalyzeSubmodule


class FileInfoAnalyzer(Analyzer):
    def __init__(self):
        Analyzer.__init__(self)
        self.filepath = self.get_param('file', None, 'File parameter is missing.')
        self.filename = self.get_param('filename', None, 'Filename is missing.')
        self.filetype = pyexifinfo.fileType(self.filepath)
        self.mimetype = magic.Magic(mime=True).from_file(self.filepath)

        # Check if manalyze submodule is enabled
        if self.get_param('config.manalyze_enable', False, 'Parameter manalyze_enable not given.'
                                                           'Please enable or disable manalyze submodule explicitly.'):
            binary_path = self.get_param('config.manalyze_binary_path',
                                         '/opt/Cortex-Analyzers/utils/manalyze/bin/manalyze')
            if self.get_param('config.manalyze_enable_docker', False):
                available_submodules.append(
                    ManalyzeSubmodule(
                        use_docker=True
                    )
                )
            elif self.get_param('config.manalyze_enable_binary', False) \
                    and os.path.isfile(binary_path):
                available_submodules.append(
                    ManalyzeSubmodule(
                        use_binary=True,
                        binary_path=binary_path
                    )
                )
            else:
                self.error('Manalyze submodule is enabled, but either there is no method allowed (docker or binary)'
                           'or the path to binary is not correct.')

    def summary(self, raw):
        taxonomies = []
        for submodule in raw['results']:
            taxonomies += submodule['summary']['taxonomies']
        return {'taxonomies': taxonomies}

    def run(self):
        results = []

        # Add metadata to result directly as it's mandatory
        m = MetadataSubmodule()
        metadata_results = m.analyze_file(self.filepath)
        results.append({
            'submodule_name': m.name,
{'fraction_non_alphanumeric': 0.08170212765957446, 'fraction_numerical': 0.000425531914893617, 'mean_word_length': 2.0173299101412066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1545220', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1197, 'n_words': 282}