Changeset 4403

Show
Ignore:
Timestamp:
10/06/08 12:37:01 (2 months ago)
Author:
cboos
Message:

GraphvizPlugin: improve rendering of graphviz command errors

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • graphvizplugin/0.11/graphviz/graphviz.py

    r4402 r4403  
    523523                arg = arg.encode(self.encoding, 'replace') 
    524524            encoded_cmd.append(arg) 
    525         p = subprocess.Popen(encoded_cmd, 
    526                              stdin=subprocess.PIPE, 
    527                              stdout=subprocess.PIPE, 
    528                              stderr=subprocess.PIPE) 
     525        p = subprocess.Popen(encoded_cmd, stdin=subprocess.PIPE, 
     526                             stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
    529527        if input: 
    530528            p.stdin.write(encoded_input) 
     
    532530        out = p.stdout.read() 
    533531        err = p.stderr.read() 
    534         if out or err: 
    535             return _("The command\n   %(cmd)s\n" 
    536                      "failed with the the following output:\n" 
    537                      "%(out)s\n%(err)s", cmd=unicode(args), out=out, err=err) 
     532        reason = None 
     533        if p.wait() != 0: 
     534            reason = _("failed with the following output:") 
     535        if err or out: 
     536            reason = _("succeeded but emitted the following output:") 
     537        if reason: 
     538            return tag.p(tag.br(), _("The command:"),  
     539                         tag.pre(repr(' '.join(encoded_cmd))), reason,  
     540                         out and tag.pre(repr(out)), err and tag.pre(repr(err))) 
    538541 
    539542    def _error_div(self, msg): 
    540543        """Display msg in an error box, using Trac style.""" 
    541         self.log.error(unicode(msg)) 
     544        if isinstance(msg, str): 
     545            msg = to_unicode(msg) 
     546        self.log.error(msg) 
     547        if isinstance(msg, unicode): 
     548            msg = tag.pre(escape(msg)) 
    542549        return tag.div( 
    543                 tag.strong("Graphviz macro processor has detected an error. " 
    544                             "Please fix the problem before continuing."), 
    545                 tag.pre(escape(to_unicode(msg))), 
    546                 class_="system-message") 
     550                tag.strong(_("Graphviz macro processor has detected an error. " 
     551                             "Please fix the problem before continuing.")), 
     552                msg, class_="system-message") 
    547553 
    548554    def _clean_cache(self):