Beispiel #1
0
 def render_logs(self):
     if lumen.config['logpath']:
         logFilePath = os.path.abspath(lumen.config['logpath'])
         logFile = open(logFilePath)
         return [
               tags.h3()['Logs'],
               tags.pre(style='border:1px solid #ccc; padding: 0.5em; overflow:auto')[
                   self.tail_logs(logFile)
               ],
         ]
     else:
         return []
Beispiel #2
0
 def render_preview(self, context, data):
     docstring = parse_str(self.docstring)
     stan, errors = epydoc2stan.doc2html(
         self.ob, docstring=docstring)
     if self.isPreview or errors:
         if errors:
             tag = context.tag
             #print stan, errors
             #assert isinstance(stan, tags.pre)
             [text] = stan.children
             lines = text.replace('\r\n', '\n').split('\n')
             line2err = {}
             for err in errors:
                 if isinstance(err, str):
                     ln = None
                 else:
                     ln = err.linenum()
                 line2err.setdefault(ln, []).append(err)
             w = len(str(len(lines)))
             for i, line in enumerate(lines):
                 i += 1
                 cls = "preview"
                 if i in line2err:
                     cls += " error"
                 tag[tags.pre(class_=cls)["%*s"%(w, i), ' ', line]]
                 for err in line2err.get(i, []):
                     tag[tags.p(class_="errormessage")[err.descr()]]
             i += 1
             for err in line2err.get(i, []):
                 tag[tags.p(class_="errormessage")[err.descr()]]
             items = []
             for err in line2err.get(None, []):
                 items.append(tags.li[str(err)])
             if items:
                 tag[tags.ul[items]]
         else:
             tag = context.tag[stan]
         return tag[tags.h2["Edit"]]
     else:
         return ()
Beispiel #3
0
 def render_preview(self, context, data):
     docstring = parse_str(self.docstring)
     stan, errors = epydoc2stan.doc2html(self.ob, docstring=docstring)
     if self.isPreview or errors:
         if errors:
             tag = context.tag
             #print stan, errors
             #assert isinstance(stan, tags.pre)
             [text] = stan.children
             lines = text.replace('\r\n', '\n').split('\n')
             line2err = {}
             for err in errors:
                 if isinstance(err, str):
                     ln = None
                 else:
                     ln = err.linenum()
                 line2err.setdefault(ln, []).append(err)
             w = len(str(len(lines)))
             for i, line in enumerate(lines):
                 i += 1
                 cls = "preview"
                 if i in line2err:
                     cls += " error"
                 tag[tags.pre(class_=cls)["%*s" % (w, i), ' ', line]]
                 for err in line2err.get(i, []):
                     tag[tags.p(class_="errormessage")[err.descr()]]
             i += 1
             for err in line2err.get(i, []):
                 tag[tags.p(class_="errormessage")[err.descr()]]
             items = []
             for err in line2err.get(None, []):
                 items.append(tags.li[str(err)])
             if items:
                 tag[tags.ul[items]]
         else:
             tag = context.tag[stan]
         return tag[tags.h2["Edit"]]
     else:
         return ()
Beispiel #4
0
 def content(self, **kwargs):
     """Subclasses should probably override this with something prettier."""
     return t.pre(pprint.pformat(self.data(**kwargs)))
