Robot Framework Integrated Development Environment (RIDE)
logger.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import re
17 import sys
18 
19 import wx
20 
21 from ..publish import RideParserLogMessage
22 from ..widgets import RIDEDialog
23 
24 
25 class Logger():
26  empty_suite_init_file_warn = re.compile("Test suite directory initialization "
27  "file '.*' contains no test data.")
28 
29  def __init__(self):
30  self._messages_messages = []
31 
33  errors = [m[0] for m in self._messages_messages]
34  if errors:
35  errors = set(errors)
36  msg = '\n'.join(self._format_parsing_error_line_format_parsing_error_line(line) for line in errors)
37  # print("DEBUG: logger: %s" % msg)
38  self._messages_messages = []
39  RideParserLogMessage(msg, level='PARSER').publish()
40  # Warnings from robot.variables.Variables.set_from_variable_tablems
41  # are present multiple times, issue 486.
42  """
43  errors = set(errors)
44  dlg = ParsingErrorDialog('\n'.join(self._format_parsing_error_line(line)
45  for line in errors))
46  dlg.ShowModal()
47  dlg.Destroy()
48  """
49  self._messages_messages = []
50 
51  def _format_parsing_error_line(self, line):
52  if ':' not in line:
53  return line
54  index = line.index(':') + 1
55  return line[:index] + '\n\t' + line[index:]
56 
57  def warn(self, msg=''):
58  self._write_write(msg, 'WARN')
59 
60  def error(self, msg=''):
61  self._write_write(msg, 'ERROR')
62 
63  def message(self, msg):
64  message, level = msg.message, msg.level.upper()
65  if self._is_logged_is_logged(level):
66  self._messages_messages.append((message, level))
67 
68  def _write(self, msg, level):
69  level = level.upper()
70  if self._is_logged_is_logged(level) and not self._is_ignored_warning_is_ignored_warning(msg):
71  self._show_message_show_message(msg, level)
72 
73  def _is_logged(self, level):
74  return level.upper() in ['ERROR', 'WARN']
75 
76  def _is_ignored_warning(self, msg):
77  return self.empty_suite_init_file_warnempty_suite_init_file_warn.search(msg)
78 
79  def _show_message(self, msg, level):
80  try:
81  icon = level == 'ERROR' and wx.ICON_ERROR or wx.ICON_WARNING
82  wx.MessageBox(msg, level, icon)
83  except wx.PyNoAppError:
84  sys.stderr.write('%s: %s\n' % (level, msg))
85 
86 
87 class ParsingErrorDialog(RIDEDialog):
88 
89  def __init__(self, message):
90  RIDEDialog.__init__(self, title='Parsing errors', size=(700, 400),
91  style=wx.DEFAULT_FRAME_STYLE)
92  # set Left to Right direction (while we don't have localization)
93  self.SetLayoutDirection(wx.Layout_LeftToRight)
94  area = wx.TextCtrl(self, size=(700,400), style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_READONLY|wx.TE_NOHIDESEL)
95  area.SetValue(message)
def _show_message(self, msg, level)
Definition: logger.py:79
def _format_parsing_error_line(self, line)
Definition: logger.py:51
def _is_logged(self, level)
Definition: logger.py:73
def report_parsing_errors(self)
Definition: logger.py:32
def warn(self, msg='')
Definition: logger.py:57
def _write(self, msg, level)
Definition: logger.py:68
def error(self, msg='')
Definition: logger.py:60
def message(self, msg)
Definition: logger.py:63
def _is_ignored_warning(self, msg)
Definition: logger.py:76
This class represents a general purpose log message.
Definition: messages.py:142