Beispiel #1
0
def main():
    """Main program loop."""

    global output_dir
    global log_level

    parser = argparse.ArgumentParser(description="DocWriter Usage information")
    parser.add_argument(
        "files",
        nargs="+",
        help="list of source files to parse, wildcards are allowed",
    )
    parser.add_argument(
        "-t",
        "--title",
        metavar="T",
        help="set project title, as in '-t \"My Project\"'",
    )
    parser.add_argument(
        "-o",
        "--output",
        metavar="DIR",
        required=True,
        help="set output directory, as in '-o mydir'",
    )
    parser.add_argument(
        "-p",
        "--prefix",
        metavar="PRE",
        help="set documentation prefix, as in '-p ft2'",
    )
    parser.add_argument(
        "-s",
        "--site",
        metavar="DIR",
        help="set 'site_dir' in mkdocs.yml [default=site]",
    )
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        "-q",
        "--quiet",
        help="run quietly, show only errors",
        action="store_true",
    )
    group.add_argument(
        "-v", "--verbose", help="increase output verbosity", action="store_true"
    )
    args = parser.parse_args()

    # process options
    project_title = "Project"
    project_prefix = None
    output_dir = None

    if args.title:
        project_title = args.title

    if args.output:
        utils.output_dir = args.output

    if args.prefix:
        project_prefix = args.prefix

    if args.site:
        utils.site_dir = args.site

    if args.quiet:
        log_level = logging.ERROR

    if args.verbose:
        log_level = logging.DEBUG

    # set up the logger
    setup_logger(level=log_level)
    log = logging.getLogger("docwriter")

    # check all packages
    status = check.check()
    if status != 0:
        sys.exit(3)

    utils.check_output()
    utils.create_markdown_dir()

    # create context and processor
    source_processor = sources.SourceProcessor()
    content_processor = content.ContentProcessor()

    # retrieve the list of files to process
    file_list = utils.make_file_list(args.files)
    for filename in file_list:
        source_processor.parse_file(filename)
        content_processor.parse_sources(source_processor)

    # process sections
    content_processor.finish()

    # clean up directory
    log.info("Cleaning output directory")
    utils.clean_markdown_dir()

    formatter = tomarkdown.MdFormatter(
        content_processor, project_title, project_prefix
    )

    # build the docs
    utils.build_message()

    formatter.toc_dump()
    formatter.index_dump()
    formatter.section_dump_all()
Beispiel #2
0
#  this file you indicate that you have read the license and
#  understand and accept it fully.

"""Unit tests for `tomarkdown`.

This module contains tests for functions in `tomarkdown.py`.
"""

from docwriter import content
from docwriter import sources
from docwriter import tomarkdown
from docwriter import utils

# Create test objects
# create context and processor
source_processor  = sources.SourceProcessor()
content_processor = content.ContentProcessor()
# Names
project_title  = 'Test Docs'
project_prefix = 'test'
# retrieve the list of files to process
file_list = utils.make_file_list( ['./assets/*.c'] )
for filename in file_list:
    source_processor.parse_file( filename )
    content_processor.parse_sources( source_processor )
# process sections
content_processor.finish()

formatter = tomarkdown.MdFormatter( content_processor,
                                    project_title,
                                    project_prefix )