Exemplo n.º 1
0
def test_get_file_list_dir_recursive():
    # path to this file's directory
    d = get_anchorhub_path() + sep + 'tests' + sep

    abs_input = d + 'test_data' + sep
    abs_output = d + 'anchorhub-out' + sep
    extensions = ['.md', '.markdown']
    recursive = True
    is_dir = True

    a = FileObj(abs_input=abs_input,
                abs_output=abs_output,
                extensions=extensions,
                recursive=recursive,
                is_dir=is_dir)
    l = get_file_list(a)

    expected_files = [
        d + 'test_data' + sep + 'file1.md',
        d + 'test_data' + sep + 'file2.markdown',
        d + 'test_data' + sep + 'dir' + sep + 'file4.md',
        d + 'test_data' + sep + 'dir' + sep + 'file5.markdown'
    ]

    assert len(l) == len(expected_files)
    for f in expected_files:
        assert f in l
Exemplo n.º 2
0
def test_get_file_list_single():
    # path to this file's directory
    d = get_anchorhub_path() + sep + 'tests' + sep

    abs_input = d + 'test_data' + sep + 'file2.markdown'
    abs_output = d + 'anchorhub-out' + sep
    extensions = ['.md', '.markdown']
    recursive = False
    is_dir = False

    a = FileObj(input=abs_input, abs_input=abs_input, abs_output=abs_output,
                extensions=extensions, recursive=recursive, is_dir=is_dir)
    l = get_file_list(a)

    expected_files = [
        d + 'test_data' + sep + 'file2.markdown'
    ]

    assert len(l) == len(expected_files)
    for f in expected_files:
        assert f in l
Exemplo n.º 3
0
def main(argv=None):
    """
    Main entry method for AnchorHub. Takes in command-line arguments,
    finds files to parse within the specified input directory, and outputs
    parsed files to the specified output directory.

    :param argv: a list of string command line arguments
    """
    # Get command line arguments, validate them, and normalize them
    opts = cmdparse.parse_args(argv)
    assert validate_opts.validate(opts)
    opts = normalize_opts.normalize(opts)

    if opts.verbose:
        # Update client: print input and output directories
        messages.print_input_output(opts)

    file_paths = fileparse.get_file_list(opts)
    assert validate_files.validate(file_paths, opts)

    if opts.verbose and opts.is_dir:
        # Update client: print files that will be parsed
        messages.print_files(opts, file_paths)

    # For now, only using default GitHub Markdown for parsing
    # Collect tag/anchor combinations
    collector = make_github_markdown_collector(opts)
    anchors, duplicate_tags = collector.collect(file_paths)
    assert validate_anchors.validate(anchors, duplicate_tags, opts)

    # Write files using previously found AnchorHub tags and generated anchors
    writer = make_github_markdown_writer(opts)
    counter = writer.write(file_paths, anchors, opts)

    if opts.verbose:
        if opts.is_dir:
            # Update client: print files that had modifications
            messages.print_modified_files(opts, anchors)
        # Print summary statistics
        messages.print_summary_stats(counter)
Exemplo n.º 4
0
def main(argv=None):
    """
    Main entry method for AnchorHub. Takes in command-line arguments,
    finds files to parse within the specified input directory, and outputs
    parsed files to the specified output directory.

    :param argv: a list of string command line arguments
    """
    # Get command line arguments, validate them, and normalize them
    opts = cmdparse.parse_args(argv)
    assert validate_opts.validate(opts)
    opts = normalize_opts.normalize(opts)

    if opts.verbose:
        # Update client: print input and output directories
        messages.print_input_output(opts)

    file_paths = fileparse.get_file_list(opts)
    assert validate_files.validate(file_paths, opts)

    if opts.verbose and opts.is_dir:
        # Update client: print files that will be parsed
        messages.print_files(opts, file_paths)

    # For now, only using default GitHub Markdown for parsing
    # Collect tag/anchor combinations
    collector = make_github_markdown_collector(opts)
    anchors, duplicate_tags = collector.collect(file_paths)
    assert validate_anchors.validate(anchors, duplicate_tags, opts)

    # Write files using previously found AnchorHub tags and generated anchors
    writer = make_github_markdown_writer(opts)
    counter = writer.write(file_paths, anchors, opts)

    if opts.verbose:
        if opts.is_dir:
            # Update client: print files that had modifications
            messages.print_modified_files(opts, anchors)
        # Print summary statistics
        messages.print_summary_stats(counter)