Beispiel #5
0
def formatFailure(myFailure):
    if not isinstance(myFailure, failure.Failure):
        return t.pre[str(myFailure)]

    stackTrace = t.div(_class="stackTrace")
    failureOverview = t.p(_class="error")[str(myFailure.type), ": ",
                                          str(myFailure.value)]

    result = [
        t.style(type="text/css")[stylesheet, ],
        t.a(href="#tracebackEnd")[failureOverview], stackTrace,
        t.a(name="tracebackEnd")[failureOverview]
    ]

    first = 1
    for method, filename, lineno, localVars, globalVars in myFailure.frames:
        # It's better to have a line number than nothing at all.
        #if filename == '<string>':
        #    continue
        if first:
            frame = t.div(_class="firstFrame")
            first = 0
        else:
            frame = t.div(_class="frame")
        stackTrace[frame]

        snippet = t.div(_class="snippet")
        frame[t.div(_class="location")[filename, ", line ", lineno, " in ",
                                       t.span(_class="function")[method]],
              snippet, ]

        textSnippet = ''
        for snipLineNo in range(lineno - 2, lineno + 2):
            snipLine = linecache.getline(filename, snipLineNo)
            textSnippet += snipLine
            if snipLineNo == lineno:
                snippetClass = "snippetHighlightLine"
            else:
                snippetClass = "snippetLine"
            snippet[t.div(_class=snippetClass)[t.span(
                _class="lineno")[snipLineNo],
                                               t.pre(_class="code")[snipLine]]]

        # Instance variables
        for name, var in localVars:
            if name == 'self' and hasattr(var, '__dict__'):
                usedVars = [(key, value)
                            for (key, value) in var.__dict__.items()
                            if re.search(r'\Wself.%s\W' %
                                         (re.escape(key), ), textSnippet)]
                if usedVars:
                    frame[t.div(_class="variables")[t.strong(
                        _class="variableClass")["Self"],
                                                    varTable(usedVars)]]
                    break

        # Local and global vars
        for nm, varList in ('Locals', localVars), ('Globals', globalVars):
            usedVars = [
                (name, var) for (name, var) in varList
                if re.search(r'\W%s\W' % (re.escape(name), ), textSnippet)
            ]
            if usedVars:
                frame[t.div(_class="variables")[t.strong(
                    _class="variableClass")[nm]],
                      varTable(usedVars)]

    return result
Beispiel #6
0
def formatFailure(myFailure):
    if not isinstance(myFailure, failure.Failure):
        return t.pre[ str(myFailure) ]

    stackTrace = t.div(_class="stackTrace")
    failureOverview = t.p(_class="error")[ str(myFailure.type), ": ", str(myFailure.value) ]

    result = [
        t.style(type="text/css")[
            stylesheet,
        ],
        t.a(href="#tracebackEnd")[ failureOverview ],
        stackTrace,
        t.a(name="tracebackEnd")[ failureOverview ]
    ]

    first = 1
    for method, filename, lineno, localVars, globalVars in myFailure.frames:
        # It's better to have a line number than nothing at all.
        #if filename == '<string>':
        #    continue
        if first:
            frame = t.div(_class="firstFrame")
            first = 0
        else:
            frame = t.div(_class="frame")
        stackTrace[ frame ]

        snippet = t.div(_class="snippet")
        frame[
            t.div(_class="location")[
                filename, ", line ", lineno, " in ", t.span(_class="function")[ method ]
            ],
            snippet,
        ]

        textSnippet = ''
        for snipLineNo in range(lineno-2, lineno+2):
            snipLine = linecache.getline(filename, snipLineNo)
            textSnippet += snipLine
            if snipLineNo == lineno:
                snippetClass = "snippetHighlightLine"
            else:
                snippetClass = "snippetLine"
            snippet[
                t.div(_class=snippetClass)[
                    t.span(_class="lineno")[ snipLineNo ],
                    t.pre(_class="code")[ snipLine ]
                ]
            ]

        # Instance variables
        for name, var in localVars:
            if name == 'self' and hasattr(var, '__dict__'):
                usedVars = [ (key, value) for (key, value) in var.__dict__.items()
                             if re.search(r'\Wself.%s\W' % (re.escape(key),), textSnippet) ]
                if usedVars:
                    frame[
                        t.div(_class="variables")[
                            t.strong(_class="variableClass")[ "Self" ],
                            varTable(usedVars)
                        ]
                    ]
                    break

        # Local and global vars
        for nm, varList in ('Locals', localVars), ('Globals', globalVars):
            usedVars = [ (name, var) for (name, var) in varList
                         if re.search(r'\W%s\W' % (re.escape(name),), textSnippet) ]
            if usedVars:
                frame[
                    t.div(_class="variables")[ t.strong(_class="variableClass")[ nm ] ],
                    varTable(usedVars)
                ]

    return result