def insertBookinfo(report_dict, doc_root, stylename, leadingpara_style,
                   bookinfo_item):
    logger.info("commencing insertBookinfo for: '%s'..." % stylename)
    if not lxml_utils.findParasWithStyle(stylename, doc_root):
        # get LEADINGPARASTYLE style which should already exist
        leadingpara = lxml_utils.findParasWithStyle(leadingpara_style,
                                                    doc_root)[0]
        if leadingpara is not None and bookinfo_item:
            lxml_utils.insertPara(stylename, leadingpara, doc_root,
                                  bookinfo_item, "after")
            lxml_utils.logForReport_old(
                report_dict, doc_root, leadingpara.getnext(),
                "added_required_book_info",
                "added '%s' paragraph with content: '%s'" %
                (lxml_utils.getStyleLongname(stylename), bookinfo_item))
        else:
            if not bookinfo_item:
                lxml_utils.logForReport_old(
                    report_dict, doc_root, leadingpara.getnext(),
                    "added_required_book_info",
                    "added '%s' paragraph with content: '%s'" %
                    (lxml_utils.getStyleLongname(stylename), bookinfo_item))
                logger.warn(
                    "'%s' was missing from the manuscript but could not be auto-inserted because %s lookup value was empty."
                    % (stylename, bookinfo_item))
            if leadingpara is None:
                logger.warn(
                    "Could not find required %s styled 'leading_para' to insert bookinfo field: '%s'"
                    % (leadingpara_style, bookinfo_item))
    return report_dict
def insertEbookISBN(report_dict, doc_root, copyrightsection_stylename,
                    copyrightstyles, isbn, isbnstyle):
    logger.info("* * * commencing insertEbookISBN function...")
    sectionpara = lxml_utils.findParasWithStyle(copyrightsection_stylename,
                                                doc_root)[0]
    lastpara = sectionpara
    pneighbors = lxml_utils.getNeighborParas(sectionpara)
    while pneighbors["nextstyle"] in copyrightstyles:
        lastpara = pneighbors["next"]
        # increment the loop
        pneighbors = lxml_utils.getNeighborParas(lastpara)
    # add para
    lxml_utils.insertPara(copyrightstyles[0], lastpara, doc_root, isbn,
                          "after")
    # add runstyle to the isbn:
    new_para = lastpara.getnext()
    new_text = new_para.find(".//*w:t", wordnamespaces)
    # create runstyle and append to run element
    new_run_props = etree.Element("{%s}rPr" % wnamespace)
    new_run_props_style = etree.Element("{%s}rStyle" % wnamespace)
    new_run_props_style.attrib["{%s}val" % wnamespace] = isbnstyle
    new_run_props.append(new_run_props_style)
    new_text.addprevious(new_run_props)
    # log for report
    lxml_utils.logForReport_old(report_dict, doc_root, lastpara.getnext(),
                                "added_ebook_isbn", "added '%s'" % isbn)
    return report_dict
def rmCharStylesFromHeads(report_dict, doc_root, nocharstyle_headingstyles):
    for headingstyle in nocharstyle_headingstyles:
        paras = lxml_utils.findParasWithStyle(headingstyle, doc_root)
        for para in paras:
            rstyle = para.find(".//*w:rStyle", wordnamespaces)
            if rstyle is not None:
                # optional; log to report_dict
                rstylename = rstyle.get('{%s}val' % wnamespace)
                lxml_utils.logForReport_old(
                    report_dict, doc_root, para, "rm_charstyle_from_heading",
                    "Removed '%s' charstyle from '%s' heading." %
                    (rstylename, headingstyle))
                # delete the runstyle!
                rstyle.getparent().remove(rstyle)
    return report_dict
def rmNonPrintingHeads(report_dict, doc_xml, nonprintingheads):
    logger.info("* * * commencing rmNonPrintingHeads function...")
    doc_tree = etree.parse(doc_xml)
    doc_root = doc_tree.getroot()
    for style in nonprintingheads:
        paras = lxml_utils.findParasWithStyle(style, doc_root)
        for para in paras:
            # get text for log
            paratxt = lxml_utils.getParaTxt(para)
            # log the para and remove
            lxml_utils.logForReport_old(
                report_dict, doc_root, para, "removed_nonprintinghead_para",
                "removed a '%s' with contents: '%s'" % (style, paratxt))
            para.getparent().remove(para)
    return report_dict
def insertRequiredSectionStart(sectionstartstyle, doc_root, contents,
                               report_dict):
    logger.info(
        "* * * commencing insertRequiredSectionStart function for (%s)..." %
        sectionstartstyle)
    if not lxml_utils.findParasWithStyle(sectionstartstyle, doc_root):
        # get 1st para of doc:
        first_para = doc_root.find(".//w:p", wordnamespaces)
        # insert my sspara at the beginnig of the doc
        lxml_utils.insertPara(sectionstartstyle, first_para, doc_root,
                              contents, "before")
        # log that we added this!
        lxml_utils.logForReport_old(
            report_dict, doc_root, first_para.getprevious(),
            "added_required_section_start",
            "added '%s' to the beginning of the manuscript" %
            lxml_utils.getStyleLongname(sectionstartstyle))
    return report_dict
Ejemplo n.º 6
0
def logTextOfParasWithStyle(report_dict,
                            doc_root,
                            stylename,
                            report_category,
                            sectionnames,
                            scriptname=""):
    logger.info("Logging paras styled as '%s' to report_dict['%s']" %
                (stylename, report_category))
    paras = lxml_utils.findParasWithStyle(
        lxml_utils.transformStylename(stylename), doc_root)
    for para in paras:
        paratxt = lxml_utils.getParaTxt(para)
        # if we're running this for rsuitevalidate & have an imageholder style, need to do extra checks:
        if stylename in cfg.imageholder_styles and scriptname == 'rsuitevalidate':
            validateImageHolders(report_dict, doc_root, stylename, para,
                                 paratxt, sectionnames)
        lxml_utils.logForReport(report_dict, doc_root, para, report_category,
                                paratxt, ['para_string', 'para_index'])
    return report_dict