Example #1
0
def filter_xml_list_by_header(xml_files: Tuple[str, ...],
                              header: str) -> Tuple[str, ...]:
    """
    Given a list of xml_file locations this function will return a new tuple
    of xml_file locations that all include the header file `header`
    """
    keep_files = list()
    msg = f"Finding source files that include '{header}'"
    title = utils.format_alive_bar_title(msg)

    with alive_bar(len(xml_files), title=title) as bar:
        with Pool(processes=os.cpu_count()) as pool:
            for res, xml_file in pool.imap_unordered(
                    xml_file_has_header,
                [(xml_file, header) for xml_file in xml_files]):
                bar()
                if res:
                    keep_files.append(xml_file)
    return tuple(keep_files)
Example #2
0
def run() -> bool:
    """
    Runs doxygen against the source code. If doxygen returns a non zero
    exit code then this function will return False, else it will return True
    """
    assert os.path.exists(DOXYCONF_LOCATION)

    if not overwrite_prior_doxygen():
        logger.info("Using previous doxygen results")
        return True

    logger.debug("Indexing source code with doxygen, this might take a while")

    kwargs = dict()  #type: Dict[str, Any]
    if not utils.is_verbose():
        kwargs = {**kwargs, "stdout": subprocess.DEVNULL}

    # Run doxy
    try:
        proc = subprocess.Popen(["doxygen", DOXYCONF_LOCATION], **kwargs)
    except subprocess.SubprocessError:
        logger.critical("Failed to run doxygen")
        return False

    # Show ascii bar
    if not utils.is_verbose():
        print("")
        bar_tit = utils.format_alive_bar_title(
            "Indexing source code, this might take a while")
        with alive_bar(title=bar_tit):
            while proc.poll() is None:
                time.sleep(0.1)

    if proc.returncode != 0:
        logger.critical("Doxygen returned a non zero error code")
        logger.info(
            f"Try run again with -v enabled or read {doxygen.config.WARN_LOGFILE}"
        )
        return False

    logger.debug("Doxygen has finished indexing source code")
    return True
Example #3
0
def filter_xml_files_bad_schema(xml_files_locs: Tuple[str, ...],
                                schema: etree.XMLSchema) -> Tuple[str, ...]:
    """
    Doxygen sometimes produces malformed XML files that don't match their schema
    we can drop these xml_files by checking the schema matches
    """
    assert isinstance(schema, etree.XMLSchema)
    valid_files = []
    bin_tit = utils.format_alive_bar_title("Validating file schemas")
    with alive_bar(len(xml_files_locs), title=bin_tit) as bar:
        for loc in xml_files_locs:
            assert os.path.exists(loc)
            try:
                if doxygen.xml_utils.validate_schema(loc, schema):
                    valid_files.append(loc)
                else:
                    logger.warning(f"Schema validation for file {loc} failed")
            except doxygen.xml_utils.DoxygenMalformedXML as e:
                logger.error(e)
            bar()
    return tuple(valid_files)
Example #4
0
def test_format_alive_bar():
    sformat = utils.format_alive_bar_title(" ")
    assert isinstance(sformat, str)
    assert len(sformat) > utils.FORMAT_LJUST
Example #5
0
def test_format_alive_bar_non_str():
    with pytest.raises(AssertionError):
        utils.format_alive_bar_title(1)