Esempio n. 1
0
def run(infilename, outfilename):
    p = yaml.Parser()
    results = p.parseFile(infilename)

    ss = getStyleSheet()

    #now make flowables from the results
    story = []
    for thingy in results:
        typ = thingy[0]
        if typ == 'Paragraph':
            (typ2, stylename, text) = thingy
            if stylename == 'bu':
                bulletText = '\267'
            else:
                bulletText = None
            try:
                style = ss[stylename]
            except KeyError:
                print 'Paragraph style "%s" not found in stylesheet, using Normal instead' % stylename
                style = ss['Normal']
            story.append(Paragraph(text, style, bulletText=bulletText))
        elif typ == 'Preformatted':
            (typ2, stylename, text) = thingy
            try:
                style = ss[stylename]
            except KeyError:
                print 'Preformatted style "%s" not found in stylesheet, using Normal instead' % stylename
                style = ss['Normal']
            story.append(Preformatted(text, style, bulletText=bulletText))
        elif typ == 'Image':
            filename = thingy[1]
            img = Image(filename)
            story.append(img)
        elif typ == 'PageBreak':
            story.append(PageBreak())
        elif typ == 'VSpace':
            height = thingy[1]
            story.append(Spacer(0, height))
        elif typ == 'NextPageTemplate':
            story.append(NextPageTemplate(thingy[1]))
        elif typ == 'Custom':
            # go find it
            searchPath = [os.getcwd() + '\\']
            (typ2, moduleName, funcName) = thingy
            found = imp.find_module(moduleName, searchPath)
            assert found, "Custom object module %s not found" % moduleName
            (file, pathname, description) = found
            mod = imp.load_module(moduleName, file, pathname, description)

            #now get the function
            func = getattr(mod, funcName)
            story.append(func())

        else:
            print 'skipping', typ, 'for now'

    #print it
    doc = RLDocTemplate(outfilename, pagesize=A4)
    doc.build(story)
Esempio n. 2
0
def run(infilename, outfilename):
    p = yaml.Parser()
    results = p.parseFile(infilename)

    ss = getStyleSheet()

    # now make flowables from the results
    story = []
    for thingy in results:
        typ = thingy[0]
        if typ == "Paragraph":
            (typ2, stylename, text) = thingy
            if stylename == "bu":
                bulletText = "\267"
            else:
                bulletText = None
            try:
                style = ss[stylename]
            except KeyError:
                print 'Paragraph style "%s" not found in stylesheet, using Normal instead' % stylename
                style = ss["Normal"]
            story.append(Paragraph(text, style, bulletText=bulletText))
        elif typ == "Preformatted":
            (typ2, stylename, text) = thingy
            try:
                style = ss[stylename]
            except KeyError:
                print 'Preformatted style "%s" not found in stylesheet, using Normal instead' % stylename
                style = ss["Normal"]
            story.append(Preformatted(text, style, bulletText=bulletText))
        elif typ == "Image":
            filename = thingy[1]
            img = Image(filename)
            story.append(img)
        elif typ == "PageBreak":
            story.append(PageBreak())
        elif typ == "VSpace":
            height = thingy[1]
            story.append(Spacer(0, height))
        elif typ == "NextPageTemplate":
            story.append(NextPageTemplate(thingy[1]))
        elif typ == "Custom":
            # go find it
            searchPath = [os.getcwd() + "\\"]
            (typ2, moduleName, funcName) = thingy
            found = imp.find_module(moduleName, searchPath)
            assert found, "Custom object module %s not found" % moduleName
            (file, pathname, description) = found
            mod = imp.load_module(moduleName, file, pathname, description)

            # now get the function
            func = getattr(mod, funcName)
            story.append(func())

        else:
            print "skipping", typ, "for now"

    # print it
    doc = RLDocTemplate(outfilename, pagesize=A4)
    doc.build(story)
Esempio n. 3
0
 def record(self):
     doc = RLDocTemplate(self.destination, pagesize=A4)
     doc.build(self.story)
Esempio n. 4
0
 def record(self):
     doc = RLDocTemplate(self.destination, pagesize=A4)
     doc.build(self.story)