Preliminary support for tracing through doc builds
authorandy_robinson
Sun, 09 Nov 2003 00:54:22 +0000
changeset 2113 e82d8b3880d8
parent 2112 8281bbabfd67
child 2114 26c636b61f7f
Preliminary support for tracing through doc builds
reportlab/platypus/__init__.py
reportlab/platypus/doctemplate.py
reportlab/platypus/flowables.py
--- a/reportlab/platypus/__init__.py	Sat Nov 08 18:40:09 2003 +0000
+++ b/reportlab/platypus/__init__.py	Sun Nov 09 00:54:22 2003 +0000
@@ -1,11 +1,11 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/__init__.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/__init__.py,v 1.15 2002/07/24 19:56:38 andy_robinson Exp $
-__version__=''' $Id: __init__.py,v 1.15 2002/07/24 19:56:38 andy_robinson Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/__init__.py,v 1.16 2003/11/09 00:54:22 andy_robinson Exp $
+__version__=''' $Id: __init__.py,v 1.16 2003/11/09 00:54:22 andy_robinson Exp $ '''
 __doc__=''
 from reportlab.platypus.flowables import Flowable, Image, Macro, PageBreak, Preformatted, Spacer, XBox, \
-                        CondPageBreak, KeepTogether
+                        CondPageBreak, KeepTogether, TraceInfo, FailOnWrap, FailOnDraw
 from reportlab.platypus.paragraph import Paragraph, cleanBlockQuotedText, ParaLines
 from reportlab.platypus.paraparser import ParaFrag
 from reportlab.platypus.tables import Table, TableStyle, CellStyle
--- a/reportlab/platypus/doctemplate.py	Sat Nov 08 18:40:09 2003 +0000
+++ b/reportlab/platypus/doctemplate.py	Sun Nov 09 00:54:22 2003 +0000
@@ -1,9 +1,9 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/doctemplate.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.66 2003/10/28 12:57:11 rgbecker Exp $
+#$Header: /tmp/reportlab/reportlab/platypus/doctemplate.py,v 1.67 2003/11/09 00:54:22 andy_robinson Exp $
 
-__version__=''' $Id: doctemplate.py,v 1.66 2003/10/28 12:57:11 rgbecker Exp $ '''
+__version__=''' $Id: doctemplate.py,v 1.67 2003/11/09 00:54:22 andy_robinson Exp $ '''
 
 __doc__="""
 This module contains the core structure of platypus.
@@ -605,7 +605,24 @@
 
         while len(flowables):
             self.clean_hanging()
-            self.handle_flowable(flowables)
+            try:
+                first = flowables[0]
+                self.handle_flowable(flowables)
+            except:
+                #if it has trace info, add it to the traceback message.
+                if first._traceInfo:
+                    exc = sys.exc_info()[1]
+                    args = list(exc.args)
+                    tr = first._traceInfo
+                    args[0] = args[0] + '\n(srcFile %s, line %d char %d to line %d char %d)' % (
+                        tr.srcFile,
+                        tr.startLineNo,
+                        tr.startLinePos,
+                        tr.endLineNo,
+                        tr.endLinePos
+                        )
+                    exc.args = tuple(args)
+                raise
             if self._onProgress:
                 self._onProgress('PROGRESS',flowableCount - len(flowables))
 
--- a/reportlab/platypus/flowables.py	Sat Nov 08 18:40:09 2003 +0000
+++ b/reportlab/platypus/flowables.py	Sun Nov 09 00:54:22 2003 +0000
@@ -1,8 +1,8 @@
 #copyright ReportLab Inc. 2000
 #see license.txt for license details
 #history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/platypus/flowables.py?cvsroot=reportlab
-#$Header: /tmp/reportlab/reportlab/platypus/flowables.py,v 1.40 2003/09/18 09:07:37 rgbecker Exp $
-__version__=''' $Id: flowables.py,v 1.40 2003/09/18 09:07:37 rgbecker Exp $ '''
+#$Header: /tmp/reportlab/reportlab/platypus/flowables.py,v 1.41 2003/11/09 00:54:22 andy_robinson Exp $
+__version__=''' $Id: flowables.py,v 1.41 2003/11/09 00:54:22 andy_robinson Exp $ '''
 __doc__="""
 A flowable is a "floating element" in a document whose exact position is determined by the
 other elements that precede it, such as a paragraph, a diagram interspersed between paragraphs,
@@ -38,6 +38,16 @@
 from reportlab.rl_config import defaultPageSize
 PAGE_HEIGHT = defaultPageSize[1]
 
+
+class TraceInfo:
+    "Holder for info about where an object originated"
+    def __init__(self):
+        self.srcFile = '(unknown)'
+        self.startLineNo = -1
+        self.startLinePos = -1
+        self.endLineNo = -1
+        self.endLinePos = -1
+        
 #############################################################
 #   Flowable Objects - a base class and a few examples.
 #   One is just a box to get some metrics.  We also have
@@ -62,6 +72,9 @@
         self.hAlign = 'LEFT'    #CENTER/CENTRE or RIGHT
         self.vAlign = 'BOTTOM'  #MIDDLE or TOP
 
+        #optional holder for trace info
+        self._traceInfo = None
+        
 
     def _drawOn(self,canv):
         '''ensure canv is set on and then draw'''
@@ -491,3 +504,17 @@
         canv = self.canv
         self.I.drawOn(canv,self.width-self.wI-self.xpad,self.height-self.hI)
         self.P.drawOn(canv,0,0)
+
+class FailOnWrap(Flowable):
+    def wrap(self, availWidth, availHeight):
+        raise ValueError("FailOnWrap flowable wrapped and failing as ordered!")
+    
+    def draw(self):
+        pass
+
+class FailOnDraw(Flowable):
+    def wrap(self, availWidth, availHeight):
+        return (0,0)
+    
+    def draw(self):
+        raise ValueError("FailOnDraw flowable drawn, and failing as ordered!")