示例#1
0
    def _format_html(self, event):
        ticket = event.target
        short_changes = {}
        long_changes = {}
        chrome = Chrome(self.env)
        for field, old_value in event.changes.items():
            new_value = ticket[field]
            if (new_value and '\n' in new_value) or \
                    (old_value and '\n' in old_value):
                long_changes[field.capitalize()] = HTML(
                    "<pre>\n%s\n</pre>" % ('\n'.join(
                        diff_cleanup(
                            difflib.unified_diff(
                                wrap(old_value, cols=60).split('\n'),
                                wrap(new_value, cols=60).split('\n'),
                                lineterm='',
                                n=3)))))

            else:
                short_changes[field.capitalize()] = (old_value, new_value)

        try:
            req = Mock(href=Href(self.env.abs_href()),
                       abs_href=self.env.abs_href(),
                       authname=event.author,
                       perm=MockPerm(),
                       chrome=dict(warnings=[], notices=[]),
                       args={})
            context = Context.from_request(req, event.realm, event.target.id)
            formatter = HtmlFormatter(self.env, context, event.comment)
            temp = formatter.generate(True)
        except Exception, e:
            self.log.error(exception_to_unicode(e, traceback=True))
            temp = 'Comment in plain text: %s' % event.comment
示例#2
0
文件: TracParser.py 项目: azrdev/thot
 def _parse_text(self):
     env, context = self.create_trac_ctx(
         self.settings['website_url'],
         self.headers['author']['name'] if ('author' in self.headers and 'name' in self.headers['author']) else self.settings['author']['name'],
         str(self.headers['timezone']) if 'timezone' in self.headers else str(self.settings['timezone']),
         self.filename if self.filename.startswith('/') else '/'+self.filename)
     formatter = HtmlFormatter(env, context, self.text)
     self.text = formatter.generate()
示例#3
0
 def _parse_text(self):
     env, context = self.create_trac_ctx(
         self.settings['website_url'],
         self.headers['author']['name'] \
             if ('author' in self.headers \
                 and 'name' in self.headers['author']) \
             else self.settings['author']['name'],
         str(self.headers['timezone']) \
             if 'timezone' in self.headers \
             else str(self.settings['timezone']),
         self.filename \
             if self.filename.startswith('/') \
             else '/'+self.filename)
     formatter = HtmlFormatter(env, context, self.text)
     self.text = formatter.generate()
示例#4
0
    def _format_html(self, event):
        ticket = event.target
        short_changes = {}
        long_changes = {}
        chrome = Chrome(self.env)        
        for field, old_value in event.changes.items():
            new_value = ticket[field]
            if (new_value and '\n' in new_value) or \
                    (old_value and '\n' in old_value):
                long_changes[field.capitalize()] = HTML(
                    "<pre>\n%s\n</pre>" % (
                        '\n'.join(
                            diff_cleanup(
                                difflib.unified_diff(
                                    wrap(old_value, cols=60).split('\n'), 
                                    wrap(new_value, cols=60).split('\n'),
                                    lineterm='', n=3
                                )
                            )
                        )
                    )
                )

            else:
                short_changes[field.capitalize()] = (old_value, new_value)

        if event.comment:
            try:
                req = Mock(
                    href=Href(self.env.abs_href()),
                    abs_href=self.env.abs_href(),
                    authname=event.author, 
                    perm=MockPerm(),
                    chrome=dict(
                        warnings=[],
                        notices=[]
                    ),
                    args={}
                )
                context = Context.from_request(req, event.realm, event.target.id)
                formatter = HtmlFormatter(self.env, context, event.comment)
                temp = formatter.generate(True)
            except Exception, e:
                self.log.error(exception_to_unicode(e, traceback=True))
                temp = 'Comment in plain text: %s'%event.comment
示例#5
0
 def wiki_to_html(event, wikitext):
     if wikitext is None:
         return ""
     try:
         req = Mock(href=Href(self.env.abs_href()),
                    abs_href=self.env.abs_href,
                    authname=event.author,
                    perm=MockPerm(),
                    chrome=dict(warnings=[], notices=[]),
                    args={})
         context = Context.from_request(req, event.realm,
                                        event.target.id)
         formatter = HtmlFormatter(self.env, context, wikitext)
         return formatter.generate(True)
     except Exception, e:
         raise
         self.log.error("Failed to render %s", repr(wikitext))
         self.log.error(exception_to_unicode(e, traceback=True))
         return wikitext
    def _format_email(self, authname, sender, recipients, subject, text, mode, links=[], attachments=[]):

        if text:
            req = Mock(
                href=Href(self.env.abs_href()),
                abs_href=self.env.abs_href,
                authname=authname,
                perm=MockPerm(),
                chrome=dict(
                    warnings=[],
                    notices=[]
                    ),
                args={}
                )
            context = Context.from_request(req)
            formatter = HtmlFormatter(self.env, context, text)
            try:
                htmlmessage = formatter.generate(True)
            except Exception, e:
                self.log.error("Failed to render %s", repr(text))
                self.log.error(exception_to_unicode(e, traceback=True))
                htmlmessage = text
示例#7
0
 def render_wiki_to_html_without_req(event, wikitext):
     if wikitext is None:
         return ""
     try:
         req = Mock(
             href=Href(self.env.abs_href()),
             abs_href=self.env.abs_href,
             authname=event.author, 
             perm=MockPerm(),
             chrome=dict(
                 warnings=[],
                 notices=[]
             ),
             args={}
         )
         context = Context.from_request(req, event.realm, event.target.id)
         formatter = HtmlFormatter(self.env, context, wikitext)
         return formatter.generate(True)
     except Exception, e:
         raise
         self.log.error("Failed to render %s", repr(wikitext))
         self.log.error(exception_to_unicode(e, traceback=True))
         return wikitext