Package pology :: Module msgreport

Module msgreport

Report info, warning and error messages.

Functions for Pology tools to report PO messages to the user at runtime, in different contexts and scenario. May colorize some output.


Authors:
Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>, Nick Shaforostoff (Николай Шафоростов) <shaforostoff@kde.ru>

License: GPLv3

Functions
 
report_on_msg(text, msg, cat, subsrc=None, file=sys.stdout)
Report on a PO message.
 
warning_on_msg(text, msg, cat, subsrc=None, file=sys.stdout)
Warning on a PO message.
 
error_on_msg(text, msg, cat, code=1, subsrc=None, file=sys.stdout)
Error on a PO message (aborts the execution).
 
report_on_msg_hl(highlight, msg, cat, fmsg=None, subsrc=None, file=sys.stdout)
Report on parts of a PO message.
 
report_msg_to_lokalize(msg, cat, report=None)
Open catalog in Lokalize and jump to message.
 
report_msg_content(msg, cat, wrapf=None, force=False, note=None, delim=None, highlight=None, showmsg=True, fmsg=None, showfmsg=False, subsrc=None, file=sys.stdout)
Report the content of a PO message.
 
rule_error(msg, cat, rule, highlight=None, fmsg=None, showmsg=True)
Print formated rule error message on screen.
 
multi_rule_error(msg, cat, rspec, showmsg=True)
Print formated rule error messages on screen.
 
rule_xml_error(msg, cat, rule, span, pluralId=0)
Create and returns rule error message in XML format
 
spell_error(msg, cat, faultyWord, suggestions)
Print formated rule error message on screen
 
spell_xml_error(msg, cat, faultyWord, suggestions, pluralId=0)
Create and returns spell error message in XML format
Variables
  __package__ = 'pology'
Function Details

report_on_msg(text, msg, cat, subsrc=None, file=sys.stdout)

 

Report on a PO message.

Outputs the message reference (catalog name and message position), along with the report text.

Parameters:
  • text (string) - text to report
  • msg (Message_base) - the message for which the text is reported
  • cat (Catalog) - the catalog where the message lives
  • subsrc (None or string) - more detailed source of the message
  • file (file) - send output to this file descriptor

warning_on_msg(text, msg, cat, subsrc=None, file=sys.stdout)

 

Warning on a PO message.

Outputs the message reference (catalog name and the message position), along with the warning text.

Parameters:
  • text (string) - text to report
  • msg (Message_base) - the message for which the text is reported
  • cat (Catalog) - the catalog where the message lives
  • subsrc (None or string) - more detailed source of the message
  • file (file) - send output to this file descriptor

error_on_msg(text, msg, cat, code=1, subsrc=None, file=sys.stdout)

 

Error on a PO message (aborts the execution).

Outputs the message reference (catalog name and message position), along with the error text. Aborts execution with the given code.

Parameters:
  • text (string) - text to report
  • msg (Message_base) - the message for which the text is reported
  • cat (Catalog) - the catalog where the message lives
  • code (int) - the exit code
  • subsrc (None or string) - more detailed source of the message
  • file (file) - send output to this file descriptor

report_on_msg_hl(highlight, msg, cat, fmsg=None, subsrc=None, file=sys.stdout)

 

Report on parts of a PO message.

For each of the spans found in the highlight specification which have a note attached, outputs the position reference (catalog name, message position, spanned segment) and the span note. The highlight can be relative to a somewhat modified, filtered message instead of the original one.

Parameters:
  • highlight (highlight) - highlight specification
  • msg (Message_base) - the message for which the text is reported
  • cat (Catalog) - the catalog where the message lives
  • fmsg (Message_base) - filtered message to which the highlight corresponds
  • subsrc (None or string) - more detailed source of the message
  • file (file) - send output to this file descriptor

report_msg_to_lokalize(msg, cat, report=None)

 

Open catalog in Lokalize and jump to message.

Lokalize is a CAT tool for KDE 4, http://userbase.kde.org/Lokalize. This function opens the catalog in Lokalize (if not already open) and jumps to the given message within it.

If the message is obsolete, it will be ignored.

Parameters:
  • msg (Message_base) - the message which should be jumped to in Lokalize
  • cat (Catalog) - the catalog in which the message resides
  • report (string or highlight) - simple text or highlight specification

report_msg_content(msg, cat, wrapf=None, force=False, note=None, delim=None, highlight=None, showmsg=True, fmsg=None, showfmsg=False, subsrc=None, file=sys.stdout)

 

Report the content of a PO message.

Provides the message reference, consisting of the catalog name and the message position within it, the message contents, and any notes on particular segments.

