problems using customconfig.py

201 views
Skip to first unread message

Richard Ash

unread,
Feb 18, 2010, 11:31:23 AM2/18/10
to mwlib
I have a probable bug, and a more general question about the possibilities of customising the output of mwlib.rl
Bug: if I put
text_align = TA_LEFT

in my customconfig.py to try and produce left aligned text rather than justified text in the PDF file then the render server never makes any progress. In the log file for mwlib.cgi I get an endless sequence of lines like
2010-02-18T16:23:38 mwlib.serve.info >> render_status 8c34910e5f6a8f22 rl
each one second apart, whilst the rendering web page sticks at 0% completed. Checking processes shows that mw-render is being started up for scratch for each refresh of the page, and has exited before the next refresh causes the next instance to start.
If I comment the line back out, then everything starts working again, but obviously text is justified not left aligned.

The more general question is about the different section styles defined in pdfstyles.py. There are lots of blocks like
if mode == 'license':
style.fontSize = 5
style.leading = 1
style.spaceBefore = 0

Is there any way I can disagree and (e.g.) change the font size for license blocks because I want it bigger? It seems if I just over-ride it unconditionally, then I will affect all text, but where do I get an object to test against from, or is the customconfig.py mechanism not designed for this?

Richard

Volker Haas

unread,
Feb 19, 2010, 4:07:51 AM2/19/10
to mw...@googlegroups.com
Hi Richard

Richard Ash wrote:
> I have a probable bug, and a more general question about the possibilities of customising the output of mwlib.rl
> Bug: if I put
> text_align = TA_LEFT
>

You need to import the file where TA_LEFT is defined before you can use it:

from reportlab.lib.enums import TA_LEFT
text_align = TA_LEFT


>
> The more general question is about the different section styles defined in pdfstyles.py. There are lots of blocks like
> if mode == 'license':
> style.fontSize = 5
> style.leading = 1
> style.spaceBefore = 0
>
> Is there any way I can disagree and (e.g.) change the font size for license blocks because I want it bigger? It seems if I just over-ride it unconditionally, then I will affect all text, but where do I get an object to test against from, or is the customconfig.py mechanism not designed for this?
>

I must admit that currently you can't use the customconfig.py file to
change font size of the license for example. One could argue that the
pdfstyles file is poorly designed - but I am somewhat hesitant to change it.

The only solution which seems "practical" to me is to directly edit the
pdfstyles.py file. If you want to do this in a somewhat painless manner
you should probably use git to check out the mwlib.rl repository. If you
go this route you should familiarize yourself with git and python (a
little bit at least - indentation matters for example)

So stfw and rtfm ;)

Good starting points for that are:

* http://docs.python.org/tutorial/
* http://git-scm.com/

You'll also find countless well written tutorials for git elsewhere.

And of course you are always welcome to ask here.

Regards,
Volker

--
volker haas brainbot technologies ag
fon +49 6131 2116394 boppstra�e 64
fax +49 6131 2116392 55118 mainz
volke...@brainbot.com http://www.brainbot.com/

Richard Ash

unread,
Feb 19, 2010, 5:28:10 AM2/19/10
to mw...@googlegroups.com
> From: Volker Haas <volke...@brainbot.com>

> Richard Ash wrote:
> > I have a probable bug, and a more general question about the possibilities of
> customising the output of mwlib.rl
> > Bug: if I put
> > text_align = TA_LEFT
> >
> You need to import the file where TA_LEFT is defined before you can use it:
>
> from reportlab.lib.enums import TA_LEFT
> text_align = TA_LEFT

Thanks! now working fine.



> > The more general question is about the different section styles defined in
> pdfstyles.py. There are lots of blocks like if mode == 'license':
> > style.fontSize = 5
> > style.leading = 1
> > style.spaceBefore = 0
> >
> > Is there any way I can disagree and (e.g.) change the font size for license
> blocks because I want it bigger? It seems if I just over-ride it
> unconditionally, then I will affect all text, but where do I get an object to
> test against from, or is the customconfig.py mechanism not designed for this?
> >
> I must admit that currently you can't use the customconfig.py file to change
> font size of the license for example. One could argue that the pdfstyles file is
> poorly designed - but I am somewhat hesitant to change it.
>
> The only solution which seems "practical" to me is to directly edit the
> pdfstyles.py file. If you want to do this in a somewhat painless manner you
> should probably use git to check out the mwlib.rl repository. If you go this
> route you should familiarize yourself with git and python (a little bit at least
> - indentation matters for example)

