<commit_before>#!/usr/bin/python3
''' bdgraph.py

Author:
    <NAME>

Description:
    Reads an input markup file containing definitions, dependencies, and graph
    options, and writes a corresponding output graphviz dot file

Usage:
    python3 bdgraph.py input_file [output_file]
'''

import sys, os
from classes.graph import Graph

# MAIN
def main(argv):
    ''' list -> none
    handles IO '''

    input_fn,output_fn = '', ''

    # parse commandline arguments
    if len(argv) > 0:
        input_fn = str(argv[0])

        if not os.path.exists(input_fn):
            print('error: file "' + input_fn + '" does not exist')
            sys.exit(1)

        # output file name is input + .dot if not provided
        output_fn = str(argv[1]) if len(argv) > 1 else input_fn + '.dot'

    else:
        print('python bdgraph.py input_file [output_file]')
        sys.exit(1)

    # read contents into list
    with open(input_fn, 'r') as input_fd:
        content = [line.strip() for line in input_fd.readlines()]

        # remove comments and blank lines
        content = [line for line in content if line and line[0] != '#']

    graph = Graph(content)
    graph.handle_options()
    graph.transitive_reduction()
    graph.compress_representation()
    graph.write_dot(output_fn)

    # rewrite the input file?
    options = [x.label for x in graph.graph_options]
    if 'cleanup' in options:
        graph.write_config(input_fn)

if __name__ == '__main__':
    main(sys.argv[1:])<commit_msg>Update usage error<commit_after>#!/usr/bin/python3
''' bdgraph.py

Author:
    <NAME>

Description:
    Reads an input markup file containing definitions, dependencies, and graph
    options, and writes a corresponding output graphviz dot file

Usage:
    python3 bdgraph.py input_file [output_file]
'''

import sys, os
from classes.graph import Graph

# MAIN
def main(argv):
    ''' list -> none
    handles IO '''

    input_fn,output_fn = '', ''

    # parse commandline arguments
    if len(argv) > 0:
        input_fn = str(argv[0])

        if not os.path.exists(input_fn):
            print('error: file "' + input_fn + '" does not exist')
            sys.exit(1)

        # output file name is input + .dot if not provided
        output_fn = str(argv[1]) if len(argv) > 1 else input_fn + '.dot'

    else:
        print('usage: python3 bdgraph.py input_file [output_file]')
        sys.exit(1)

    # read contents into list
    with open(input_fn, 'r') as input_fd:
        content = [line.strip() for line in input_fd.readlines()]

        # remove comments and blank lines
        content = [line for line in content if line and line[0] != '#']

    graph = Graph(content)
    graph.handle_options()
    graph.transitive_reduction()
    graph.compress_representation()
    graph.write_dot(output_fn)

    # rewrite the input file?
    options = [x.label for x in graph.graph_options]
    if 'cleanup' in options:
        graph.write_config(input_fn)

if __name__ == '__main__':
    main(sys.argv[1:])
{'fraction_non_alphanumeric': 0.11192294918631684, 'fraction_numerical': 0.006974427100631019, 'mean_word_length': 2.774436090225564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4568380', 'n_tokens_mistral': 960, 'n_tokens_neox': 931, 'n_words': 282}