[odf-devel] bug in addPicture

Toon Verstraelen Toon.Verstraelen at UGent.be
Sat Mar 21 05:35:45 EDT 2009


Hi Søren,

Thanks for the info. I'll check the new version. So far all my 
experiments are going well. When the supporting information file is 
published, I'll send a link on this mailing list. It is maybe a nice 
example of what can be done with odfpy.

Best regards,

Toon

Søren Roug wrote:
> Hello Toon,
> 
> 
> Thanks for the bug fix. It was already pointed out a few months ago and 
> a patch released, that you apparently didn't see.
> 
> 
> I like your idea of splitting up the addPicture method and will 
> introduce it into the product.
> 
> 
> B.t.w. a few days ago I silently released version 0.9, that uses the ODF 
> 1.1 standard. You can download it from 
> http://forge.osor.eu/frs/?group_id=33 or the Python package index.
> 
> 
> I intend to post an announcement about it this weekend.
> 
> 
> /Søren Roug
> 
> 
> Lørdag 21 marts 2009 06:52:43 skrev Toon Verstraelen:
>  > Hi,
>  >
>  > I've been using odfpy-0.8 to generate supporting information for a
>  > scientific paper. These documents typically contain a lot of pictures
>  > and data that one does not want to enter by hand. I ran into a bug when
>  > adding a picture based on a filename:
>  >
>  > Traceback (most recent call last):
>  > File "../../bin/supinf.py", line 59, in <module>
>  > href = doc.addPicture(fn)
>  > File "/usr/local//lib/python2.5/site-packages/odf/opendocument.py",
>  > line 290, in addPicture
>  > self.Pictures[manifestfn] = (IS_FILENAME, fileobj, mediatype)
>  > NameError: global name 'fileobj' is not defined
>  >
>  > It was easy to fix: fileobj must simply be replaced by filename on line
>  > 290. However, I do find the addPicture method very confusing and the
>  > document string talks about file objects that are nowhere in the code. I
>  > suggest to split the method into two different ones, see below. That
>  > makes the code at least understandable.
>  >
>  > best regards,
>  >
>  > Toon
>  >
>  >
>  >
>  > def addPicture(self, filename, mediatype=None):
>  > """ Add a picture
>  > It uses the same convention as OOo, in that it saves the
>  > picture in
>  > the zipfile in the subdirectory 'Pictures'.
>  > If mediatype is not given, it will be guessed from the
>  > filename
>  > extension.
>  > """
>  > if mediatype is None:
>  > mediatype, encoding = mimetypes.guess_type(filename)
>  > if mediatype is None:
>  > mediatype = ''
>  > try: ext = filename[filename.rindex('.'):]
>  > except ValueError: ext=''
>  > else:
>  > ext = mimetypes.guess_extension(mediatype)
>  > manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000),
>  > ext) self.Pictures[manifestfn] = (IS_FILENAME, filename, mediatype) 
> return
>  > manifestfn
>  >
>  > def addPictureString(self, content, mediatype):
>  > """ Add a picture
>  > It uses the same convention as OOo, in that it saves the
>  > picture in
>  > the zipfile in the subdirectory 'Pictures'. The content
>  > variable
>  > is a string that contains the binary image data. The
>  > mediatype indicates the image format.
>  > """
>  > ext = mimetypes.guess_extension(mediatype)
>  > manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000),
>  > ext) self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype) return
>  > manifestfn
>  >
>  >
>  >
>  > _______________________________________________
>  > odf-devel mailing list
>  > odf-devel at opendocumentfellowship.com
>  > http://lists.opendocumentfellowship.com/mailman/listinfo/odf-devel
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> odf-devel mailing list
> odf-devel at opendocumentfellowship.com
> http://lists.opendocumentfellowship.com/mailman/listinfo/odf-devel



More information about the odf-devel mailing list