[scribus] Crashing script

mental at mentalware.com mental at mentalware.com
Thu Jan 22 04:30:56 CET 2009


I've run into a peculiar problem with a script. I'm a master at Perl and
I used to be pretty good with C, but I'm just starting to muddle around
with Python. I've got a directory with about 50 *.sla files developed
with Scribus-ng 1.3.5svn Build ID: C-C-T-F-C1.8.0 using gs 8.63. I'm on
an Ubuntu Intrepid system with python 2.5.2.

The following script runs perfectly if all the Scribus stuff is stripped
out (in particular, all of the invocations of os.path.join, etc, so my
assumption is that the Python part is ok...but I have been wrong so many
times before about so many things, that another set of eyes might be
useful to me. <g>

Or, I've discovered an obscure bug in Scribus which, perhaps, someone
else has seen before or may think of a way to work around.

Here's my code:
----------------------
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import shutil
try:
    import scribus
except ImportError,err:
    print "This Python script is written for the Scribus scripting
interface."
    print "It can only be run from within Scribus."
    sys.exit(1)

def main(argv):
        """Creates a PDF from each *.sla file found in the source
directory. Copies each file
        to the working directory (the base directory from which all images
can be reached),
        loads it, makes a PDF, unloads it, and deletes the copy leaving
the PDFs behind
        in the working directory.
        """
        src_path = '/home/me/workspace/src';    # directory holding all
completed *.sla files
        work_path = '/home/me/workspace/report';        # directory where
*.sla was created

        if scribus.haveDoc():
                scribus.closeDoc();

        nameList = [os.path.join(src_path, n) for n in os.listdir(src_path)\
        if os.path.isfile(os.path.join(src_path, n)) and n.endswith('.sla')]

        for f in (nameList):                    # loop all of the *.sla
files in the ./done director
                basePath, fn = os.path.split(f)
                fname, ext = os.path.splitext(fn)

                infile = os.path.join(work_path,fn)
                outfile = os.path.join(work_path,fname+'.pdf')

                shutil.copy(f, infile)  # copy the file into the working
directory where it was created

#               load infile into Scribus
                scribus.openDoc(infile)
                scribus.setRedraw(False)        # maybe get a little
performance improvement

#               set up pdf attributes and write the PDF file
                pdf = scribus.PDFfile()
                pdf.outdst = 0                  # screen
                pdf.compress = True             # compress it
                pdf.compressmtd = 0     # use 'automatic' compression
method, set to 2 for zip
                pdf.acopy = True                        # allow copying text
                pdf.aprint = True                       # allow printing
                pdf.achange = False             # disallow changing the
document
                pdf.downsample = 100    # downsample all images to 100 dpi
                pdf.resolution = 100            # maximum allowed resolution
                pdf.info = 'The Solution, Vol 3, Jan 2009'      #
required. Adobe recommends file name, but issue title used
here.
                pdf.thumbnails = False  # don't embed thumbnails
                pdf.file = outfile
                pdf.save()

#               close out this file
                scribus.closeDoc()
                os.unlink(infile);

def main_wrapper(argv):
        """The main_wrapper() function disables redrawing, sets a sensible
generic
        status bar message, and optionally sets up the progress bar. It
then runs
        the main() function. Once everything finishes it cleans up after
the main()
        function, making sure everything is sane before the script
terminates."""
        try:
                scribus.statusMessage("Running script...")
                scribus.progressReset()
                main(argv)
                scribus.messageBox('Note','Finished processing');
        finally:
#               Exit neatly even if the script terminated with an exception.
#               Leave the progress and status bars blank and make sure
drawing is enabled.
                if scribus.haveDoc():
                        scribus.setRedraw(True)
                scribus.statusMessage("")
                scribus.progressReset()

# Only run main() if running as a script as opposed to being imported
if __name__ == '__main__':
    main_wrapper(sys.argv)
----------------------------------

Here's what I see whtn the program crashes after having written the
first PDF file and starts back thru on the second.

Traceback (most recent call last):
  File "", line 8, in
  File "/home/me/workspace/test.py", line 80, in
    main_wrapper(sys.argv)
  File "/home/me/workspace/test.py", line 68, in main_wrapper
    main(argv)
  File "/home/me/workspace/test.py", line 32, in main
    infile = os.path.join(work_path,fn)
  File "/usr/lib/python2.5/posixpath.py", line 59, in join
    for b in p:
IndexError: list assignment index out of range

Any help or ideas would be greatly appreciated.

Pat






More information about the scribus mailing list