def UserString(label, default=None): # this name left with C naming style for compatibility with translation assistance procedures #pylint: disable=invalid-name """ A translation assistance tool is intended to search for this method to identify translatable strings.""" table_string = fo.userString(label) if "ERROR: " + label in table_string: # implement test for string lookup not found error return default or table_string else: return table_string
def UserString(label, default=None): # this name left with C naming style for compatibility with translation assistance procedures #pylint: disable=invalid-name ''' A translation assistance tool is intended to search for this method to identify translatable strings. :param label: a UserString key :param default: a default value to return if there is a key error :return: a translated string for the label ''' table_string = fo.userString(label) if "ERROR: " + label in table_string: # implement test for string lookup not found error return default or table_string else: return table_string
def UserString(label, default=None): # pylint: disable=invalid-name """ A translation assistance tool is intended to search for this method to identify translatable strings. :param label: a UserString key :param default: a default value to return if there is a key error :return: a translated string for the label """ table_string = fo.userString(label) if "ERROR: " + label in table_string: # implement test for string lookup not found error return default or table_string else: return table_string
def print_error(exception, location=None, trace=True): """ Sends error to host chat and print its to log. :param exception: message text or exception :type exception: Exception :param location: text that describes error location :param trace: flag if print traceback """ print "possible recipients host status: %s" % [(x, fo.playerIsHost(x)) for x in fo.allPlayerIDs()] if location: message = '%s in "%s": "%s"' % (UserString('AI_ERROR_MSG', 'AI_Error: AI script error'), location, exception) else: message = '%s: "%s"' % (fo.userString('AI_ERROR_MSG'), exception) chat_human(RED % message) if trace: sys.stderr.write(format_exc())
def print_error(msg, location=None, trace=True): """ Sends error to host chat and print its to log. :param msg: message text :param location: text that describes error location :param trace: flag if print traceback """ recipient_id = [x for x in fo.allPlayerIDs() if fo.playerIsHost(x)][0] if location: message = '%s in "%s": "%s"' % (UserString('AI_ERROR_MSG', 'AI_Error: AI script error'), location, msg) else: message = '%s: "%s"' % (fo.userString('AI_ERROR_MSG'), msg) fo.sendChatMessage(recipient_id, message) print "\n%s\n" % message if trace: print format_exc()
for human_id in human_ids: fo.sendChatMessage(human_id, msg) except (KeyboardInterrupt, SystemExit): raise # Hide errors from within the ConsoleLogHandler except: self.handleError(record) # Create the log handler, format it and attach it to the root logger console_handler = ConsoleLogHandler() console_handler.setFormatter( logging.Formatter(RED % ('%s : %%(filename)s:%%(funcName)s():%%(lineno)d - %%(message)s' % fo.userString('AI_ERROR_MSG')))) console_handler.setLevel(logging.ERROR) logging.getLogger().addHandler(console_handler) def remove_tags(message): """Remove tags described in Font.h from message.""" expr = '</?(i|u|(rgba ([0-1]\.)?\d+ ([0-1]\.)?\d+ ([0-1]\.)?\d+ ([0-1]\.)?\d+)|rgba|left|center|right|pre)>' return re.sub(expr, '', message) def chat_human(message): """ Send chat message to human and print it to log.
fo.sendChatMessage(human_id, msg) except (KeyboardInterrupt, SystemExit): raise # Hide errors from within the ConsoleLogHandler except: self.handleError(record) # Create the log handler, format it and attach it to the root logger console_handler = ConsoleLogHandler() console_handler.setFormatter( logging.Formatter( RED % ('%s : %%(filename)s:%%(funcName)s():%%(lineno)d - %%(message)s' % fo.userString('AI_ERROR_MSG')))) console_handler.setLevel(logging.ERROR) logging.getLogger().addHandler(console_handler) def remove_tags(message): """Remove tags described in Font.h from message.""" expr = r'</?(i|u|(rgba ([0-1]\.)?\d+ ([0-1]\.)?\d+ ([0-1]\.)?\d+ ([0-1]\.)?\d+)|rgba|left|center|right|pre)>' return re.sub(expr, '', message) def chat_human(message): """ Send chat message to human and print it to log.
fo.sendChatMessage(human_id, msg) except (KeyboardInterrupt, SystemExit): raise # Hide errors from within the ConsoleLogHandler except: # noqa: E722 self.handleError(record) # Create the log handler, format it and attach it to the root logger console_handler = ConsoleLogHandler() console_handler.setFormatter( FOLogFormatter( RED % ("%s : %%(filename)s:%%(funcName)s():%%(lineno)d - %%(message)s" % fo.userString("AI_ERROR_MSG")))) console_handler.setLevel(ERROR) getLogger().addHandler(console_handler) def remove_tags(message): """Remove tags described in Font.h from message.""" expr = r"</?(i|u|(rgba ([0-1]\.)?\d+ ([0-1]\.)?\d+ ([0-1]\.)?\d+ ([0-1]\.)?\d+)|rgba|left|center|right|pre)>" return re.sub(expr, "", message) def chat_human(message, send_to_logs=True): """ Send chat message to human and print it to log.