Parts of the message can be highlighted using colors. Parameter highlight provides the highlighting specification, as list of tuples where each tuple consists of: name of the message element to highlight, element index (used when the element is a list of values), list of spans, and optionally the filtered text of the element value. For example, to highlight spans (5, 10) and (15, 25) in the msgid, and (30, 40) in msgstr, the highlighting specification would be:

   [("msgid", 0, [(5, 10), (15, 25)]), ("msgstr", 0, [(30, 40)])]

Names of the elements that can presently be highlighted are: "msgctxt", "msgid", "msgid_plural", "msgstr", "manual_comment", "auto_comment", "source", "flag". For unique fields the element index is not used, but 0 should be given for consistency (may be enforced later). Span tuples can have a third element, following the indices, which is the note about why the particular span is highlighted; there may be more elements after the note, and these are all ignored. If start or end index of a span is not an integer, then the note is taken as relating to the complete field.

Sometimes the match to which the spans correspond has been made on a filtered value of the message field (e.g. after accelerator markers or tags have been removed). In that case, the filtered text can be given as the fourth element of the tuple, after the list of spans, and the function will try to fit spans from filtered onto original text. More globally, if the complete highlight is relative to a modified, filtered version of the message, this message can be given as fmsg parameter.

The display of content can be controlled by showmsg parameter; if it is False, only the message reference and span notes are shown. Similarly for the showfmsg parameter, which controls the display of the content of filtered message (if given by fmsg). To show the filtered message may be useful for debugging filtering in cases when it is not straightforward, or it is user-defined.

Parameters:
  • msg (Message_base) - the message to report the content for
  • cat (Catalog or None) - the catalog where the message lives
  • wrapf ((string)->[string...]) - the function used for wrapping message fields in output. See to_lines() method of message classes for details. If not given, it will be taken from the catalog (see Catalog.wrapf).
  • force (bool) - whether to force reformatting of cached message content
  • note (string) - note about why the content is being reported
  • delim (None or string) - text to print on the line following the message
  • highlight ((see description)) - highlighting specification of message elements
  • showmsg (bool) - show content of the message
  • fmsg (Message_base) - filtered message
  • showfmsg (bool) - show content of the filtered message, if any
  • subsrc (None or string) - more detailed source of the message
  • file (file) - output stream

rule_error(msg, cat, rule, highlight=None, fmsg=None, showmsg=True)

 

Print formated rule error message on screen.

Parameters:
  • msg - pology.message.Message object
  • cat - pology.catalog.Catalog object
  • rule - pology.rules.Rule object
  • highlight - highlight specification (see report_msg_content)
  • fmsg - filtered message which the rule really matched
  • showmsg - whether to show contents of message (either filtered or original)

multi_rule_error(msg, cat, rspec, showmsg=True)

 

Print formated rule error messages on screen.

Like rule_error, but reports multiple failed rules at once. Contents of the matched message is shown only once for all rules, with all highlights embedded, and all rule information following. This holds unless there are several different filtered messages, when rule failures are reported in groups by filtered message.

Parameters:
  • msg (Message) - the message matched by rules
  • cat (Catalog) - the catalog in which the message resides
  • rspec ([(Rule|(Rule, highlight)|(Rule, highlight, Message))*]) - specification of failed rules. This is a list in which each element can be one of:
    • rule
    • tuple of rule and highlight specification (see report_msg_content for details on highlight specifications). Highlight can be None.
    • tuple of rule, highlight, and filtered message which the rule really matched. Highlight and filtered message can be None.
  • showmsg (bool) - whether to show contents of message (both original and filtered if given)

rule_xml_error(msg, cat, rule, span, pluralId=0)

 

Create and returns rule error message in XML format

Parameters:
  • msg - pology.message.Message object
  • cat - pology.catalog.Catalog object
  • span - list of 2-tuple (start, end) of offending spans
  • rule - pology.rules.Rule object
  • pluralId - msgstr count in case of plural form. Default to 0
Returns:
XML message as a list of unicode string

spell_error(msg, cat, faultyWord, suggestions)

 

Print formated rule error message on screen

Parameters:
  • msg - pology.message.Message object
  • cat - pology.catalog.Catalog object
  • faultyWord - badly spelled word
  • suggestions - list of correct words to suggest

spell_xml_error(msg, cat, faultyWord, suggestions, pluralId=0)

 

Create and returns spell error message in XML format

Parameters:
  • msg - pology.message.Message object
  • cat - pology.catalog.Catalog object
  • faultyWord - badly spelled word
  • suggestions - list of correct words to suggest
  • pluralId - msgstr count in case of plural form. Default to 0
Returns:
XML message as a list of unicode string