Beispiel #1
0
    def finalize (self):

        if self.byrule:
            ruleIdents = sorted(self.postFailedMessages.keys())
            for ruleIdent in ruleIdents:
                for msg, cat, failedRule in self.postFailedMessages[ruleIdent]:
                    multi_rule_error(msg, cat, [failedRule], self.showmsg,
                                     predelim=self._first_error)
                    self._first_error = False

        if self.xmlFile:
            # Close last po tag and xml file
            if self.cached and self.cacheFile:
                self.cacheFile.write("</po>\n")
                self.cacheFile.close()
                self.cacheFile = None
            else:
                self.xmlFile.write("</po>\n")
            self.xmlFile.write("</pos>\n")
            self.xmlFile.close()
        if self.nmatch > 0:
            msg = n_("@info:progress",
                     "Rules detected %(num)d problem.",
                     "Rules detected %(num)d problems.",
                     num=self.nmatch)
            report("===== " + msg)
        printStat(self.rules)
Beispiel #2
0
    def process_header(self, hdr, cat):

        mcount = hdr.modcount

        for tfilter, tfname in self.tfilters:
            try:
                res = tfilter(hdr, cat)
            except TypeError:
                raise SieveError(
                    _("@info",
                      "Cannot execute filter '%(filt)s'.",
                      filt=tfname))

            # Process result based on hook type.
            if isinstance(res, list):
                # Validation hook.
                # TODO: Better span reporting on headers.
                for part in res:
                    for span in part[2]:
                        if len(span) >= 3:
                            errmsg = span[2]
                            report("%s:header: %s", (cat.filename, errmsg))
            else:
                # Side-effect hook, nothing to do.
                # TODO: Perhaps report returned number?
                pass

        if mcount < hdr.modcount:
            self.nmod += 1
Beispiel #3
0
def exit_on_exception(func, cleanup=None):
    """
    Gracefully exit a Pology script when an exception is received.

    Any error message will be printed, any progress lines will be cleared,
    and keyboard interrupt will exist silently.

    The backtrace can be shown instead (on non-keyboard interrupt exceptions)
    by setting C{[global]/show-backtrace} user configuration field to true.

    @param func: a zero-argument function
    @type func: () -> any
    @param cleanup: a zero-argument function to execute before exiting
    @type cleanup: () -> any

    @returns: path of current working directory
    @rtype: string
    """

    try:
        func()
    except KeyboardInterrupt:
        report("", newline=False)
        if cleanup:
            cleanup()
        exit(100)
    except Exception, e:
        report("", newline=False)
        if cleanup:
            cleanup()
        if pology.config.section("global").boolean("show-backtrace"):
            raise
        else:
            error(str_to_unicode(str(e)), code=1)
Beispiel #4
0
 def finalize (self):
     if self.nmatch:
         msg = n_("@info:progress",
                  "Detected %(num)d problem in grammar and style.",
                  "Detected %(num)d problems in grammar and style.",
                  num=self.nmatch)
         report("===== " + msg)
Beispiel #5
0
def spell_error(msg, cat, faultyWord, suggestions):
    """Print formated rule error message on screen
    @param msg: pology.message.Message object
    @param cat: pology.catalog.Catalog object
    @param faultyWord: badly spelled word
    @param suggestions : list of correct words to suggest"""
    report("-" * 40)
    report(
        ColorString("<bold>%s:%d(%d)</bold>") %
        (cat.filename, msg.refline, msg.refentry))
    if msg.msgctxt:
        report(
            _("@info",
              "<bold>Context:</bold> %(snippet)s",
              snippet=msg.msgctxt))
    #TODO: color in red part of context that make the mistake
    report(
        _("@info",
          "<bold>Faulty word:</bold> <red>%(word)s</red>",
          word=faultyWord))
    if suggestions:
        report(
            _("@info",
              "<bold>Suggestions:</bold> %(wordlist)s",
              wordlist=format_item_list(suggestions)))
Beispiel #6
0
    def finalize (self):

        if self.nmatch:
            msg = n_("@info:progress",
                     "Found %(num)d message satisfying the conditions.",
                     "Found %(num)d messages satisfying the conditions.",
                     num=self.nmatch)
            report("===== " + msg)
