def checkRqrdNamespace(xml_file):
    logger.info(
        'verifying that this "body" namespace url in document.xml matches our template'
    )
    namespace_check = True
    ns_url = compareElementNamespace(cfg.doc_xml, cfg.template_document_xml,
                                     'body')
    # log alert as needed
    if ns_url != 'expected' and ns_url != 'unavailable':
        namespace_check = False
        setup_cleanup.setAlert('error', 'unexpected_namespace')
        # send notification to wf team so we can keep an eye on these
        subject = usertext_templates.subjects()["ns_notify"]
        bodytxt = usertext_templates.emailtxt()["ns_notify"].format(
            inputfilename=cfg.inputfilename,
            ns_url=ns_url,
            submitter=cfg.submitter_email,
            alert_text=usertext_templates.alerts()['unexpected_namespace'],
            support_email_address=cfg.support_email_address,
            helpurl=cfg.helpurl)
        sendmail.sendMail([cfg.alert_email_address], subject, bodytxt)
    return namespace_check
            os_utils.writeXMLtoFile(doc_root, doc_xml)

            ### zip ziproot up as a docx
            logger.info(
                "Zipping updated xml to replace workingfile .docx in the tmpfolder"
            )
            # os_utils.rm_existing_os_object(newdocxfile, 'validated_docx') <-- shouldnt be necessary, zipfile.py should overwrite
            zipDOCX.zipDOCX(ziproot, workingfile)  # < for prod
            # zipDOCX.zipDOCX(ziproot, newdocxfile)  # < for testing

        ########## SKIP RUNNING STUFF, LOG ALERTS
        # Doc is not styled or has protection enabled, skip python validation
        else:
            logger.warn("* * Skipping ISBN_check:")
            if protection:
                errstring = usertext_templates.alerts()["protected"].format(
                    protection=protection)
                os_utils.logAlerttoJSON(alerts_json, "error", errstring)
                logger.warn("* {}".format(errstring))

        ########## CLEANUP
        # write our json for style report to tmpdir
        logger.debug("Writing isbn_check.json")
        isbn_dict["completed"] = True
        os_utils.dumpJSON(isbn_dict, cfg.isbn_check_json)

        setup_cleanup.cleanupforValidator(this_outfolder, workingfile,
                                          cfg.inputfilename, '',
                                          cfg.stylereport_txt, alerts_json,
                                          cfg.script_name)

    except:
Exemple #3
0
cfg.defineLogger(logfile, cfg.loglevel)
logger = logging.getLogger(__name__)
# w_logger = logging.getLogger('w_logger')


######### RUN!
# only run if this script is being invoked directly
if __name__ == '__main__':

    try:
        ########## SETUP
        # get file submitter via api, copy infile to tmpdir, setup outfolder
        submitter_email, display_name, notdocx = setup_cleanup.setupforReporterOrConverter(inputfile, inputfilename, workingfile, this_outfolder, inputfile_ext)

        if notdocx == True:
            errstring = usertext_templates.alerts()["notdocx"].format(scriptname=cfg.script_name)
            os_utils.logAlerttoJSON(alerts_json, "error", errstring)
            logger.warn("* {}".format(errstring))
        else:
            # copy template to tmpdir, unzip infile and tmpdir
            setup_cleanup.copyTemplateandUnzipFiles(macmillan_template, tmpdir, workingfile, ziproot, template_ziproot)

            ########## CHECK DOCUMENT
            ### check and compare versions, styling percentage, doc protection
            logger.info('Comparing docx version to template, checking percent styled, checking if protection, trackchanges...')
            version_result, current_version, template_version = check_docx.version_test(cfg.customprops_xml, cfg.template_customprops_xml, doc_version_min, doc_version_max)
            percent_styled, macmillan_styled_paras, total_paras = check_docx.macmillanStyleCount(cfg.doc_xml, cfg.styles_xml)
            protection, tc_marker_found, trackchange_status = check_docx.getProtectionAndTrackChangesStatus(cfg.doc_xml, cfg.settings_xml, cfg.footnotes_xml, cfg.endnotes_xml)

            # create warnings re: track changes:
            if tc_marker_found == True:
            cfg.doc_xml, cfg.styles_xml)
        protection, tc_marker_found, trackchange_status = check_docx.getProtectionAndTrackChangesStatus(
            cfg.doc_xml, cfg.settings_xml, cfg.footnotes_xml, cfg.endnotes_xml)

        # log for the rest o the validator suite:
        report_dict["percent_styled"] = percent_styled

        ########## RUN STUFF
        # Basic requirements passed, proceed with validation & cleanup
        if percent_styled >= percent_styled_min and protection == "" and version_result != "docversion_above_maximum":
            logger.info("Proceeding! (percent_styled='%s', protection='%s')" %
                        (percent_styled, protection))

            # note and accept all track changes
            if tc_marker_found == True:
                errstring = usertext_templates.alerts()["v_unaccepted_tcs"]
                os_utils.logAlerttoJSON(alerts_json, "warning", errstring)
                logger.warn("* {}".format(errstring))
                check_docx.acceptTrackChanges(cfg.doc_xml)
                if os.path.exists(cfg.footnotes_xml):
                    check_docx.acceptTrackChanges(cfg.footnotes_xml)
                if os.path.exists(cfg.endnotes_xml):
                    check_docx.acceptTrackChanges(cfg.endnotes_xml)

            # # # Attach the template as needed
            if version_result == "no_version" or version_result == "docversion_below_minimum":
                errstring = usertext_templates.alerts()["v_no_template"]
                os_utils.logAlerttoJSON(alerts_json, "warning", errstring)
                logger.warn("* {}".format(errstring))
                # logger.info("'version_result' = '%s'. Attaching macmillan template (updating styles in styles.xml, etc)" % version_result)
                # # print "* This .docx did not have section start styles, attaching up-to-date template"
Exemple #5
0
                                      time.strftime("%y%m%d-%H%M%S")))
cfg.defineLogger(logfile, cfg.loglevel)
logger = logging.getLogger(__name__)

######### RUN!
# only run if this script is being invoked directly
if __name__ == '__main__':
    try:
        ########## SETUP
        # get file submitter via api, copy infile to tmpdir, setup outfolder
        submitter_email, display_name, notdocx = setup_cleanup.setupforReporterOrConverter(
            inputfile, inputfilename, workingfile, this_outfolder,
            inputfile_ext)

        if notdocx == True:
            errstring = usertext_templates.alerts()["notdocx"].format(
                scriptname=cfg.script_name)
            os_utils.logAlerttoJSON(alerts_json, "error", errstring)
            logger.warn("* {}".format(errstring))
        else:
            # copy template to tmpdir, unzip infile and tmpdir
            setup_cleanup.copyTemplateandUnzipFiles(macmillan_template, tmpdir,
                                                    workingfile, ziproot,
                                                    template_ziproot)

            ########## CHECK DOCUMENT
            ### check and compare versions, styling percentage, doc protection
            logger.info(
                'Comparing docx version to template, checking percent styled, checking if protection, trackchanges...'
            )
            version_result, current_version, template_version = check_docx.version_test(
                cfg.customprops_xml, cfg.template_customprops_xml,