<commit_before># This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright (c) 2020 ScyllaDB

import time
from typing import Any, Optional, Sequence
from traceback import format_stack

from sdcm.sct_events import Severity
from sdcm.sct_events.base import SctEvent, SystemEvent, InformationalEvent


class StartupTestEvent(SystemEvent):
    def __init__(self):
        super().__init__(severity=Severity.NORMAL)


class TestTimeoutEvent(SctEvent):
    def __init__(self, start_time: float, duration: int):
        super().__init__(severity=Severity.CRITICAL)
        self.start_time = start_time
        self.duration = duration

    @property
    def msgfmt(self) -> str:
        start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.start_time))
        return f"{super().msgfmt}, Test started at {start_time}, reached it's timeout ({self.duration} minute)"


class TestFrameworkEvent(InformationalEvent):  # pylint: disable=too-many-instance-attributes
    __test__ = False  # Mark this class to be not collected by pytest.

    def __init__(self,
                 source: Any,
                 source_method: Optional = None,
                 args: Optional[Sequence] = None,
                 kwargs: Optional[dict] = None,
                 message: Optional = None,
                 exception: Optional = None,
                 trace: Optional = None,
                 severity: Optional[Severity] = None):

        if severity is None:
            severity = Severity.ERROR
        super().__init__(severity=severity)

        self.source = str(source) if source else None
        self.source_method = str(source_method) if source_method else None
        self.exception = str(exception) if exception else None
        self.message = str(message) if message else None
        self.trace = "".join(format_stack(trace)) if trace else None
        self.args = args
        self.kwargs = kwargs

    @property
    def msgfmt(self) -> str:
        fmt = super().msgfmt + ", source={0.source}"

        if self.source_method:
            args = []
            if self.args:
                args.append("args={0.args}")
            if self.kwargs:
                args.append("kwargs={0.kwargs}")
            fmt += ".{0.source_method}(" + ", ".join(args) + ")"

        if self.message:
            fmt += " message={0.message}"
        if self.exception:
            fmt += "\nexception={0.exception}"
        if self.trace:
            fmt += "\nTraceback (most recent call last):\n{0.trace}"

        return fmt


class ElasticsearchEvent(InformationalEvent):
    def __init__(self, doc_id: str, error: str):
        super().__init__(severity=Severity.ERROR)

        self.doc_id = doc_id
        self.error = error

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": doc_id={0.doc_id} error={0.error}"


class SpotTerminationEvent(InformationalEvent):
    def __init__(self, node: Any, message: str):
        super().__init__(severity=Severity.CRITICAL)

        self.node = str(node)
        self.message = message

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": node={0.node} message={0.message}"


class ScyllaRepoEvent(InformationalEvent):
    def __init__(self, url: str, error: str):
        super().__init__(severity=Severity.WARNING)

        self.url = url
        self.error = error

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": url={0.url} error={0.error}"


class InfoEvent(SctEvent):
    def __init__(self, message: str):
        super().__init__(severity=Severity.NORMAL)

        self.message = message

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": message={0.message}"


class ThreadFailedEvent(InformationalEvent):
    def __init__(self, message: str, traceback: Any):
        super().__init__(severity=Severity.ERROR)

        self.message = message
        self.traceback = str(traceback)

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": message={0.message}\n{0.traceback}"


class CoreDumpEvent(InformationalEvent):
    def __init__(self,
                 node: Any,
                 corefile_url: str,
                 backtrace: str,
                 download_instructions: str,
                 timestamp: Optional[float] = None):

        super().__init__(severity=Severity.ERROR)

        self.node = str(node)
        self.corefile_url = corefile_url
        self.backtrace = backtrace
        self.download_instructions = download_instructions

        if timestamp is not None:
            self.timestamp = timestamp
<commit_msg>fix(sdcm.sct_events.system): fix pylint issues<commit_after># This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright (c) 2020 ScyllaDB

import time
from typing import Any, Optional, Sequence
from traceback import format_stack