Beispiel #7
0
    def finalize(self):

        if self.nmatch > 0:
            msg = n_("@info:progress",
                     "Removed %(num)d obsolete message.",
                     "Removed %(num)d obsolete messages.",
                     num=self.nmatch)
            report("===== " + msg)
Beispiel #8
0
    def finalize(self):

        if self.ncorr > 0:
            msg = n_("@info:progress",
                     "Merged %(num)d corrected message.",
                     "Merged %(num)d corrected messages.",
                     num=self.ncorr)
            report("===== " + msg)
Beispiel #9
0
    def finalize(self):

        if self.nresolved > 0:
            msg = n_("@info:progress",
                     "Resolved %(num)d alternative in translation.",
                     "Resolved %(num)d alternatives in translation.",
                     num=self.nresolved)
            report("===== " + msg)
Beispiel #10
0
    def finalize(self):

        if self.nemptied > 0:
            msg = n_("@info:progress",
                     "Cleared %(num)d fuzzy message of translation.",
                     "Cleared %(num)d fuzzy messages of translation.",
                     num=self.nemptied)
            report("===== " + msg)
Beispiel #11
0
    def finalize(self):

        if self.nconv > 0:
            msg = n_("@info:progress",
                     "Converted %(num)d separator-embedded context.",
                     "Converted %(num)d separator-embedded contexts.",
                     num=self.nconv)
            report("===== " + msg)
Beispiel #12
0
    def finalize (self):

        if self.nproblems > 0:
            msg = n_("@info:progress",
                     "Found %(num)d problem in Docbook translations.",
                     "Found %(num)d problems in Docbook translations.",
                     num=self.nproblems)
            report("===== " + msg)
Beispiel #13
0
    def finalize(self):

        if self.nbad > 0:
            msg = n_("@info:progress",
                     "Detected %(num)d bad pattern in translation.",
                     "Detected %(num)d bad patterns in translation.",
                     num=self.nbad)
            report("===== " + msg)
Beispiel #14
0
    def finalize (self):

        if self.ncleared > 0:
            msg = n_("@info:progress",
                     "Cleared previous fields from %(num)d message.",
                     "Cleared previous fields from %(num)d messages.",
                     num=self.ncleared)
            report("===== " + msg)
Beispiel #15
0
    def finalize(self):

        if self.nmatch > 0:
            report(
                n_("@info",
                   "Non-breaking spaces added in %(num)d message.",
                   "Non-breaking spaces added in %(num)d messages.",
                   num=self.nmatch))
Beispiel #16
0
    def finalize(self):

        if self.nmod > 0:
            msg = n_("@info:progress",
                     "Removed some comments from %(num)d fuzzy message.",
                     "Removed some comments from %(num)d fuzzy messages.",
                     num=self.nmod)
            report("===== " + msg)
Beispiel #17
0
    def finalize(self):

        if self.nmod:
            msg = n_("@info:progress",
                     "Modified %(num)d message by filtering.",
                     "Modified %(num)d messages by filtering.",
                     num=self.nmod)
            report("===== " + msg)
Beispiel #18
0
    def finalize (self):

        if self.nproblems > 0:
            msg = n_("@info:progress BfW stands for \"Battle for Wesnoth\"",
                     "Found %(num)d problem in BfW translations.",
                     "Found %(num)d problems in BfW translations.",
                     num=self.nproblems)
            report("===== " + msg)
Beispiel #19
0
    def finalize(self):

        if self.nmatch > 0:
            msg = n_("@info:progress",
                     "Unfuzzied %(num)d message fuzzy due to "
                     "difference in Qt class context only.",
                     "Unfuzzied %(num)d messages fuzzy due to "
                     "difference in Qt class context only.",
                     num=self.nmatch)
            report("===== " + msg)
