# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Roberto Bordolanghi
#
# This file is part of the Screenshot Paste plugin for Trac.
#
# The Screenshot Paste plugin for Trac is free software: you can
# redistribute it and/or modify it under the terms of the GNU General
# Public License as published by the Free Software Foundation, either
# version 3 of the License, or (at your option) any later version.
#
# The Screenshot Paste plugin for Trac is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the Screenshot Paste plugin for Trac.
# If not, see .
#
import re
import sys
import traceback
from genshi import HTML
from genshi.builder import tag
from genshi.core import Stream, Markup, escape
from trac.core import *
from trac.util.text import CRLF
from trac.web.chrome import add_stylesheet, add_script, ITemplateProvider
def get_page_title(text):
return text.split('\n')[0].strip('\r\n').strip('= \'')
def get_page_description(text):
return text.partition(CRLF)[2]
def write_common_code(req, rel_path=''):
add_stylesheet(req, 'common/css/report.css')
add_stylesheet(req, 'screenshotpaste/css/blitzer/jquery-ui-1.8.13.custom.css')
add_stylesheet(req, 'screenshotpaste/css/screenshotpaste.css')
common_code = """
""" % {"rel_path": rel_path, "base_location": fix_base_location(req)}
return HTML(common_code)
def fix_base_location(req):
base_location = req.href('/')
if base_location.endswith('/'):
base_location = base_location[:-1]
return base_location
def formatExceptionInfo(maxTBlevel=5):
cla, exc, trbk = sys.exc_info()
excName = cla.__name__
try:
excArgs = exc.__dict__["args"]
except KeyError:
excArgs = ""
excTb = traceback.format_tb(trbk, maxTBlevel)
tracestring = ""
for step in excTb:
tracestring += step + "\n"
return "Error name: %s\nArgs: %s\nTraceback:\n%s" % (excName, excArgs, tracestring)