from sdcm.sct_events import Severity
from sdcm.sct_events.base import SctEvent, SystemEvent, InformationalEvent


class StartupTestEvent(SystemEvent):
    def __init__(self):
        super().__init__(severity=Severity.NORMAL)


class TestTimeoutEvent(SctEvent):
    def __init__(self, start_time: float, duration: int):
        super().__init__(severity=Severity.CRITICAL)
        self.start_time = start_time
        self.duration = duration

    @property
    def msgfmt(self) -> str:
        start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.start_time))
        return f"{super().msgfmt}, Test started at {start_time}, reached it's timeout ({self.duration} minute)"


class TestFrameworkEvent(InformationalEvent):  # pylint: disable=too-many-instance-attributes
    __test__ = False  # Mark this class to be not collected by pytest.

    # pylint: disable=too-many-arguments
    def __init__(self,
                 source: Any,
                 source_method: Optional = None,
                 args: Optional[Sequence] = None,
                 kwargs: Optional[dict] = None,
                 message: Optional = None,
                 exception: Optional = None,
                 trace: Optional = None,
                 severity: Optional[Severity] = None):

        if severity is None:
            severity = Severity.ERROR
        super().__init__(severity=severity)

        self.source = str(source) if source else None
        self.source_method = str(source_method) if source_method else None
        self.exception = str(exception) if exception else None
        self.message = str(message) if message else None
        self.trace = "".join(format_stack(trace)) if trace else None
        self.args = args
        self.kwargs = kwargs

    @property
    def msgfmt(self) -> str:
        fmt = super().msgfmt + ", source={0.source}"

        if self.source_method:
            args = []
            if self.args:
                args.append("args={0.args}")
            if self.kwargs:
                args.append("kwargs={0.kwargs}")
            fmt += ".{0.source_method}(" + ", ".join(args) + ")"

        if self.message:
            fmt += " message={0.message}"
        if self.exception:
            fmt += "\nexception={0.exception}"
        if self.trace:
            fmt += "\nTraceback (most recent call last):\n{0.trace}"

        return fmt


class ElasticsearchEvent(InformationalEvent):
    def __init__(self, doc_id: str, error: str):
        super().__init__(severity=Severity.ERROR)

        self.doc_id = doc_id
        self.error = error

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": doc_id={0.doc_id} error={0.error}"


class SpotTerminationEvent(InformationalEvent):
    def __init__(self, node: Any, message: str):
        super().__init__(severity=Severity.CRITICAL)

        self.node = str(node)
        self.message = message

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": node={0.node} message={0.message}"


class ScyllaRepoEvent(InformationalEvent):
    def __init__(self, url: str, error: str):
        super().__init__(severity=Severity.WARNING)

        self.url = url
        self.error = error

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": url={0.url} error={0.error}"


class InfoEvent(SctEvent):
    def __init__(self, message: str):
        super().__init__(severity=Severity.NORMAL)

        self.message = message

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": message={0.message}"


class ThreadFailedEvent(InformationalEvent):
    def __init__(self, message: str, traceback: Any):
        super().__init__(severity=Severity.ERROR)

        self.message = message
        self.traceback = str(traceback)

    @property
    def msgfmt(self) -> str:
        return super().msgfmt + ": message={0.message}\n{0.traceback}"


class CoreDumpEvent(InformationalEvent):
    # pylint: disable=too-many-arguments
    def __init__(self,
                 node: Any,
                 corefile_url: str,
                 backtrace: str,
                 download_instructions: str,
                 timestamp: Optional[float] = None):

        super().__init__(severity=Severity.ERROR)

        self.node = str(node)
        self.corefile_url = corefile_url
        self.backtrace = backtrace
        self.download_instructions = download_instructions

        if timestamp is not None:
            self.timestamp = timestamp

{'fraction_non_alphanumeric': 0.1070067428906479, 'fraction_numerical': 0.004104368220463207, 'mean_word_length': 2.531400966183575, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5868617', 'n_tokens_mistral': 2973, 'n_tokens_neox': 2881, 'n_words': 783}