Beispiel #20
0
def main ():

    locale.setlocale(locale.LC_ALL, "")

    # Get defaults for command line options from global config.
    cfgsec = pology_config.section("porewrap")

    # Setup options and parse the command line.
    usage = _("@info command usage",
        "%(cmd)s [options] POFILE...",
        cmd="%prog")
    desc = _("@info command description",
        "Rewrap message strings in PO files.")
    ver = _("@info command version",
        u"%(cmd)s (Pology) %(version)s\n"
        u"Copyright © 2007, 2008, 2009, 2010 "
        u"Chusslove Illich (Часлав Илић) &lt;%(email)s&gt;",
        cmd="%prog", version=version(), email="*****@*****.**")

    opars = ColorOptionParser(usage=usage, description=desc, version=ver)
    opars.add_option(
        "-v", "--verbose",
        action="store_true", dest="verbose", default=False,
        help=_("@info command line option description",
               "More detailed progress information."))
    add_cmdopt_wrapping(opars)
    add_cmdopt_filesfrom(opars)

    (op, fargs) = opars.parse_args()

    if len(fargs) < 1 and not op.files_from:
        error(_("@info", "No input files given."))

    # Could use some speedup.
    try:
        import psyco
        psyco.full()
    except ImportError:
        pass

    # Assemble list of files.
    fnames = collect_paths_cmdline(rawpaths=fargs,
                                   filesfrom=op.files_from,
                                   respathf=collect_catalogs,
                                   abort=True)

    # Rewrap all catalogs.
    for fname in fnames:
        if op.verbose:
            report(_("@info:progress", "Rewrapping: %(file)s", file=fname))
        cat = Catalog(fname, monitored=False)
        wrapping = select_field_wrapping(cfgsec, cat, op)
        cat.set_wrapping(wrapping)
        cat.sync(force=True)
Beispiel #21
0
    def finalize(self):

        nrepl_both = self.nrepl_single + self.nrepl_double
        if nrepl_both > 0:
            msg = n_("@info:progress",
                     "Replaced %(num)d pair of quotes in translation "
                     "(single+double: %(nums)d+%(numd)d).",
                     "Replaced %(num)d pairs of quotes in translation "
                     "(single+double: %(nums)d+%(numd)d).",
                     num=nrepl_both,
                     nums=self.nrepl_single,
                     numd=self.nrepl_double)
            report("===== " + msg)
Beispiel #22
0
    def finalize(self):

        if self.nmod > 0:
            if not self.strip:
                msg = n_("@info:progress",
                         "Added differences to %(num)d fuzzy message.",
                         "Added differences to %(num)d fuzzy messages.",
                         num=self.nmod)
            else:
                msg = n_("@info:progress",
                         "Stripped differences from %(num)d fuzzy message.",
                         "Stripped differences from %(num)d fuzzy messages.",
                         num=self.nmod)
            report("===== " + msg)
Beispiel #23
0
    def finalize(self):

        if self.ntagged > 0:
            msg = n_("@info:progress",
                     "Tagged %(num)d untranslated message.",
                     "Tagged %(num)d untranslated messages.",
                     num=self.ntagged)
            report("===== " + msg)
        if self.ncleared > 0:
            msg = n_("@info:progress",
                     "Cleared untranslated tag from %(num)d message.",
                     "Cleared untranslated tag from %(num)d messages.",
                     num=self.ncleared)
            report("===== " + msg)
Beispiel #24
0
    def finalize(self):

        if self.unknown_words:
            if not self.words_only:
                nwords = len(self.unknown_words)
                msg = n_("@info:progress",
                         "Encountered %(num)d unknown word.",
                         "Encountered %(num)d unknown words.",
                         num=nwords)
                report("===== " + msg)
            else:
                wlist = list(self.unknown_words)
                wlist.sort(lambda x, y: locale.strcoll(x.lower(), y.lower()))
                report("\n".join(wlist))
Beispiel #25
0
    def finalize(self):

        if self.nresolvedhdr > 0:
            msg = n_("@info:progress",
                     "Resolved %(num)d aggregate header.",
                     "Resolved %(num)d aggregate headers.",
                     num=self.nresolvedhdr)
            report("===== " + msg)
        if self.nresolved > 0:
            msg = n_("@info:progress",
                     "Resolved %(num)d aggregate message.",
                     "Resolved %(num)d aggregate messages.",
                     num=self.nresolved)
            report("===== " + msg)