For the moment I can live with the sizes, I will come back to this when I have more time to look at it.

Working on this I also hit a bug in PIL 1.1.7 which causes any page with an image on it to be rendered as plain text (and no images). mw-render.log contains tracebacks like
2010-02-19T09:37:57 rlwriter.error >> Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/mwlib/rl/rlwriter.py", line 387, in art
icleRenderingOK
testdoc.build(elements)
[...]
File "/usr/lib/python2.6/site-packages/mwlib/ext/reportlab/pdfgen/canvas.py",
line 794, in drawImage
rawdata = image.getRGBData()
File "/usr/lib/python2.6/site-packages/mwlib/ext/reportlab/lib/utils.py", line
664, in getRGBData
self._dataA = ImageReader(im.split()[3])
File "/usr/lib/python2.6/site-packages/PIL/Image.py", line 1497, in split
if self.im.bands == 1:
AttributeError: 'NoneType' object has no attribute 'bands'

The problem is that PIL should load the image before trying to access the number of bands, but doesn't. This is known upstream (there is a debian bug against PIL), to work around it you just need to do the load() explicitly before trying to access the number of bands.

diff -ur mwlib.ext-0.12.2.orig/upstream-src/src/reportlab/lib/utils.py mwlib.ext-0.12.2/upstream-src/src/reportlab/lib/utils.py
--- mwlib.ext-0.12.2.orig/upstream-src/src/reportlab/lib/utils.py 2009-09-11 13:10:24.000000000 +0100
+++ mwlib.ext-0.12.2/upstream-src/src/reportlab/lib/utils.py 2010-02-19 09:56:32.000000000 +0000
@@ -661,6 +661,7 @@
im = self._image
mode = self.mode = im.mode
if mode=='RGBA':
+ im.load()
self._dataA = ImageReader(im.split()[3])
im = im.convert('RGB')
self.mode = 'RGB'

I don't know if it's worth trying to put this through to Reportlab, but it might help anyone else who finds that images don't work with PIL 1.1.7.

Thanks,

Richard

Ralf Schmitt

unread,
Feb 22, 2010, 8:29:55 AM2/22/10
to mw...@googlegroups.com
Richard Ash <richard...@yahoo.co.uk> writes:

>
> Working on this I also hit a bug in PIL 1.1.7 which causes any page with an image on it to be rendered as plain text (and no images). mw-render.log contains tracebacks like
> 2010-02-19T09:37:57 rlwriter.error >> Traceback (most recent call last):
> File "/usr/lib/python2.6/site-packages/mwlib/rl/rlwriter.py", line 387, in art
> icleRenderingOK
> testdoc.build(elements)
> [...]
> File "/usr/lib/python2.6/site-packages/mwlib/ext/reportlab/pdfgen/canvas.py",
> line 794, in drawImage
> rawdata = image.getRGBData()
> File "/usr/lib/python2.6/site-packages/mwlib/ext/reportlab/lib/utils.py", line
> 664, in getRGBData
> self._dataA = ImageReader(im.split()[3])
> File "/usr/lib/python2.6/site-packages/PIL/Image.py", line 1497, in split
> if self.im.bands == 1:
> AttributeError: 'NoneType' object has no attribute 'bands'
>
> The problem is that PIL should load the image before trying to access the number of bands, but doesn't. This is known upstream (there is a debian bug against PIL), to work around it you just need to do the load() explicitly before trying to access the number of bands.
>

Many thanks for looking into this and providing a patch. I've applied it
to mwlib.ext in
http://code.pediapress.com/git/?p=mwlib.ext/.git;a=commit;h=d5823791b35f6df5fb182b80130be1fb7a17695a
and also uploaded a new version to pypi
(http://pypi.python.org/pypi/mwlib.ext/0.12.3)

Regards,
- Ralf

Reply all
Reply to author
Forward
0 new messages