Exemple #1
0
def build_xml(article_id, article=None, jats_config=None, add_comment=True):
    "generate xml from an article object"
    if not jats_config:
        jats_config = parse_raw_config(raw_config(None))

    if not article:
        article = build_article_from_csv(article_id, jats_config)
        if not hasattr(article, "manuscript"):
            LOGGER.info("could not build article for %s", article_id)
            return None

    article_xml = ArticleXML(article, jats_config, add_comment)
    if hasattr(article_xml, "root"):
        LOGGER.info("generated xml for %s", article_id)
        return article_xml
    return None
Exemple #2
0
def build_article_from_csv(article_id, jats_config=None):
    "build article objects populated with csv data"
    if not jats_config:
        jats_config = parse_raw_config(raw_config(None))
    article, error_count, error_messages = parse.build_article(article_id)
    if article:
        return article
    LOGGER.warning(
        "the following article did not have enough components and " +
        "xml was not generated %s",
        article_id,
    )
    LOGGER.warning("warning count was %s", error_count)
    if error_messages:
        LOGGER.warning(", ".join(error_messages))
    return False
Exemple #3
0
 def test_parse_raw_config(self):
     "test parsing a raw config of all the different value types"
     # override the library values
     conf.BOOLEAN_VALUES = ["test_boolean"]
     conf.INT_VALUES = ["test_int"]
     conf.LIST_VALUES = ["test_list"]
     # build a config object
     config = configparser.ConfigParser(interpolation=None)
     config["DEFAULT"]["test_boolean"] = "True"
     config["DEFAULT"]["test_int"] = "42"
     config["DEFAULT"]["test_list"] = "[1,1,2,3,5]"
     # parse the raw config for coverage
     config_dict = conf.parse_raw_config(config["DEFAULT"])
     # assert some things
     self.assertIsNotNone(config_dict)
     self.assertEqual(config_dict.get("test_boolean"), True)
     self.assertEqual(config_dict.get("test_int"), 42)
     self.assertEqual(config_dict.get("test_list"), [1, 1, 2, 3, 5])
Exemple #4
0
def build_xml_to_disk(article_id,
                      article=None,
                      jats_config=None,
                      add_comment=True):
    "generate xml from an article object and write to disk"
    if not jats_config:
        jats_config = parse_raw_config(raw_config(None))
    if not article:
        article = build_article_from_csv(article_id, jats_config)
    article_xml = build_xml(article_id, article, jats_config, add_comment)
    if article_xml and hasattr(article_xml, "root"):
        filename = jats_config.get("xml_filename_pattern").format(
            manuscript=article.manuscript)
        try:
            output_dir = jats_config.get("target_output_dir")
            write_xml_to_disk(article_xml, filename, output_dir)
            LOGGER.info("xml written for %s", article_id)
            print("written " + str(article_id))
            return True
        except IOError:
            LOGGER.error("could not write xml for %s", article_id)
            return False
    LOGGER.error("could not generate xml to disk for %s", article_id)
    return False
def build_config(config_section):
    "build the config and override the output directory"
    jats_config = parse_raw_config(raw_config(config_section))
    jats_config["target_output_dir"] = TARGET_OUTPUT_DIR
    return jats_config