<commit_before>#!/usr/bin/env python

from __future__ import print_function
import sys
import argparse
import yaml

from cnsparser import CNSParser

parser = argparse.ArgumentParser(description='Convert a run.cns file to a YAML model description')

parser.add_argument(
    '-V', '--version',
    action  = 'version',
    version = '%(prog)s 0.1'
)
parser.add_argument(
    '-v', '--verbose',
    dest    = 'verbose',
    action  = 'store_true',
    default = False,
    help    = 'print parsing information to stderr'
)
parser.add_argument(
    '-w', '--warnings',
    dest    = 'warnings',
    action  = 'store_true',
    default = False,
    help    = 'show warnings for unrecognized input data'
)
parser.add_argument(
    '-W', '--fatal-warnings',
    dest    = 'fatal_warnings',
    action  = 'store_true',
    default = False,
    help    = 'make unrecognized input data throw a fatal error, implicitly sets -w'
)
parser.add_argument(
    'source', metavar='INPUT',
    type    = argparse.FileType('r'),
    default = sys.stdin,
    nargs   = '?',
    help    = 'the run.cns file to parse, defaults to \'-\' for stdin'
)
parser.add_argument(
    '-o', '--output', metavar='OUTPUT',
    dest    = 'destination',
    type    = argparse.FileType('w'),
    default = sys.stdout,
    help    = 'the output YAML file, defualts to \'-\' for stdout'
)

args = parser.parse_args()

# Pass arguments as an unpacked dictionary to the CNSParser constructor
parser = CNSParser(**dict(
    (key, value) for (key, value) in vars(args).iteritems()
        if key not in set(['destination'])
))
accesslevels, components = parser.parse()

print(yaml.dump_all([accesslevels, components],
    explicit_start=True, default_flow_style=False), file=args.destination)<commit_msg>Added compact option to cnstoyml.py<commit_after>#!/usr/bin/env python

from __future__ import print_function
import sys
import argparse
import yaml

from cnsparser import CNSParser

parser = argparse.ArgumentParser(description='Convert a run.cns file to a YAML model description')

parser.add_argument(
    '-V', '--version',
    action  = 'version',
    version = '%(prog)s 0.1'
)
parser.add_argument(
    '-v', '--verbose',
    dest    = 'verbose',
    action  = 'store_true',
    default = False,
    help    = 'print parsing information to stderr'
)
parser.add_argument(
    '-w', '--warnings',
    dest    = 'warnings',
    action  = 'store_true',
    default = False,
    help    = 'show warnings for unrecognized input data'
)
parser.add_argument(
    '-W', '--fatal-warnings',
    dest    = 'fatal_warnings',
    action  = 'store_true',
    default = False,
    help    = 'make unrecognized input data throw a fatal error, implicitly sets -w'
)
parser.add_argument(
    '-c', '--compact',
    dest    = 'tidy',
    action  = 'store_false',
    default = True,
    help    = 'do NOT default to the more readable YAML block syntax'
)
parser.add_argument(
    'source', metavar='INPUT',
    type    = argparse.FileType('r'),
    default = sys.stdin,
    nargs   = '?',
    help    = 'the run.cns file to parse, defaults to \'-\' for stdin'
)
parser.add_argument(
    '-o', '--output', metavar='OUTPUT',
    dest    = 'destination',
    type    = argparse.FileType('w'),
    default = sys.stdout,
    help    = 'the output YAML file, defualts to \'-\' for stdout'
)

args = parser.parse_args()

# Pass arguments as an unpacked dictionary to the CNSParser constructor
parser = CNSParser(**dict(
    (key, value) for (key, value) in vars(args).iteritems()
        # Filter out arguments used only by this program
        if key not in set(['destination', 'tidy'])
))
accesslevels, components = parser.parse()

print(yaml.dump_all([accesslevels, components],
    explicit_start=True, default_flow_style=(not args.tidy)), file=args.destination)
{'fraction_non_alphanumeric': 0.1347871781397793, 'fraction_numerical': 0.0010509721492380452, 'mean_word_length': 3.2019867549668874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6144555', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1209, 'n_words': 347}