summaryrefslogtreecommitdiff
path: root/src/buildstream/_message.py
blob: 675cc7b85ff87890cbddbda08c492fb6da1c3208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#
#  Copyright (C) 2017 Codethink Limited
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This library 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 the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
#  Authors:
#        Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>

import datetime
import os


# Types of status messages.
#
class MessageType:
    DEBUG = "debug"  # Debugging message
    STATUS = "status"  # Status message, verbose details
    INFO = "info"  # Informative messages
    WARN = "warning"  # Warning messages
    ERROR = "error"  # Error messages
    BUG = "bug"  # An unhandled exception was raised in a plugin
    LOG = "log"  # Messages for log files _only_, never in the frontend

    # Timed Messages: SUCCESS and FAIL have duration timestamps
    START = "start"  # Status start message
    SUCCESS = "success"  # Successful status complete message
    FAIL = "failure"  # Failing status complete message
    SKIPPED = "skipped"


# Messages which should be reported regardless of whether
# they are currently silenced or not
unconditional_messages = [MessageType.INFO, MessageType.WARN, MessageType.FAIL, MessageType.ERROR, MessageType.BUG]


# Message object
#
class Message:
    def __init__(
        self,
        message_type,
        message,
        *,
        task_element_name=None,
        task_element_key=None,
        element_name=None,
        element_key=None,
        detail=None,
        action_name=None,
        elapsed=None,
        logfile=None,
        sandbox=False,
        scheduler=False
    ):
        self.message_type = message_type  # Message type
        self.message = message  # The message string
        self.task_element_name = task_element_name  # The name of the issuing task element
        self.task_element_key = task_element_key  # The DisplayKey of the issuing task element
        self.element_name = element_name  # The name of the issuing element
        self.element_key = element_key  # The DisplayKey of the issuing element
        self.detail = detail  # An additional detail string
        self.action_name = action_name  # Name of the task queue (fetch, refresh, build, etc)
        self.elapsed = elapsed  # The elapsed time, in timed messages
        self.logfile = logfile  # The log file path where commands took place
        self.sandbox = sandbox  # Whether the error that caused this message used a sandbox
        self.pid = os.getpid()  # The process pid
        self.scheduler = scheduler  # Whether this is a scheduler level message
        self.creation_time = datetime.datetime.now()
        if message_type in (MessageType.SUCCESS, MessageType.FAIL):
            assert elapsed is not None