Beispiel #26
0
    def finalize (self):

        if self.nproblems > 0:
            if not self.strict:
                msg = n_("@info:progress TP stands for Translation Project",
                         "Found %(num)d problem in KDE TP translations.",
                         "Found %(num)d problems in KDE TP translations.",
                         num=self.nproblems)
            else:
                msg = n_("@info:progress",
                         "Found %(num)d problem in "
                         "KDE TP translations (strict mode).",
                         "Found %(num)d problems in "
                         "KDE TP translations (strict mode).",
                         num=self.nproblems)
            report("===== " + msg)
Beispiel #27
0
    def finalize(self):

        if self.nproblems > 0:
            if not self.strict:
                msg = n_("@info:progress",
                         "Found %(num)d problem in KDE4 translations.",
                         "Found %(num)d problems in KDE4 translations.",
                         num=self.nproblems)
            else:
                msg = n_("@info:progress",
                         "Found %(num)d problem in KDE4 translations "
                         "(strict mode).",
                         "Found %(num)d problems in KDE4 translations "
                         "(strict mode).",
                         num=self.nproblems)
            report("===== " + msg)
Beispiel #28
0
def assert_system(cmdline, echo=False, wdir=None):
    """
    Execute command line and assert success.

    If the command exits with non-zero zero state, the program aborts.

    C{cmdline} can be either a monolithic string, in which case it is
    executed through a shell, or a list of argument strings,
    when the process is started directly with these arguments.

    C{cmdline} is processed with L{unicode_to_str} to convert any
    unicode strings to raw byte strings in expected system encoding.

    @param cmdline: command line to execute
    @type cmdline: string
    @param echo: whether to echo the supplied command line
    @type echo: bool
    @param wdir: working directory for the command (CWD if none given)
    @type wdir: path
    """

    if echo:
        if isinstance(cmdline, basestring):
            cmdstr = cmdline
        else:
            cmdstr = " ".join(map(escape_sh, cmdline))
        report(cmdstr)
    if wdir is not None:
        cwd = getucwd()
        os.chdir(wdir)
    if isinstance(cmdline, basestring):
        cmdline = unicode_to_str(cmdline)
        shell = True
    else:
        cmdline = map(unicode_to_str, cmdline)
        shell = False
    ret = subprocess.call(cmdline, shell=shell)
    if wdir is not None:
        os.chdir(cwd)
    if ret:
        if echo:
            error(_("@info", "Non-zero exit from the previous command."))
        else:
            error(
                _("@info",
                  "Non-zero exit from the command:\n%(cmdline)s",
                  cmdline=cmdline))
Beispiel #29
0
    def finalize (self):

        if self.nunfuzz > 0:
            msg = n_("@info:progress",
                     "Unfuzzied %(num)d message fuzzy due to "
                     "difference in context only.",
                     "Unfuzzied %(num)d messages fuzzy due to "
                     "difference in context only.",
                     num=self.nunfuzz)
            report("===== " + msg)
        if self.nrep > 0:
            msg = n_("@info:progress",
                     "Reported %(num)d message due to equality "
                     "of '%(field)s' field.",
                     "Reported %(num)d messages due to equality "
                     "of '%(field)s' field.",
                     num=self.nrep, field="msgid")
            report("===== " + msg)
Beispiel #30
0
    def finalize (self):

        if self.nunfuzz > 0:
            msg = n_("@info:progress",
                     "Unfuzzied %(num)d message due to "
                     "closing tags in-place.",
                     "Unfuzzied %(num)d messages due to "
                     "closing tags in-place.",
                     num=self.nunfuzz)
            report("===== " + msg)
        if self.nmodinpl > 0:
            msg = n_("@info:progress",
                     "Modified %(num)d translations by "
                     "closing tags in-place.",
                     "Modified %(num)d translations by "
                     "closing tags in-place.",
                     num=self.nmodinpl)
            report("===== " + msg)